xfm.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * xfm.h
  3. *
  4. * interface for abstract crypto transform
  5. *
  6. * David A. McGrew
  7. * Cisco Systems, Inc.
  8. */
  9. #ifndef XFM_H
  10. #define XFM_H
  11. #include "crypto_kernel.h"
  12. #include "err.h"
  13. /**
  14. * @defgroup Crypto Cryptography
  15. *
  16. * A simple interface to an abstract cryptographic transform that
  17. * provides both confidentiality and message authentication.
  18. *
  19. * @{
  20. */
  21. /**
  22. * @brief applies a crypto transform
  23. *
  24. * The function pointer xfm_func_t points to a function that
  25. * implements a crypto transform, and provides a uniform API for
  26. * accessing crypto mechanisms.
  27. *
  28. * @param key location of secret key
  29. *
  30. * @param clear data to be authenticated only
  31. *
  32. * @param clear_len length of data to be authenticated only
  33. *
  34. * @param iv location to write the Initialization Vector (IV)
  35. *
  36. * @param protect location of the data to be encrypted and
  37. * authenticated (before the function call), and the ciphertext
  38. * and authentication tag (after the call)
  39. *
  40. * @param protected_len location of the length of the data to be
  41. * encrypted and authenticated (before the function call), and the
  42. * length of the ciphertext (after the call)
  43. *
  44. * @param auth_tag location to write auth tag
  45. */
  46. typedef err_status_t (*xfm_func_t)
  47. (void *key,
  48. void *clear,
  49. unsigned clear_len,
  50. void *iv,
  51. void *protect,
  52. unsigned *protected_len,
  53. void *auth_tag
  54. );
  55. typedef
  56. err_status_t (*xfm_inv_t)
  57. (void *key, /* location of secret key */
  58. void *clear, /* data to be authenticated only */
  59. unsigned clear_len, /* length of data to be authenticated only */
  60. void *iv, /* location of iv */
  61. void *opaque, /* data to be decrypted and authenticated */
  62. unsigned *opaque_len, /* location of the length of data to be
  63. * decrypted and authd (before and after)
  64. */
  65. void *auth_tag /* location of auth tag */
  66. );
  67. typedef struct xfm_ctx_t {
  68. xfm_func_t func;
  69. xfm_inv_t inv;
  70. unsigned key_len;
  71. unsigned iv_len;
  72. unsigned auth_tag_len;
  73. } xfm_ctx_t;
  74. typedef xfm_ctx_t *xfm_t;
  75. #define xfm_get_key_len(xfm) ((xfm)->key_len)
  76. #define xfm_get_iv_len(xfm) ((xfm)->iv_len)
  77. #define xfm_get_auth_tag_len(xfm) ((xfm)->auth_tag_len)
  78. /* cryptoalgo - 5/28 */
  79. typedef err_status_t (*cryptoalg_func_t)
  80. (void *key,
  81. void *clear,
  82. unsigned clear_len,
  83. void *iv,
  84. void *opaque,
  85. unsigned *opaque_len
  86. );
  87. typedef
  88. err_status_t (*cryptoalg_inv_t)
  89. (void *key, /* location of secret key */
  90. void *clear, /* data to be authenticated only */
  91. unsigned clear_len, /* length of data to be authenticated only */
  92. void *iv, /* location of iv */
  93. void *opaque, /* data to be decrypted and authenticated */
  94. unsigned *opaque_len /* location of the length of data to be
  95. * decrypted and authd (before and after)
  96. */
  97. );
  98. typedef struct cryptoalg_ctx_t {
  99. cryptoalg_func_t enc;
  100. cryptoalg_inv_t dec;
  101. unsigned key_len;
  102. unsigned iv_len;
  103. unsigned auth_tag_len;
  104. unsigned max_expansion;
  105. } cryptoalg_ctx_t;
  106. typedef cryptoalg_ctx_t *cryptoalg_t;
  107. #define cryptoalg_get_key_len(cryptoalg) ((cryptoalg)->key_len)
  108. #define cryptoalg_get_iv_len(cryptoalg) ((cryptoalg)->iv_len)
  109. #define cryptoalg_get_auth_tag_len(cryptoalg) ((cryptoalg)->auth_tag_len)
  110. /**
  111. * @}
  112. */
  113. #endif /* XFM_H */