efm32_aes.h 7.5 KB

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