fsl_mmcau.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  4. * All rights reserved.
  5. *
  6. *
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted (subject to the limitations in the disclaimer below) provided
  9. * that the following conditions are met:
  10. *
  11. * o Redistributions of source code must retain the above copyright notice, this list
  12. * of conditions and the following disclaimer.
  13. *
  14. * o Redistributions in binary form must reproduce the above copyright notice, this
  15. * list of conditions and the following disclaimer in the documentation and/or
  16. * other materials provided with the distribution.
  17. *
  18. * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  27. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef _FSL_MMCAU_H_
  35. #define _FSL_MMCAU_H_
  36. #include "fsl_common.h"
  37. /*******************************************************************************
  38. * API
  39. ******************************************************************************/
  40. /*!
  41. * @addtogroup mmcau MMCAU Peripheral Driver Wrapper
  42. * @{
  43. */
  44. #if defined(__cplusplus)
  45. extern "C" {
  46. #endif
  47. /*!
  48. * @brief AES: Performs an AES key expansion.
  49. *
  50. * This function performs an AES key expansion.
  51. *
  52. * @param key Pointer to input key (128, 192, 256 bits in length).
  53. * @param keySize Key size in bytes (16, 24, 32)
  54. * @param[out] keySch Pointer to key schedule output (44, 52, 60 longwords)
  55. * @note Table below shows the requirements for the MMCAU_AES_SetKey() function when using AES128, AES192, or AES256.
  56. * | [in] Key Size (bits) | [out] Key Schedule Size (32 bit data values) |
  57. * | :---------------------: | :--------------------------------------------: |
  58. * | 128 | 44 |
  59. * | 192 | 52 |
  60. * | 256 | 60 |
  61. * @return Status of the operation. (kStatus_Success, kStatus_InvalidArgument, kStatus_Fail)
  62. */
  63. status_t MMCAU_AES_SetKey(const uint8_t *key, const size_t keySize, uint8_t *keySch);
  64. /*!
  65. * @brief AES: Encrypts a single 16 byte block.
  66. *
  67. * This function encrypts a single 16-byte block for AES128, AES192, and AES256.
  68. *
  69. * @param in Pointer to 16-byte block of input plaintext.
  70. * @param keySch Pointer to key schedule (44, 52, 60 longwords).
  71. * @param aesRounds Number of AES rounds (10, 12, 14 = f(key_schedule)).
  72. * @param[out] out Pointer to 16-byte block of output ciphertext.
  73. * @note Input and output blocks may overlap.@n
  74. * Table below shows the requirements for the MMCAU_AES_EncryptEcb()/MMCAU_AES_DecryptEcb()
  75. * function when using AES128, AES192 or AES256.
  76. * | Block Cipher | [in] Key Schedule Size (longwords) | [in] Number of AES rounds |
  77. * | :----------: | :--------------------------------: | :-----------------------: |
  78. * | AES128 | 44 | 10 |
  79. * | AES192 | 52 | 12 |
  80. * | AES256 | 60 | 14 |
  81. * @return Status of the operation. (kStatus_Success, kStatus_InvalidArgument, kStatus_Fail)
  82. */
  83. status_t MMCAU_AES_EncryptEcb(const uint8_t *in, const uint8_t *keySch, uint32_t aesRounds, uint8_t *out);
  84. /*!
  85. * @brief AES: Decrypts a single 16-byte block.
  86. *
  87. * This function decrypts a single 16-byte block for AES128, AES192, and AES256.
  88. *
  89. * @param in Pointer to 16-byte block of input ciphertext.
  90. * @param keySch Pointer to key schedule (44, 52, 60 longwords).
  91. * @param aesRounds Number of AES rounds (10, 12, 14 = f(key_schedule)).
  92. * @param[out] out Pointer to 16-byte block of output plaintext.
  93. * @note Input and output blocks may overlap.@n
  94. * Table below shows the requirements for the cau_aes_encrypt()/cau_aes_decrypt().
  95. * function when using AES128, AES192 or AES256.
  96. * | Block Cipher | [in] Key Schedule Size (longwords) | [in] Number of AES rounds |
  97. * | :----------: | :--------------------------------: | :-----------------------: |
  98. * | AES128 | 44 | 10 |
  99. * | AES192 | 52 | 12 |
  100. * | AES256 | 60 | 14 |
  101. * @return Status of the operation. (kStatus_Success, kStatus_InvalidArgument, kStatus_Fail)
  102. */
  103. status_t MMCAU_AES_DecryptEcb(const uint8_t *in, const uint8_t *keySch, uint32_t aesRounds, uint8_t *out);
  104. /*!
  105. * @brief DES: Checks the key parity.
  106. *
  107. * This function checks the parity of a DES key.
  108. *
  109. * @param key 64-bit DES key with parity bits.
  110. * @return kStatus_Success No error.
  111. * @return kStatus_Fail Parity error.
  112. * @return kStatus_InvalidArgument Key argument is NULL.
  113. */
  114. status_t MMCAU_DES_ChkParity(const uint8_t *key);
  115. /*!
  116. * @brief DES: Encrypts a single 8-byte block.
  117. *
  118. * This function encrypts a single 8-byte block with the DES algorithm.
  119. *
  120. * @param in Pointer to 8-byte block of input plaintext.
  121. * @param key Pointer to 64-bit DES key with parity bits.
  122. * @param[out] out Pointer to 8-byte block of output ciphertext.
  123. * @note Input and output blocks may overlap.
  124. * @return Status of the operation. (kStatus_Success, kStatus_InvalidArgument, kStatus_Fail)
  125. */
  126. status_t MMCAU_DES_EncryptEcb(const uint8_t *in, const uint8_t *key, uint8_t *out);
  127. /*!
  128. * @brief DES: Decrypts a single 8-byte block.
  129. *
  130. * This function decrypts a single 8-byte block with the DES algorithm.
  131. *
  132. * @param in Pointer to 8-byte block of input ciphertext.
  133. * @param key Pointer to 64-bit DES key with parity bits.
  134. * @param[out] out Pointer to 8-byte block of output plaintext.
  135. * @note Input and output blocks may overlap.
  136. * @return Status of the operation. (kStatus_Success, kStatus_InvalidArgument, kStatus_Fail)
  137. */
  138. status_t MMCAU_DES_DecryptEcb(const uint8_t *in, const uint8_t *key, uint8_t *out);
  139. /*!
  140. * @brief MD5: Initializes the MD5 state variables.
  141. *
  142. * This function initializes the MD5 state variables.
  143. * The output can be used as input to MMCAU_MD5_HashN().
  144. *
  145. * @param[out] md5State Pointer to 128-bit block of md5 state variables: a,b,c,d
  146. */
  147. status_t MMCAU_MD5_InitializeOutput(uint32_t *md5State);
  148. /*!
  149. * @brief MD5: Updates the MD5 state variables with n message blocks.
  150. *
  151. * This function updates the MD5 state variables for one or more input message blocks.
  152. *
  153. * @param msgData Pointer to start of input message data.
  154. * @param numBlocks Number of 512-bit blocks to process.
  155. * @param[in,out] md5State Pointer to 128-bit block of MD5 state variables: a, b, c, d.
  156. * @note Input message and digest output blocks must not overlap.
  157. * The MMCAU_MD5_InitializeOutput() function must be called when starting a new hash.
  158. * Useful when handling non-contiguous input message blocks.
  159. */
  160. status_t MMCAU_MD5_HashN(const uint8_t *msgData, uint32_t numBlocks, uint32_t *md5State);
  161. /*!
  162. * @brief MD5: Updates the MD5 state variables.
  163. *
  164. * This function updates the MD5 state variables for one or more input message blocks.
  165. * It starts a new hash as it internally calls MMCAU_MD5_InitializeOutput() first.
  166. *
  167. * @param msgData Pointer to start of input message data.
  168. * @param numBlocks Number of 512-bit blocks to process.
  169. * @param[out] md5State Pointer to 128-bit block of MD5 state variables: a, b, c, d.
  170. * @note Input message and digest output blocks must not overlap.
  171. * The MMCAU_MD5_InitializeOutput() function is not required to be called
  172. * as it is called internally to start a new hash.
  173. * All input message blocks must be contiguous.
  174. */
  175. status_t MMCAU_MD5_Update(const uint8_t *msgData, uint32_t numBlocks, uint32_t *md5State);
  176. /*!
  177. * @brief SHA1: Initializes the SHA1 state variables.
  178. *
  179. * This function initializes the SHA1 state variables.
  180. * The output can be used as input to MMCAU_SHA1_HashN().
  181. *
  182. * @param[out] sha1State Pointer to 160-bit block of SHA1 state variables: a, b, c, d, e.
  183. */
  184. status_t MMCAU_SHA1_InitializeOutput(uint32_t *sha1State);
  185. /*!
  186. * @brief SHA1: Updates the SHA1 state variables with n message blocks.
  187. *
  188. * This function updates the SHA1 state variables for one or more input message blocks.
  189. *
  190. * @param msgData Pointer to start of input message data.
  191. * @param numBlocks Number of 512-bit blocks to process.
  192. * @param[in,out] sha1State Pointer to 160-bit block of SHA1 state variables: a, b, c, d, e.
  193. * @note Input message and digest output blocks must not overlap.
  194. * The MMCAU_SHA1_InitializeOutput() function must be called when starting a new hash.
  195. * Useful when handling non-contiguous input message blocks.
  196. */
  197. status_t MMCAU_SHA1_HashN(const uint8_t *msgData, uint32_t numBlocks, uint32_t *sha1State);
  198. /*!
  199. * @brief SHA1: Updates the SHA1 state variables.
  200. *
  201. * This function updates the SHA1 state variables for one or more input message blocks.
  202. * It starts a new hash as it internally calls MMCAU_SHA1_InitializeOutput() first.
  203. *
  204. * @param msgData Pointer to start of input message data.
  205. * @param numBlocks Number of 512-bit blocks to process.
  206. * @param[out] sha1State Pointer to 160-bit block of SHA1 state variables: a, b, c, d, e.
  207. * @note Input message and digest output blocks must not overlap.
  208. * The MMCAU_SHA1_InitializeOutput() function is not required to be called
  209. * as it is called internally to start a new hash.
  210. * All input message blocks must be contiguous.
  211. */
  212. status_t MMCAU_SHA1_Update(const uint8_t *msgData, uint32_t numBlocks, uint32_t *sha1State);
  213. /*!
  214. * @brief SHA256: Initializes the SHA256 state variables.
  215. *
  216. * This function initializes the SHA256 state variables.
  217. * The output can be used as input to MMCAU_SHA256_HashN().
  218. *
  219. * @param[out] sha256State Pointer to 256-bit block of SHA2 state variables a, b, c, d, e, f, g, h.
  220. * @return kStatus_Success No error. CAU hardware support for SHA256 is present.
  221. * @return kStatus_Fail Error. CAU hardware support for SHA256 is not present.
  222. * @return kStatus_InvalidArgument Error. sha256State is NULL.
  223. */
  224. status_t MMCAU_SHA256_InitializeOutput(uint32_t *sha256State);
  225. /*!
  226. * @brief SHA256: Updates the SHA256 state variables with n message blocks.
  227. *
  228. * This function updates SHA256 state variables for one or more input message blocks.
  229. *
  230. * @param input Pointer to start of input message data.
  231. * @param numBlocks Number of 512-bit blocks to process.
  232. * @param[in,out] sha256State Pointer to 256-bit block of SHA2 state variables: a, b, c, d, e, f, g, h.
  233. * @note Input message and digest output blocks must not overlap.
  234. * The MMCAU_SHA256_InitializeOutput() function must be called when starting a new hash.
  235. * Useful when handling non-contiguous input message blocks.
  236. */
  237. status_t MMCAU_SHA256_HashN(const uint8_t *input, uint32_t numBlocks, uint32_t *sha256State);
  238. /*!
  239. * @brief SHA256: Updates SHA256 state variables.
  240. *
  241. * This function updates the SHA256 state variables for one or more input message blocks.
  242. * It starts a new hash as it internally calls cau_sha256_initialize_output() first.
  243. *
  244. * @param input Pointer to start of input message data.
  245. * @param numBlocks Number of 512-bit blocks to process.
  246. * @param[out] sha256State Pointer to 256-bit block of SHA2 state variables: a, b, c, d, e, f, g, h.
  247. * @note Input message and digest output blocks must not overlap.
  248. * The MMCAU_SHA256_InitializeOutput() function is not required to be called.
  249. * as it is called internally to start a new hash.
  250. * All input message blocks must be contiguous.
  251. */
  252. status_t MMCAU_SHA256_Update(const uint8_t *input, uint32_t numBlocks, uint32_t *sha256State);
  253. #if defined(__cplusplus)
  254. }
  255. #endif
  256. /*! @}*/
  257. #endif /* _FSL_MMCAU_H_ */