cryptodev.h 8.8 KB

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