cryptocop.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * The device /dev/cryptocop is accessible using this driver using
  3. * CRYPTOCOP_MAJOR (254) and minor number 0.
  4. */
  5. #ifndef _UAPICRYPTOCOP_H
  6. #define _UAPICRYPTOCOP_H
  7. #include <linux/uio.h>
  8. #define CRYPTOCOP_SESSION_ID_NONE (0)
  9. typedef unsigned long long int cryptocop_session_id;
  10. /* cryptocop ioctls */
  11. #define ETRAXCRYPTOCOP_IOCTYPE (250)
  12. #define CRYPTOCOP_IO_CREATE_SESSION _IOWR(ETRAXCRYPTOCOP_IOCTYPE, 1, struct strcop_session_op)
  13. #define CRYPTOCOP_IO_CLOSE_SESSION _IOW(ETRAXCRYPTOCOP_IOCTYPE, 2, struct strcop_session_op)
  14. #define CRYPTOCOP_IO_PROCESS_OP _IOWR(ETRAXCRYPTOCOP_IOCTYPE, 3, struct strcop_crypto_op)
  15. #define CRYPTOCOP_IO_MAXNR (3)
  16. typedef enum {
  17. cryptocop_cipher_des = 0,
  18. cryptocop_cipher_3des = 1,
  19. cryptocop_cipher_aes = 2,
  20. cryptocop_cipher_m2m = 3, /* mem2mem is essentially a NULL cipher with blocklength=1 */
  21. cryptocop_cipher_none
  22. } cryptocop_cipher_type;
  23. typedef enum {
  24. cryptocop_digest_sha1 = 0,
  25. cryptocop_digest_md5 = 1,
  26. cryptocop_digest_none
  27. } cryptocop_digest_type;
  28. typedef enum {
  29. cryptocop_csum_le = 0,
  30. cryptocop_csum_be = 1,
  31. cryptocop_csum_none
  32. } cryptocop_csum_type;
  33. typedef enum {
  34. cryptocop_cipher_mode_ecb = 0,
  35. cryptocop_cipher_mode_cbc,
  36. cryptocop_cipher_mode_none
  37. } cryptocop_cipher_mode;
  38. typedef enum {
  39. cryptocop_3des_eee = 0,
  40. cryptocop_3des_eed = 1,
  41. cryptocop_3des_ede = 2,
  42. cryptocop_3des_edd = 3,
  43. cryptocop_3des_dee = 4,
  44. cryptocop_3des_ded = 5,
  45. cryptocop_3des_dde = 6,
  46. cryptocop_3des_ddd = 7
  47. } cryptocop_3des_mode;
  48. /* Usermode accessible (ioctl) operations. */
  49. struct strcop_session_op{
  50. cryptocop_session_id ses_id;
  51. cryptocop_cipher_type cipher; /* AES, DES, 3DES, m2m, none */
  52. cryptocop_cipher_mode cmode; /* ECB, CBC, none */
  53. cryptocop_3des_mode des3_mode;
  54. cryptocop_digest_type digest; /* MD5, SHA1, none */
  55. cryptocop_csum_type csum; /* BE, LE, none */
  56. unsigned char *key;
  57. size_t keylen;
  58. };
  59. #define CRYPTOCOP_CSUM_LENGTH (2)
  60. #define CRYPTOCOP_MAX_DIGEST_LENGTH (20) /* SHA-1 20, MD5 16 */
  61. #define CRYPTOCOP_MAX_IV_LENGTH (16) /* (3)DES==8, AES == 16 */
  62. #define CRYPTOCOP_MAX_KEY_LENGTH (32)
  63. struct strcop_crypto_op{
  64. cryptocop_session_id ses_id;
  65. /* Indata. */
  66. unsigned char *indata;
  67. size_t inlen; /* Total indata length. */
  68. /* Cipher configuration. */
  69. unsigned char do_cipher:1;
  70. unsigned char decrypt:1; /* 1 == decrypt, 0 == encrypt */
  71. unsigned char cipher_explicit:1;
  72. size_t cipher_start;
  73. size_t cipher_len;
  74. /* cipher_iv is used if do_cipher and cipher_explicit and the cipher
  75. mode is CBC. The length is controlled by the type of cipher,
  76. e.g. DES/3DES 8 octets and AES 16 octets. */
  77. unsigned char cipher_iv[CRYPTOCOP_MAX_IV_LENGTH];
  78. /* Outdata. */
  79. unsigned char *cipher_outdata;
  80. size_t cipher_outlen;
  81. /* digest configuration. */
  82. unsigned char do_digest:1;
  83. size_t digest_start;
  84. size_t digest_len;
  85. /* Outdata. The actual length is determined by the type of the digest. */
  86. unsigned char digest[CRYPTOCOP_MAX_DIGEST_LENGTH];
  87. /* Checksum configuration. */
  88. unsigned char do_csum:1;
  89. size_t csum_start;
  90. size_t csum_len;
  91. /* Outdata. */
  92. unsigned char csum[CRYPTOCOP_CSUM_LENGTH];
  93. };
  94. #endif /* _UAPICRYPTOCOP_H */