cryptodev.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /* This is a source compatible implementation with the original API of
  2. * cryptodev by Angelos D. Keromytis, found at openbsd cryptodev.h.
  3. * Placed under public domain */
  4. #ifndef L_CRYPTODEV_H
  5. #define L_CRYPTODEV_H
  6. #include <linux/types.h>
  7. #ifndef __KERNEL__
  8. #define __user
  9. #endif
  10. /* API extensions for linux */
  11. #define CRYPTO_HMAC_MAX_KEY_LEN 512
  12. #define CRYPTO_CIPHER_MAX_KEY_LEN 64
  13. /* All the supported algorithms
  14. */
  15. enum cryptodev_crypto_op_t {
  16. CRYPTO_DES_CBC = 1,
  17. CRYPTO_3DES_CBC = 2,
  18. CRYPTO_BLF_CBC = 3,
  19. CRYPTO_CAST_CBC = 4,
  20. CRYPTO_SKIPJACK_CBC = 5,
  21. CRYPTO_MD5_HMAC = 6,
  22. CRYPTO_SHA1_HMAC = 7,
  23. CRYPTO_RIPEMD160_HMAC = 8,
  24. CRYPTO_MD5_KPDK = 9,
  25. CRYPTO_SHA1_KPDK = 10,
  26. CRYPTO_RIJNDAEL128_CBC = 11,
  27. CRYPTO_AES_CBC = CRYPTO_RIJNDAEL128_CBC,
  28. CRYPTO_ARC4 = 12,
  29. CRYPTO_MD5 = 13,
  30. CRYPTO_SHA1 = 14,
  31. CRYPTO_DEFLATE_COMP = 15,
  32. CRYPTO_NULL = 16,
  33. CRYPTO_LZS_COMP = 17,
  34. CRYPTO_SHA2_256_HMAC = 18,
  35. CRYPTO_SHA2_384_HMAC = 19,
  36. CRYPTO_SHA2_512_HMAC = 20,
  37. CRYPTO_AES_CTR = 21,
  38. CRYPTO_AES_XTS = 22,
  39. CRYPTO_AES_ECB = 23,
  40. CRYPTO_AES_GCM = 50,
  41. CRYPTO_CAMELLIA_CBC = 101,
  42. CRYPTO_RIPEMD160,
  43. CRYPTO_SHA2_224,
  44. CRYPTO_SHA2_256,
  45. CRYPTO_SHA2_384,
  46. CRYPTO_SHA2_512,
  47. CRYPTO_SHA2_224_HMAC,
  48. CRYPTO_ALGORITHM_ALL, /* Keep updated - see below */
  49. };
  50. #define CRYPTO_ALGORITHM_MAX (CRYPTO_ALGORITHM_ALL - 1)
  51. /* Values for ciphers */
  52. #define DES_BLOCK_LEN 8
  53. #define DES3_BLOCK_LEN 8
  54. #define RIJNDAEL128_BLOCK_LEN 16
  55. #define AES_BLOCK_LEN RIJNDAEL128_BLOCK_LEN
  56. #define CAMELLIA_BLOCK_LEN 16
  57. #define BLOWFISH_BLOCK_LEN 8
  58. #define SKIPJACK_BLOCK_LEN 8
  59. #define CAST128_BLOCK_LEN 8
  60. /* the maximum of the above */
  61. #define EALG_MAX_BLOCK_LEN 16
  62. /* Values for hashes/MAC */
  63. #define AALG_MAX_RESULT_LEN 64
  64. /* maximum length of verbose alg names (depends on CRYPTO_MAX_ALG_NAME) */
  65. #define CRYPTODEV_MAX_ALG_NAME 64
  66. #define HASH_MAX_LEN 64
  67. /* input of CIOCGSESSION */
  68. struct session_op {
  69. /* Specify either cipher or mac
  70. */
  71. __u32 cipher; /* cryptodev_crypto_op_t */
  72. __u32 mac; /* cryptodev_crypto_op_t */
  73. __u32 keylen;
  74. __u8 __user *key;
  75. __u32 mackeylen;
  76. __u8 __user *mackey;
  77. __u32 ses; /* session identifier */
  78. };
  79. struct session_info_op {
  80. __u32 ses; /* session identifier */
  81. /* verbose names for the requested ciphers */
  82. struct alg_info {
  83. char cra_name[CRYPTODEV_MAX_ALG_NAME];
  84. char cra_driver_name[CRYPTODEV_MAX_ALG_NAME];
  85. } cipher_info, hash_info;
  86. __u16 alignmask; /* alignment constraints */
  87. __u32 flags; /* SIOP_FLAGS_* */
  88. };
  89. /* If this flag is set then this algorithm uses
  90. * a driver only available in kernel (software drivers,
  91. * or drivers based on instruction sets do not set this flag).
  92. *
  93. * If multiple algorithms are involved (as in AEAD case), then
  94. * if one of them is kernel-driver-only this flag will be set.
  95. */
  96. #define SIOP_FLAG_KERNEL_DRIVER_ONLY 1
  97. #define COP_ENCRYPT 0
  98. #define COP_DECRYPT 1
  99. /* input of CIOCCRYPT */
  100. struct crypt_op {
  101. __u32 ses; /* session identifier */
  102. __u16 op; /* COP_ENCRYPT or COP_DECRYPT */
  103. __u16 flags; /* see COP_FLAG_* */
  104. __u32 len; /* length of source data */
  105. __u8 __user *src; /* source data */
  106. __u8 __user *dst; /* pointer to output data */
  107. /* pointer to output data for hash/MAC operations */
  108. __u8 __user *mac;
  109. /* initialization vector for encryption operations */
  110. __u8 __user *iv;
  111. };
  112. /* input of CIOCAUTHCRYPT */
  113. struct crypt_auth_op {
  114. __u32 ses; /* session identifier */
  115. __u16 op; /* COP_ENCRYPT or COP_DECRYPT */
  116. __u16 flags; /* see COP_FLAG_AEAD_* */
  117. __u32 len; /* length of source data */
  118. __u32 auth_len; /* length of auth data */
  119. __u8 __user *auth_src; /* authenticated-only data */
  120. /* The current implementation is more efficient if data are
  121. * encrypted in-place (src==dst). */
  122. __u8 __user *src; /* data to be encrypted and authenticated */
  123. __u8 __user *dst; /* pointer to output data. Must have
  124. * space for tag. For TLS this should be at least
  125. * len + tag_size + block_size for padding */
  126. __u8 __user *tag; /* where the tag will be copied to. TLS mode
  127. * doesn't use that as tag is copied to dst.
  128. * SRTP mode copies tag there. */
  129. __u32 tag_len; /* the length of the tag. Use zero for digest size or max tag. */
  130. /* initialization vector for encryption operations */
  131. __u8 __user *iv;
  132. __u32 iv_len;
  133. };
  134. /* In plain AEAD mode the following are required:
  135. * flags : 0
  136. * iv : the initialization vector (12 bytes)
  137. * auth_len: the length of the data to be authenticated
  138. * auth_src: the data to be authenticated
  139. * len : length of data to be encrypted
  140. * src : the data to be encrypted
  141. * dst : space to hold encrypted data. It must have
  142. * at least a size of len + tag_size.
  143. * tag_size: the size of the desired authentication tag or zero to use
  144. * the maximum tag output.
  145. *
  146. * Note tag isn't being used because the Linux AEAD interface
  147. * copies the tag just after data.
  148. */
  149. /* In TLS mode (used for CBC ciphers that required padding)
  150. * the following are required:
  151. * flags : COP_FLAG_AEAD_TLS_TYPE
  152. * iv : the initialization vector
  153. * auth_len: the length of the data to be authenticated only
  154. * len : length of data to be encrypted
  155. * auth_src: the data to be authenticated
  156. * src : the data to be encrypted
  157. * dst : space to hold encrypted data (preferably in-place). It must have
  158. * at least a size of len + tag_size + blocksize.
  159. * tag_size: the size of the desired authentication tag or zero to use
  160. * the default mac output.
  161. *
  162. * Note that the padding used is the minimum padding.
  163. */
  164. /* In SRTP mode the following are required:
  165. * flags : COP_FLAG_AEAD_SRTP_TYPE
  166. * iv : the initialization vector
  167. * auth_len: the length of the data to be authenticated. This must
  168. * include the SRTP header + SRTP payload (data to be encrypted) + rest
  169. *
  170. * len : length of data to be encrypted
  171. * auth_src: pointer the data to be authenticated. Should point at the same buffer as src.
  172. * src : pointer to the data to be encrypted.
  173. * dst : This is mandatory to be the same as src (in-place only).
  174. * tag_size: the size of the desired authentication tag or zero to use
  175. * the default mac output.
  176. * tag : Pointer to an address where the authentication tag will be copied.
  177. */
  178. /* struct crypt_op flags */
  179. #define COP_FLAG_NONE (0 << 0) /* totally no flag */
  180. #define COP_FLAG_UPDATE (1 << 0) /* multi-update hash mode */
  181. #define COP_FLAG_FINAL (1 << 1) /* multi-update final hash mode */
  182. #define COP_FLAG_WRITE_IV (1 << 2) /* update the IV during operation */
  183. #define COP_FLAG_NO_ZC (1 << 3) /* do not zero-copy */
  184. #define COP_FLAG_AEAD_TLS_TYPE (1 << 4) /* authenticate and encrypt using the
  185. * TLS protocol rules */
  186. #define COP_FLAG_AEAD_SRTP_TYPE (1 << 5) /* authenticate and encrypt using the
  187. * SRTP protocol rules */
  188. #define COP_FLAG_RESET (1 << 6) /* multi-update reset the state.
  189. * should be used in combination
  190. * with COP_FLAG_UPDATE */
  191. /* Stuff for bignum arithmetic and public key
  192. * cryptography - not supported yet by linux
  193. * cryptodev.
  194. */
  195. #define CRYPTO_ALG_FLAG_SUPPORTED 1
  196. #define CRYPTO_ALG_FLAG_RNG_ENABLE 2
  197. #define CRYPTO_ALG_FLAG_DSA_SHA 4
  198. struct crparam {
  199. __u8 *crp_p;
  200. __u32 crp_nbits;
  201. };
  202. #define CRK_MAXPARAM 8
  203. /* input of CIOCKEY */
  204. struct crypt_kop {
  205. __u32 crk_op; /* cryptodev_crk_op_t */
  206. __u32 crk_status;
  207. __u16 crk_iparams;
  208. __u16 crk_oparams;
  209. __u32 crk_pad1;
  210. struct crparam crk_param[CRK_MAXPARAM];
  211. };
  212. enum cryptodev_crk_op_t {
  213. CRK_MOD_EXP = 0,
  214. CRK_MOD_EXP_CRT = 1,
  215. CRK_DSA_SIGN = 2,
  216. CRK_DSA_VERIFY = 3,
  217. CRK_DH_COMPUTE_KEY = 4,
  218. CRK_ALGORITHM_ALL
  219. };
  220. #define CRK_ALGORITHM_MAX (CRK_ALGORITHM_ALL-1)
  221. /* features to be queried with CIOCASYMFEAT ioctl
  222. */
  223. #define CRF_MOD_EXP (1 << CRK_MOD_EXP)
  224. #define CRF_MOD_EXP_CRT (1 << CRK_MOD_EXP_CRT)
  225. #define CRF_DSA_SIGN (1 << CRK_DSA_SIGN)
  226. #define CRF_DSA_VERIFY (1 << CRK_DSA_VERIFY)
  227. #define CRF_DH_COMPUTE_KEY (1 << CRK_DH_COMPUTE_KEY)
  228. /* ioctl's. Compatible with old linux cryptodev.h
  229. */
  230. #define CRIOGET _IOWR('c', 101, __u32)
  231. #define CIOCGSESSION _IOWR('c', 102, struct session_op)
  232. #define CIOCFSESSION _IOW('c', 103, __u32)
  233. #define CIOCCRYPT _IOWR('c', 104, struct crypt_op)
  234. #define CIOCKEY _IOWR('c', 105, struct crypt_kop)
  235. #define CIOCASYMFEAT _IOR('c', 106, __u32)
  236. #define CIOCGSESSINFO _IOWR('c', 107, struct session_info_op)
  237. /* to indicate that CRIOGET is not required in linux
  238. */
  239. #define CRIOGET_NOT_NEEDED 1
  240. /* additional ioctls for AEAD */
  241. #define CIOCAUTHCRYPT _IOWR('c', 109, struct crypt_auth_op)
  242. /* additional ioctls for asynchronous operation.
  243. * These are conditionally enabled since version 1.6.
  244. */
  245. #define CIOCASYNCCRYPT _IOW('c', 110, struct crypt_op)
  246. #define CIOCASYNCFETCH _IOR('c', 111, struct crypt_op)
  247. #endif /* L_CRYPTODEV_H */