aes.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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) 2020 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. hcryp1.Instance = AES1;
  33. hcryp1.Init.DataType = CRYP_DATATYPE_32B;
  34. hcryp1.Init.KeySize = CRYP_KEYSIZE_128B;
  35. hcryp1.Init.pKey = (uint32_t *)pKeyAES1;
  36. hcryp1.Init.Algorithm = CRYP_AES_ECB;
  37. hcryp1.Init.DataWidthUnit = CRYP_DATAWIDTHUNIT_WORD;
  38. hcryp1.Init.KeyIVConfigSkip = CRYP_KEYIVCONFIG_ALWAYS;
  39. if (HAL_CRYP_Init(&hcryp1) != HAL_OK)
  40. {
  41. Error_Handler();
  42. }
  43. }
  44. /* AES2 init function */
  45. void MX_AES2_Init(void)
  46. {
  47. hcryp2.Instance = AES2;
  48. hcryp2.Init.DataType = CRYP_DATATYPE_32B;
  49. hcryp2.Init.KeySize = CRYP_KEYSIZE_128B;
  50. hcryp2.Init.pKey = (uint32_t *)pKeyAES2;
  51. hcryp2.Init.Algorithm = CRYP_AES_ECB;
  52. hcryp2.Init.DataWidthUnit = CRYP_DATAWIDTHUNIT_WORD;
  53. hcryp2.Init.KeyIVConfigSkip = CRYP_KEYIVCONFIG_ALWAYS;
  54. if (HAL_CRYP_Init(&hcryp2) != HAL_OK)
  55. {
  56. Error_Handler();
  57. }
  58. }
  59. void HAL_CRYP_MspInit(CRYP_HandleTypeDef* crypHandle)
  60. {
  61. if(crypHandle->Instance==AES1)
  62. {
  63. /* USER CODE BEGIN AES1_MspInit 0 */
  64. /* USER CODE END AES1_MspInit 0 */
  65. /* AES1 clock enable */
  66. __HAL_RCC_AES1_CLK_ENABLE();
  67. /* USER CODE BEGIN AES1_MspInit 1 */
  68. /* USER CODE END AES1_MspInit 1 */
  69. }
  70. else if(crypHandle->Instance==AES2)
  71. {
  72. /* USER CODE BEGIN AES2_MspInit 0 */
  73. /* USER CODE END AES2_MspInit 0 */
  74. /* AES2 clock enable */
  75. __HAL_RCC_AES2_CLK_ENABLE();
  76. /* USER CODE BEGIN AES2_MspInit 1 */
  77. /* USER CODE END AES2_MspInit 1 */
  78. }
  79. }
  80. void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef* crypHandle)
  81. {
  82. if(crypHandle->Instance==AES1)
  83. {
  84. /* USER CODE BEGIN AES1_MspDeInit 0 */
  85. /* USER CODE END AES1_MspDeInit 0 */
  86. /* Peripheral clock disable */
  87. __HAL_RCC_AES1_CLK_DISABLE();
  88. /* USER CODE BEGIN AES1_MspDeInit 1 */
  89. /* USER CODE END AES1_MspDeInit 1 */
  90. }
  91. else if(crypHandle->Instance==AES2)
  92. {
  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****/