aes.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /**
  2. ******************************************************************************
  3. * @file aes.c
  4. * @brief This file provides code for the configuration
  5. * of the AES instances.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under Ultimate Liberty license
  13. * SLA0044, the "License"; You may not use this file except in compliance with
  14. * the License. You may obtain a copy of the License at:
  15. * www.st.com/SLA0044
  16. *
  17. ******************************************************************************
  18. */
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "aes.h"
  21. /* USER CODE BEGIN 0 */
  22. /* USER CODE END 0 */
  23. CRYP_HandleTypeDef hcryp1;
  24. __ALIGN_BEGIN static const uint32_t pKeyAES1[4] __ALIGN_END =
  25. {0x00000000, 0x00000000, 0x00000000, 0x00000000};
  26. CRYP_HandleTypeDef hcryp2;
  27. __ALIGN_BEGIN static const uint32_t pKeyAES2[4] __ALIGN_END =
  28. {0x00000000, 0x00000000, 0x00000000, 0x00000000};
  29. /* AES1 init function */
  30. void MX_AES1_Init(void) {
  31. /* USER CODE BEGIN AES1_Init 0 */
  32. /* USER CODE END AES1_Init 0 */
  33. /* USER CODE BEGIN AES1_Init 1 */
  34. /* USER CODE END AES1_Init 1 */
  35. hcryp1.Instance = AES1;
  36. hcryp1.Init.DataType = CRYP_DATATYPE_32B;
  37. hcryp1.Init.KeySize = CRYP_KEYSIZE_128B;
  38. hcryp1.Init.pKey = (uint32_t*)pKeyAES1;
  39. hcryp1.Init.Algorithm = CRYP_AES_ECB;
  40. hcryp1.Init.DataWidthUnit = CRYP_DATAWIDTHUNIT_WORD;
  41. hcryp1.Init.KeyIVConfigSkip = CRYP_KEYIVCONFIG_ALWAYS;
  42. if(HAL_CRYP_Init(&hcryp1) != HAL_OK) {
  43. Error_Handler();
  44. }
  45. /* USER CODE BEGIN AES1_Init 2 */
  46. /* USER CODE END AES1_Init 2 */
  47. }
  48. /* AES2 init function */
  49. void MX_AES2_Init(void) {
  50. /* USER CODE BEGIN AES2_Init 0 */
  51. /* USER CODE END AES2_Init 0 */
  52. /* USER CODE BEGIN AES2_Init 1 */
  53. /* USER CODE END AES2_Init 1 */
  54. hcryp2.Instance = AES2;
  55. hcryp2.Init.DataType = CRYP_DATATYPE_32B;
  56. hcryp2.Init.KeySize = CRYP_KEYSIZE_128B;
  57. hcryp2.Init.pKey = (uint32_t*)pKeyAES2;
  58. hcryp2.Init.Algorithm = CRYP_AES_ECB;
  59. hcryp2.Init.DataWidthUnit = CRYP_DATAWIDTHUNIT_WORD;
  60. hcryp2.Init.KeyIVConfigSkip = CRYP_KEYIVCONFIG_ALWAYS;
  61. if(HAL_CRYP_Init(&hcryp2) != HAL_OK) {
  62. Error_Handler();
  63. }
  64. /* USER CODE BEGIN AES2_Init 2 */
  65. /* USER CODE END AES2_Init 2 */
  66. }
  67. void HAL_CRYP_MspInit(CRYP_HandleTypeDef* crypHandle) {
  68. if(crypHandle->Instance == AES1) {
  69. /* USER CODE BEGIN AES1_MspInit 0 */
  70. /* USER CODE END AES1_MspInit 0 */
  71. /* AES1 clock enable */
  72. __HAL_RCC_AES1_CLK_ENABLE();
  73. /* USER CODE BEGIN AES1_MspInit 1 */
  74. /* USER CODE END AES1_MspInit 1 */
  75. } else if(crypHandle->Instance == AES2) {
  76. /* USER CODE BEGIN AES2_MspInit 0 */
  77. /* USER CODE END AES2_MspInit 0 */
  78. /* AES2 clock enable */
  79. __HAL_RCC_AES2_CLK_ENABLE();
  80. /* USER CODE BEGIN AES2_MspInit 1 */
  81. /* USER CODE END AES2_MspInit 1 */
  82. }
  83. }
  84. void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef* crypHandle) {
  85. if(crypHandle->Instance == AES1) {
  86. /* USER CODE BEGIN AES1_MspDeInit 0 */
  87. /* USER CODE END AES1_MspDeInit 0 */
  88. /* Peripheral clock disable */
  89. __HAL_RCC_AES1_CLK_DISABLE();
  90. /* USER CODE BEGIN AES1_MspDeInit 1 */
  91. /* USER CODE END AES1_MspDeInit 1 */
  92. } else if(crypHandle->Instance == AES2) {
  93. /* USER CODE BEGIN AES2_MspDeInit 0 */
  94. /* USER CODE END AES2_MspDeInit 0 */
  95. /* Peripheral clock disable */
  96. __HAL_RCC_AES2_CLK_DISABLE();
  97. /* USER CODE BEGIN AES2_MspDeInit 1 */
  98. /* USER CODE END AES2_MspDeInit 1 */
  99. }
  100. }
  101. /* USER CODE BEGIN 1 */
  102. /* USER CODE END 1 */
  103. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/