cmac.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*!
  2. \ingroup CMAC
  3. \brief Initialize the Cmac structure with defaults
  4. \return 0 on success
  5. \param cmac pointer to the Cmac structure
  6. \param key key pointer
  7. \param keySz size of the key pointer (16, 24 or 32)
  8. \param type Always WC_CMAC_AES = 1
  9. \param unused not used, exists for potential future use around compatiblity
  10. _Example_
  11. \code
  12. Cmac cmac[1];
  13. ret = wc_InitCmac(cmac, key, keySz, WC_CMAC_AES, NULL);
  14. if (ret == 0) {
  15. ret = wc_CmacUpdate(cmac, in, inSz);
  16. }
  17. if (ret == 0) {
  18. ret = wc_CmacFinal(cmac, out, outSz);
  19. }
  20. \endcode
  21. \sa wc_InitCmac_ex
  22. \sa wc_CmacUpdate
  23. \sa wc_CmacFinal
  24. */
  25. int wc_InitCmac(Cmac* cmac,
  26. const byte* key, word32 keySz,
  27. int type, void* unused);
  28. /*!
  29. \ingroup CMAC
  30. \brief Initialize the Cmac structure with defaults
  31. \return 0 on success
  32. \param cmac pointer to the Cmac structure
  33. \param key key pointer
  34. \param keySz size of the key pointer (16, 24 or 32)
  35. \param type Always WC_CMAC_AES = 1
  36. \param unused not used, exists for potential future use around compatiblity
  37. \param heap pointer to the heap hint used for dynamic allocation. Typically used with our static memory option. Can be NULL.
  38. \param devId ID to use with async hardware. Set to INVALID_DEVID if not using async hardware.
  39. _Example_
  40. \code
  41. Cmac cmac[1];
  42. ret = wc_InitCmac_ex(cmac, key, keySz, WC_CMAC_AES, NULL, NULL, INVALID_DEVID);
  43. if (ret == 0) {
  44. ret = wc_CmacUpdate(cmac, in, inSz);
  45. }
  46. if (ret == 0) {
  47. ret = wc_CmacFinal(cmac, out, &outSz);
  48. }
  49. \endcode
  50. \sa wc_InitCmac_ex
  51. \sa wc_CmacUpdate
  52. \sa wc_CmacFinal
  53. */
  54. int wc_InitCmac_ex(Cmac* cmac,
  55. const byte* key, word32 keySz,
  56. int type, void* unused, void* heap, int devId);
  57. /*!
  58. \ingroup CMAC
  59. \brief Add Cipher-based Message Authentication Code input data
  60. \return 0 on success
  61. \param cmac pointer to the Cmac structure
  62. \param in input data to process
  63. \param inSz size of input data
  64. _Example_
  65. \code
  66. ret = wc_CmacUpdate(cmac, in, inSz);
  67. \endcode
  68. \sa wc_InitCmac
  69. \sa wc_CmacFinal
  70. */
  71. int wc_CmacUpdate(Cmac* cmac,
  72. const byte* in, word32 inSz);
  73. /*!
  74. \ingroup CMAC
  75. \brief Generate the final result using Cipher-based Message Authentication Code
  76. \return 0 on success
  77. \param cmac pointer to the Cmac structure
  78. \param out pointer to return the result
  79. \param outSz pointer size of output (in/out)
  80. _Example_
  81. \code
  82. ret = wc_CmacFinal(cmac, out, &outSz);
  83. \endcode
  84. \sa wc_InitCmac
  85. \sa wc_CmacFinal
  86. */
  87. int wc_CmacFinal(Cmac* cmac,
  88. byte* out, word32* outSz);
  89. /*!
  90. \ingroup CMAC
  91. \brief Single shot fuction for generating a CMAC
  92. \return 0 on success
  93. \param out pointer to return the result
  94. \param outSz pointer size of output (in/out)
  95. \param in input data to process
  96. \param inSz size of input data
  97. \param key key pointer
  98. \param keySz size of the key pointer (16, 24 or 32)
  99. _Example_
  100. \code
  101. ret = wc_AesCmacGenerate(mac, &macSz, msg, msgSz, key, keySz);
  102. \endcode
  103. \sa wc_AesCmacVerify
  104. */
  105. int wc_AesCmacGenerate(byte* out, word32* outSz,
  106. const byte* in, word32 inSz,
  107. const byte* key, word32 keySz);
  108. /*!
  109. \ingroup CMAC
  110. \brief Single shot fuction for validating a CMAC
  111. \return 0 on success
  112. \param check pointer to return the result
  113. \param checkSz size of checkout buffer
  114. \param in input data to process
  115. \param inSz size of input data
  116. \param key key pointer
  117. \param keySz size of the key pointer (16, 24 or 32)
  118. _Example_
  119. \code
  120. ret = wc_AesCmacVerify(mac, macSz, msg, msgSz, key, keySz);
  121. \endcode
  122. \sa wc_AesCmacGenerate
  123. */
  124. int wc_AesCmacVerify(const byte* check, word32 checkSz,
  125. const byte* in, word32 inSz,
  126. const byte* key, word32 keySz);
  127. /*!
  128. \ingroup CMAC
  129. \brief Only used with WOLFSSL_HASH_KEEP when hardware requires single-shot and the updates must be cached in memory
  130. \return 0 on success
  131. \param in input data to process
  132. \param inSz size of input data
  133. _Example_
  134. \code
  135. ret = wc_CMAC_Grow(cmac, in, inSz)
  136. \endcode
  137. */
  138. int wc_CMAC_Grow(Cmac* cmac, const byte* in, int inSz);