aes.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. {
  32. /* USER CODE BEGIN AES1_Init 0 */
  33. /* USER CODE END AES1_Init 0 */
  34. /* USER CODE BEGIN AES1_Init 1 */
  35. /* USER CODE END AES1_Init 1 */
  36. hcryp1.Instance = AES1;
  37. hcryp1.Init.DataType = CRYP_DATATYPE_32B;
  38. hcryp1.Init.KeySize = CRYP_KEYSIZE_128B;
  39. hcryp1.Init.pKey = (uint32_t *)pKeyAES1;
  40. hcryp1.Init.Algorithm = CRYP_AES_ECB;
  41. hcryp1.Init.DataWidthUnit = CRYP_DATAWIDTHUNIT_WORD;
  42. hcryp1.Init.KeyIVConfigSkip = CRYP_KEYIVCONFIG_ALWAYS;
  43. if (HAL_CRYP_Init(&hcryp1) != HAL_OK)
  44. {
  45. Error_Handler();
  46. }
  47. /* USER CODE BEGIN AES1_Init 2 */
  48. /* USER CODE END AES1_Init 2 */
  49. }
  50. /* AES2 init function */
  51. void MX_AES2_Init(void)
  52. {
  53. /* USER CODE BEGIN AES2_Init 0 */
  54. /* USER CODE END AES2_Init 0 */
  55. /* USER CODE BEGIN AES2_Init 1 */
  56. /* USER CODE END AES2_Init 1 */
  57. hcryp2.Instance = AES2;
  58. hcryp2.Init.DataType = CRYP_DATATYPE_32B;
  59. hcryp2.Init.KeySize = CRYP_KEYSIZE_128B;
  60. hcryp2.Init.pKey = (uint32_t *)pKeyAES2;
  61. hcryp2.Init.Algorithm = CRYP_AES_ECB;
  62. hcryp2.Init.DataWidthUnit = CRYP_DATAWIDTHUNIT_WORD;
  63. hcryp2.Init.KeyIVConfigSkip = CRYP_KEYIVCONFIG_ALWAYS;
  64. if (HAL_CRYP_Init(&hcryp2) != HAL_OK)
  65. {
  66. Error_Handler();
  67. }
  68. /* USER CODE BEGIN AES2_Init 2 */
  69. /* USER CODE END AES2_Init 2 */
  70. }
  71. void HAL_CRYP_MspInit(CRYP_HandleTypeDef* crypHandle)
  72. {
  73. if(crypHandle->Instance==AES1)
  74. {
  75. /* USER CODE BEGIN AES1_MspInit 0 */
  76. /* USER CODE END AES1_MspInit 0 */
  77. /* AES1 clock enable */
  78. __HAL_RCC_AES1_CLK_ENABLE();
  79. /* USER CODE BEGIN AES1_MspInit 1 */
  80. /* USER CODE END AES1_MspInit 1 */
  81. }
  82. else if(crypHandle->Instance==AES2)
  83. {
  84. /* USER CODE BEGIN AES2_MspInit 0 */
  85. /* USER CODE END AES2_MspInit 0 */
  86. /* AES2 clock enable */
  87. __HAL_RCC_AES2_CLK_ENABLE();
  88. /* USER CODE BEGIN AES2_MspInit 1 */
  89. /* USER CODE END AES2_MspInit 1 */
  90. }
  91. }
  92. void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef* crypHandle)
  93. {
  94. if(crypHandle->Instance==AES1)
  95. {
  96. /* USER CODE BEGIN AES1_MspDeInit 0 */
  97. /* USER CODE END AES1_MspDeInit 0 */
  98. /* Peripheral clock disable */
  99. __HAL_RCC_AES1_CLK_DISABLE();
  100. /* USER CODE BEGIN AES1_MspDeInit 1 */
  101. /* USER CODE END AES1_MspDeInit 1 */
  102. }
  103. else if(crypHandle->Instance==AES2)
  104. {
  105. /* USER CODE BEGIN AES2_MspDeInit 0 */
  106. /* USER CODE END AES2_MspDeInit 0 */
  107. /* Peripheral clock disable */
  108. __HAL_RCC_AES2_CLK_DISABLE();
  109. /* USER CODE BEGIN AES2_MspDeInit 1 */
  110. /* USER CODE END AES2_MspDeInit 1 */
  111. }
  112. }
  113. /* USER CODE BEGIN 1 */
  114. /* USER CODE END 1 */
  115. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/