chcr_crypto.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /*
  2. * This file is part of the Chelsio T6 Crypto driver for Linux.
  3. *
  4. * Copyright (c) 2003-2016 Chelsio Communications, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. *
  34. */
  35. #ifndef __CHCR_CRYPTO_H__
  36. #define __CHCR_CRYPTO_H__
  37. #define GHASH_BLOCK_SIZE 16
  38. #define GHASH_DIGEST_SIZE 16
  39. #define CCM_B0_SIZE 16
  40. #define CCM_AAD_FIELD_SIZE 2
  41. #define T5_MAX_AAD_SIZE 512
  42. /* Define following if h/w is not dropping the AAD and IV data before
  43. * giving the processed data
  44. */
  45. #define CHCR_CRA_PRIORITY 300
  46. #define CHCR_AES_MAX_KEY_LEN (2 * (AES_MAX_KEY_SIZE)) /* consider xts */
  47. #define CHCR_MAX_CRYPTO_IV_LEN 16 /* AES IV len */
  48. #define CHCR_MAX_AUTHENC_AES_KEY_LEN 32 /* max aes key length*/
  49. #define CHCR_MAX_AUTHENC_SHA_KEY_LEN 128 /* max sha key length*/
  50. #define CHCR_GIVENCRYPT_OP 2
  51. /* CPL/SCMD parameters */
  52. #define CHCR_ENCRYPT_OP 0
  53. #define CHCR_DECRYPT_OP 1
  54. #define CHCR_SCMD_SEQ_NO_CTRL_32BIT 1
  55. #define CHCR_SCMD_SEQ_NO_CTRL_48BIT 2
  56. #define CHCR_SCMD_SEQ_NO_CTRL_64BIT 3
  57. #define CHCR_SCMD_PROTO_VERSION_GENERIC 4
  58. #define CHCR_SCMD_AUTH_CTRL_AUTH_CIPHER 0
  59. #define CHCR_SCMD_AUTH_CTRL_CIPHER_AUTH 1
  60. #define CHCR_SCMD_CIPHER_MODE_NOP 0
  61. #define CHCR_SCMD_CIPHER_MODE_AES_CBC 1
  62. #define CHCR_SCMD_CIPHER_MODE_AES_GCM 2
  63. #define CHCR_SCMD_CIPHER_MODE_AES_CTR 3
  64. #define CHCR_SCMD_CIPHER_MODE_GENERIC_AES 4
  65. #define CHCR_SCMD_CIPHER_MODE_AES_XTS 6
  66. #define CHCR_SCMD_CIPHER_MODE_AES_CCM 7
  67. #define CHCR_SCMD_AUTH_MODE_NOP 0
  68. #define CHCR_SCMD_AUTH_MODE_SHA1 1
  69. #define CHCR_SCMD_AUTH_MODE_SHA224 2
  70. #define CHCR_SCMD_AUTH_MODE_SHA256 3
  71. #define CHCR_SCMD_AUTH_MODE_GHASH 4
  72. #define CHCR_SCMD_AUTH_MODE_SHA512_224 5
  73. #define CHCR_SCMD_AUTH_MODE_SHA512_256 6
  74. #define CHCR_SCMD_AUTH_MODE_SHA512_384 7
  75. #define CHCR_SCMD_AUTH_MODE_SHA512_512 8
  76. #define CHCR_SCMD_AUTH_MODE_CBCMAC 9
  77. #define CHCR_SCMD_AUTH_MODE_CMAC 10
  78. #define CHCR_SCMD_HMAC_CTRL_NOP 0
  79. #define CHCR_SCMD_HMAC_CTRL_NO_TRUNC 1
  80. #define CHCR_SCMD_HMAC_CTRL_TRUNC_RFC4366 2
  81. #define CHCR_SCMD_HMAC_CTRL_IPSEC_96BIT 3
  82. #define CHCR_SCMD_HMAC_CTRL_PL1 4
  83. #define CHCR_SCMD_HMAC_CTRL_PL2 5
  84. #define CHCR_SCMD_HMAC_CTRL_PL3 6
  85. #define CHCR_SCMD_HMAC_CTRL_DIV2 7
  86. #define VERIFY_HW 0
  87. #define VERIFY_SW 1
  88. #define CHCR_SCMD_IVGEN_CTRL_HW 0
  89. #define CHCR_SCMD_IVGEN_CTRL_SW 1
  90. /* This are not really mac key size. They are intermediate values
  91. * of sha engine and its size
  92. */
  93. #define CHCR_KEYCTX_MAC_KEY_SIZE_128 0
  94. #define CHCR_KEYCTX_MAC_KEY_SIZE_160 1
  95. #define CHCR_KEYCTX_MAC_KEY_SIZE_192 2
  96. #define CHCR_KEYCTX_MAC_KEY_SIZE_256 3
  97. #define CHCR_KEYCTX_MAC_KEY_SIZE_512 4
  98. #define CHCR_KEYCTX_CIPHER_KEY_SIZE_128 0
  99. #define CHCR_KEYCTX_CIPHER_KEY_SIZE_192 1
  100. #define CHCR_KEYCTX_CIPHER_KEY_SIZE_256 2
  101. #define CHCR_KEYCTX_NO_KEY 15
  102. #define CHCR_CPL_FW4_PLD_IV_OFFSET (5 * 64) /* bytes. flt #5 and #6 */
  103. #define CHCR_CPL_FW4_PLD_HASH_RESULT_OFFSET (7 * 64) /* bytes. flt #7 */
  104. #define CHCR_CPL_FW4_PLD_DATA_SIZE (4 * 64) /* bytes. flt #4 to #7 */
  105. #define KEY_CONTEXT_HDR_SALT_AND_PAD 16
  106. #define flits_to_bytes(x) (x * 8)
  107. #define IV_NOP 0
  108. #define IV_IMMEDIATE 1
  109. #define IV_DSGL 2
  110. #define AEAD_H_SIZE 16
  111. #define CRYPTO_ALG_SUB_TYPE_MASK 0x0f000000
  112. #define CRYPTO_ALG_SUB_TYPE_HASH_HMAC 0x01000000
  113. #define CRYPTO_ALG_SUB_TYPE_AEAD_RFC4106 0x02000000
  114. #define CRYPTO_ALG_SUB_TYPE_AEAD_GCM 0x03000000
  115. #define CRYPTO_ALG_SUB_TYPE_AEAD_AUTHENC 0x04000000
  116. #define CRYPTO_ALG_SUB_TYPE_AEAD_CCM 0x05000000
  117. #define CRYPTO_ALG_SUB_TYPE_AEAD_RFC4309 0x06000000
  118. #define CRYPTO_ALG_SUB_TYPE_AEAD_NULL 0x07000000
  119. #define CRYPTO_ALG_SUB_TYPE_CTR 0x08000000
  120. #define CRYPTO_ALG_TYPE_HMAC (CRYPTO_ALG_TYPE_AHASH |\
  121. CRYPTO_ALG_SUB_TYPE_HASH_HMAC)
  122. #define MAX_SCRATCH_PAD_SIZE 32
  123. #define CHCR_HASH_MAX_BLOCK_SIZE_64 64
  124. #define CHCR_HASH_MAX_BLOCK_SIZE_128 128
  125. /* Aligned to 128 bit boundary */
  126. struct ablk_ctx {
  127. __be32 key_ctx_hdr;
  128. unsigned int enckey_len;
  129. u8 key[CHCR_AES_MAX_KEY_LEN];
  130. unsigned char ciph_mode;
  131. u8 rrkey[AES_MAX_KEY_SIZE];
  132. };
  133. struct chcr_aead_reqctx {
  134. struct sk_buff *skb;
  135. short int dst_nents;
  136. u16 verify;
  137. u8 iv[CHCR_MAX_CRYPTO_IV_LEN];
  138. unsigned char scratch_pad[MAX_SCRATCH_PAD_SIZE];
  139. };
  140. struct chcr_gcm_ctx {
  141. u8 ghash_h[AEAD_H_SIZE];
  142. };
  143. struct chcr_authenc_ctx {
  144. u8 dec_rrkey[AES_MAX_KEY_SIZE];
  145. u8 h_iopad[2 * CHCR_HASH_MAX_DIGEST_SIZE];
  146. unsigned char auth_mode;
  147. };
  148. struct __aead_ctx {
  149. struct chcr_gcm_ctx gcm[0];
  150. struct chcr_authenc_ctx authenc[0];
  151. };
  152. struct chcr_aead_ctx {
  153. __be32 key_ctx_hdr;
  154. unsigned int enckey_len;
  155. struct crypto_skcipher *null;
  156. u8 salt[MAX_SALT];
  157. u8 key[CHCR_AES_MAX_KEY_LEN];
  158. u16 hmac_ctrl;
  159. u16 mayverify;
  160. struct __aead_ctx ctx[0];
  161. };
  162. struct hmac_ctx {
  163. struct crypto_shash *base_hash;
  164. u8 ipad[CHCR_HASH_MAX_BLOCK_SIZE_128];
  165. u8 opad[CHCR_HASH_MAX_BLOCK_SIZE_128];
  166. };
  167. struct __crypto_ctx {
  168. struct hmac_ctx hmacctx[0];
  169. struct ablk_ctx ablkctx[0];
  170. struct chcr_aead_ctx aeadctx[0];
  171. };
  172. struct chcr_context {
  173. struct chcr_dev *dev;
  174. unsigned char tx_channel_id;
  175. struct __crypto_ctx crypto_ctx[0];
  176. };
  177. struct chcr_ahash_req_ctx {
  178. u32 result;
  179. u8 bfr1[CHCR_HASH_MAX_BLOCK_SIZE_128];
  180. u8 bfr2[CHCR_HASH_MAX_BLOCK_SIZE_128];
  181. u8 *reqbfr;
  182. u8 *skbfr;
  183. u8 reqlen;
  184. /* DMA the partial hash in it */
  185. u8 partial_hash[CHCR_HASH_MAX_DIGEST_SIZE];
  186. u64 data_len; /* Data len till time */
  187. /* SKB which is being sent to the hardware for processing */
  188. struct sk_buff *skb;
  189. };
  190. struct chcr_blkcipher_req_ctx {
  191. struct sk_buff *skb;
  192. unsigned int dst_nents;
  193. u8 iv[CHCR_MAX_CRYPTO_IV_LEN];
  194. };
  195. struct chcr_alg_template {
  196. u32 type;
  197. u32 is_registered;
  198. union {
  199. struct crypto_alg crypto;
  200. struct ahash_alg hash;
  201. struct aead_alg aead;
  202. } alg;
  203. };
  204. struct chcr_req_ctx {
  205. union {
  206. struct ahash_request *ahash_req;
  207. struct aead_request *aead_req;
  208. struct ablkcipher_request *ablk_req;
  209. } req;
  210. union {
  211. struct chcr_ahash_req_ctx *ahash_ctx;
  212. struct chcr_aead_reqctx *reqctx;
  213. struct chcr_blkcipher_req_ctx *ablk_ctx;
  214. } ctx;
  215. };
  216. struct sge_opaque_hdr {
  217. void *dev;
  218. dma_addr_t addr[MAX_SKB_FRAGS + 1];
  219. };
  220. typedef struct sk_buff *(*create_wr_t)(struct aead_request *req,
  221. unsigned short qid,
  222. int size,
  223. unsigned short op_type);
  224. static int chcr_aead_op(struct aead_request *req_base,
  225. unsigned short op_type,
  226. int size,
  227. create_wr_t create_wr_fn);
  228. static inline int get_aead_subtype(struct crypto_aead *aead);
  229. #endif /* __CHCR_CRYPTO_H__ */