HAL_AES.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /***********************************************************************
  2. * All rights reserved.
  3. * Filename : aes.h
  4. * Description : aes driver header file
  5. * Author(s) : Eric
  6. * version : V1.0
  7. * Modify date : 2016-03-24
  8. ***********************************************************************/
  9. #ifndef __AES_H__
  10. #define __AES_H__
  11. #include "ACM32Fxx_HAL.h"
  12. #define AES_ENCRYPTION 1
  13. #define AES_DECRYPTION 0
  14. #define AES_ECB_MODE 0
  15. #define AES_CBC_MODE 1
  16. #define AES_SWAP_ENABLE 1
  17. #define AES_SWAP_DISABLE 0
  18. #define AES_NORMAL_MODE 0x12345678
  19. #define AES_SECURITY_MODE 0
  20. #define AES_KEY_128 0
  21. #define AES_KEY_192 1
  22. #define AES_KEY_256 2
  23. #define AES_FAIL 0x00
  24. #define AES_PASS 0xa59ada68
  25. #define BIT_AES (1<<28)
  26. /************************************************************************
  27. * function : delay
  28. * Description: delay for a while.
  29. * input :
  30. * count: count to decrease
  31. * return: none
  32. ************************************************************************/
  33. extern void delay(uint32_t count);
  34. /******************************************************************************
  35. * Name: HAL_AES_SetKey
  36. * Function: set key of AES
  37. * Input:
  38. keyin -- pointer to buffer of key
  39. key_len -- select length of key(AES_KEY_128/ AES_KEY_192/ AES_KEY_256)
  40. swap_en -- AES_SWAP_ENABLE, AES_SWAP_DISABLE
  41. * Return: None
  42. *******************************************************************************/
  43. void HAL_AES_SetKey(UINT32 *keyin, UINT8 key_len, UINT8 swap_en);
  44. void HAL_AES_SetKey_U8(UINT8 *keyin, UINT8 key_len, UINT8 swap_en);
  45. /******************************************************************************
  46. Name: HAL_AES_Crypt
  47. Function: Function for AES encryption and decryption
  48. Input:
  49. indata -- pointer to buffer of input
  50. outdata -- pointer to buffer of result
  51. block_len -- block(128bit) length for aes cryption
  52. operation -- AES_ENCRYPTION,AES_DECRYPTION
  53. mode -- AES_ECB_MODE, AES_CBC_MODE,
  54. iv -- initial vector for CBC mode
  55. security_mode -- AES_NORMAL_MODE, AES_SECURITY_MDOE£¬
  56. Return: None
  57. *******************************************************************************/
  58. uint32_t HAL_AES_Crypt(
  59. uint32_t *indata,
  60. uint32_t *outdata,
  61. uint32_t block_len,
  62. uint8_t operation,
  63. uint8_t mode,
  64. uint32_t *iv,
  65. uint32_t security_mode
  66. );
  67. uint32_t HAL_AES_Crypt_U8(
  68. uint8_t *indata,
  69. uint8_t *outdata,
  70. uint32_t block_len,
  71. uint8_t operation,
  72. uint8_t mode,
  73. uint8_t *iv,
  74. uint32_t security_mode
  75. );
  76. #endif
  77. /******************************************************************************
  78. * end of file
  79. *******************************************************************************/