1
0

em_aes.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /***************************************************************************//**
  2. * @file
  3. * @brief Advanced encryption standard (AES) accelerator peripheral API for
  4. * EFM32.
  5. * @author Energy Micro AS
  6. * @version 3.0.0
  7. *******************************************************************************
  8. * @section License
  9. * <b>(C) Copyright 2012 Energy Micro AS, http://www.energymicro.com</b>
  10. *******************************************************************************
  11. *
  12. * Permission is granted to anyone to use this software for any purpose,
  13. * including commercial applications, and to alter it and redistribute it
  14. * freely, subject to the following restrictions:
  15. *
  16. * 1. The origin of this software must not be misrepresented; you must not
  17. * claim that you wrote the original software.
  18. * 2. Altered source versions must be plainly marked as such, and must not be
  19. * misrepresented as being the original software.
  20. * 3. This notice may not be removed or altered from any source distribution.
  21. *
  22. * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
  23. * obligation to support this Software. Energy Micro AS is providing the
  24. * Software "AS IS", with no express or implied warranties of any kind,
  25. * including, but not limited to, any implied warranties of merchantability
  26. * or fitness for any particular purpose or warranties against infringement
  27. * of any proprietary rights of a third party.
  28. *
  29. * Energy Micro AS will not be liable for any consequential, incidental, or
  30. * special damages, or any other relief, or for any claim by any third party,
  31. * arising from your use of this Software.
  32. *
  33. ******************************************************************************/
  34. #ifndef __EM_AES_H
  35. #define __EM_AES_H
  36. #include <stdbool.h>
  37. #include "em_part.h"
  38. #if defined(AES_COUNT) && (AES_COUNT > 0)
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. /***************************************************************************//**
  43. * @addtogroup EM_Library
  44. * @{
  45. ******************************************************************************/
  46. /***************************************************************************//**
  47. * @addtogroup AES
  48. * @{
  49. ******************************************************************************/
  50. /*******************************************************************************
  51. ****************************** TYPEDEFS ***********************************
  52. ******************************************************************************/
  53. /**
  54. * @brief
  55. * AES counter modification function pointer.
  56. * @details
  57. * Parameters:
  58. * @li ctr - Ptr to byte array (16 bytes) holding counter to be modified.
  59. */
  60. typedef void (*AES_CtrFuncPtr_TypeDef)(uint8_t *ctr);
  61. /*******************************************************************************
  62. ***************************** PROTOTYPES **********************************
  63. ******************************************************************************/
  64. void AES_CBC128(uint8_t *out,
  65. const uint8_t *in,
  66. unsigned int len,
  67. const uint8_t *key,
  68. const uint8_t *iv,
  69. bool encrypt);
  70. void AES_CBC256(uint8_t *out,
  71. const uint8_t *in,
  72. unsigned int len,
  73. const uint8_t *key,
  74. const uint8_t *iv,
  75. bool encrypt);
  76. void AES_CFB128(uint8_t *out,
  77. const uint8_t *in,
  78. unsigned int len,
  79. const uint8_t *key,
  80. const uint8_t *iv,
  81. bool encrypt);
  82. void AES_CFB256(uint8_t *out,
  83. const uint8_t *in,
  84. unsigned int len,
  85. const uint8_t *key,
  86. const uint8_t *iv,
  87. bool encrypt);
  88. void AES_CTR128(uint8_t *out,
  89. const uint8_t *in,
  90. unsigned int len,
  91. const uint8_t *key,
  92. uint8_t *ctr,
  93. AES_CtrFuncPtr_TypeDef ctrFunc);
  94. void AES_CTR256(uint8_t *out,
  95. const uint8_t *in,
  96. unsigned int len,
  97. const uint8_t *key,
  98. uint8_t *ctr,
  99. AES_CtrFuncPtr_TypeDef ctrFunc);
  100. void AES_CTRUpdate32Bit(uint8_t *ctr);
  101. void AES_DecryptKey128(uint8_t *out, const uint8_t *in);
  102. void AES_DecryptKey256(uint8_t *out, const uint8_t *in);
  103. void AES_ECB128(uint8_t *out,
  104. const uint8_t *in,
  105. unsigned int len,
  106. const uint8_t *key,
  107. bool encrypt);
  108. void AES_ECB256(uint8_t *out,
  109. const uint8_t *in,
  110. unsigned int len,
  111. const uint8_t *key,
  112. bool encrypt);
  113. /***************************************************************************//**
  114. * @brief
  115. * Clear one or more pending AES interrupts.
  116. *
  117. * @param[in] flags
  118. * Pending AES interrupt source to clear. Use a bitwise logic OR combination of
  119. * valid interrupt flags for the AES module (AES_IF_nnn).
  120. ******************************************************************************/
  121. __STATIC_INLINE void AES_IntClear(uint32_t flags)
  122. {
  123. AES->IFC = flags;
  124. }
  125. /***************************************************************************//**
  126. * @brief
  127. * Disable one or more AES interrupts.
  128. *
  129. * @param[in] flags
  130. * AES interrupt sources to disable. Use a bitwise logic OR combination of
  131. * valid interrupt flags for the AES module (AES_IF_nnn).
  132. ******************************************************************************/
  133. __STATIC_INLINE void AES_IntDisable(uint32_t flags)
  134. {
  135. AES->IEN &= ~(flags);
  136. }
  137. /***************************************************************************//**
  138. * @brief
  139. * Enable one or more AES interrupts.
  140. *
  141. * @note
  142. * Depending on the use, a pending interrupt may already be set prior to
  143. * enabling the interrupt. Consider using AES_IntClear() prior to enabling
  144. * if such a pending interrupt should be ignored.
  145. *
  146. * @param[in] flags
  147. * AES interrupt sources to enable. Use a bitwise logic OR combination of
  148. * valid interrupt flags for the AES module (AES_IF_nnn).
  149. ******************************************************************************/
  150. __STATIC_INLINE void AES_IntEnable(uint32_t flags)
  151. {
  152. AES->IEN |= flags;
  153. }
  154. /***************************************************************************//**
  155. * @brief
  156. * Get pending AES interrupt flags.
  157. *
  158. * @note
  159. * The event bits are not cleared by the use of this function.
  160. *
  161. * @return
  162. * AES interrupt sources pending. A bitwise logic OR combination of valid
  163. * interrupt flags for the AES module (AES_IF_nnn).
  164. ******************************************************************************/
  165. __STATIC_INLINE uint32_t AES_IntGet(void)
  166. {
  167. return(AES->IF);
  168. }
  169. /***************************************************************************//**
  170. * @brief
  171. * Set one or more pending AES interrupts from SW.
  172. *
  173. * @param[in] flags
  174. * AES interrupt sources to set to pending. Use a bitwise logic OR combination
  175. * of valid interrupt flags for the AES module (AES_IF_nnn).
  176. ******************************************************************************/
  177. __STATIC_INLINE void AES_IntSet(uint32_t flags)
  178. {
  179. AES->IFS = flags;
  180. }
  181. void AES_OFB128(uint8_t *out,
  182. const uint8_t *in,
  183. unsigned int len,
  184. const uint8_t *key,
  185. const uint8_t *iv);
  186. void AES_OFB256(uint8_t *out,
  187. const uint8_t *in,
  188. unsigned int len,
  189. const uint8_t *key,
  190. const uint8_t *iv);
  191. /** @} (end addtogroup AES) */
  192. /** @} (end addtogroup EM_Library) */
  193. #ifdef __cplusplus
  194. }
  195. #endif
  196. #endif /* __EM_AES_H */
  197. #endif /* defined(AES_COUNT) && (AES_COUNT > 0) */