summaryrefslogtreecommitdiffstats
path: root/bsps/arm/stm32h7/hal/stm32h7xx_hal_cryp_ex.c
diff options
context:
space:
mode:
Diffstat (limited to 'bsps/arm/stm32h7/hal/stm32h7xx_hal_cryp_ex.c')
-rw-r--r--bsps/arm/stm32h7/hal/stm32h7xx_hal_cryp_ex.c56
1 files changed, 33 insertions, 23 deletions
diff --git a/bsps/arm/stm32h7/hal/stm32h7xx_hal_cryp_ex.c b/bsps/arm/stm32h7/hal/stm32h7xx_hal_cryp_ex.c
index 42ff3401b2..42c4e04ee3 100644
--- a/bsps/arm/stm32h7/hal/stm32h7xx_hal_cryp_ex.c
+++ b/bsps/arm/stm32h7/hal/stm32h7xx_hal_cryp_ex.c
@@ -7,6 +7,17 @@
* functionalities of CRYP extension peripheral:
* + Extended AES processing functions
*
+ ******************************************************************************
+ * @attention
+ *
+ * Copyright (c) 2017 STMicroelectronics.
+ * All rights reserved.
+ *
+ * This software is licensed under terms that can be found in the LICENSE file
+ * in the root directory of this software component.
+ * If no LICENSE file comes with this software, it is provided AS-IS.
+ *
+ ******************************************************************************
@verbatim
==============================================================================
##### How to use this driver #####
@@ -16,18 +27,6 @@
Encryption/Decryption to get the authentication messages.
@endverbatim
- ******************************************************************************
- * @attention
- *
- * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
- * All rights reserved.</center></h2>
- *
- * This software component is licensed by ST under BSD 3-Clause license,
- * the "License"; You may not use this file except in compliance with the
- * License. You may obtain a copy of the License at:
- * opensource.org/licenses/BSD-3-Clause
- *
- ******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
@@ -105,6 +104,9 @@
* @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
* the configuration information for CRYP module
* @param AuthTag: Pointer to the authentication buffer
+ * the AuthTag generated here is 128bits length, if the TAG length is
+ * less than 128bits, user should consider only the valid part of AuthTag
+ * buffer which correspond exactly to TAG length.
* @param Timeout: Timeout duration
* @retval HAL status
*/
@@ -112,9 +114,15 @@ HAL_StatusTypeDef HAL_CRYPEx_AESGCM_GenerateAuthTAG(CRYP_HandleTypeDef *hcryp, u
{
uint32_t tickstart;
uint64_t headerlength = (uint64_t)(hcryp->Init.HeaderSize) * 32U; /* Header length in bits */
- uint64_t inputlength = (uint64_t)hcryp->SizesSum * 8U; /* input length in bits */
+ uint64_t inputlength = (uint64_t)hcryp->SizesSum * 8U; /* Input length in bits */
uint32_t tagaddr = (uint32_t)AuthTag;
+ /* Correct header length if Init.HeaderSize is actually in bytes */
+ if (hcryp->Init.HeaderWidthUnit == CRYP_HEADERWIDTHUNIT_BYTE)
+ {
+ headerlength /= 4U;
+ }
+
if (hcryp->State == HAL_CRYP_STATE_READY)
{
/* Process locked */
@@ -151,7 +159,7 @@ HAL_StatusTypeDef HAL_CRYPEx_AESGCM_GenerateAuthTAG(CRYP_HandleTypeDef *hcryp, u
/* Select final phase */
MODIFY_REG(hcryp->Instance->CR, CRYP_CR_GCM_CCMPH, CRYP_PHASE_FINAL);
- /*ALGODIR bit must be set to ‘0’.*/
+ /*ALGODIR bit must be set to '0'.*/
hcryp->Instance->CR &= ~CRYP_CR_ALGODIR;
/* Enable the CRYP peripheral */
@@ -172,28 +180,28 @@ HAL_StatusTypeDef HAL_CRYPEx_AESGCM_GenerateAuthTAG(CRYP_HandleTypeDef *hcryp, u
#if !defined (CRYP_VER_2_2)
else/* data has to be swapped according to the DATATYPE */
{
- if (hcryp->Init.DataType == CRYP_DATATYPE_1B)
+ if (hcryp->Init.DataType == CRYP_BIT_SWAP)
{
hcryp->Instance->DIN = 0U;
hcryp->Instance->DIN = __RBIT((uint32_t)(headerlength));
hcryp->Instance->DIN = 0U;
hcryp->Instance->DIN = __RBIT((uint32_t)(inputlength));
}
- else if (hcryp->Init.DataType == CRYP_DATATYPE_8B)
+ else if (hcryp->Init.DataType == CRYP_BYTE_SWAP)
{
hcryp->Instance->DIN = 0U;
hcryp->Instance->DIN = __REV((uint32_t)(headerlength));
hcryp->Instance->DIN = 0U;
hcryp->Instance->DIN = __REV((uint32_t)(inputlength));
}
- else if (hcryp->Init.DataType == CRYP_DATATYPE_16B)
+ else if (hcryp->Init.DataType == CRYP_HALFWORD_SWAP)
{
hcryp->Instance->DIN = 0U;
hcryp->Instance->DIN = __ROR((uint32_t)headerlength, 16U);
hcryp->Instance->DIN = 0U;
hcryp->Instance->DIN = __ROR((uint32_t)inputlength, 16U);
}
- else if (hcryp->Init.DataType == CRYP_DATATYPE_32B)
+ else if (hcryp->Init.DataType == CRYP_NO_SWAP)
{
hcryp->Instance->DIN = 0U;
hcryp->Instance->DIN = (uint32_t)(headerlength);
@@ -262,6 +270,9 @@ HAL_StatusTypeDef HAL_CRYPEx_AESGCM_GenerateAuthTAG(CRYP_HandleTypeDef *hcryp, u
* @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
* the configuration information for CRYP module
* @param AuthTag: Pointer to the authentication buffer
+ * the AuthTag generated here is 128bits length, if the TAG length is
+ * less than 128bits, user should consider only the valid part of AuthTag
+ * buffer which correspond exactly to TAG length.
* @param Timeout: Timeout duration
* @retval HAL status
*/
@@ -305,7 +316,7 @@ HAL_StatusTypeDef HAL_CRYPEx_AESCCM_GenerateAuthTAG(CRYP_HandleTypeDef *hcryp, u
/* Disable CRYP to start the final phase */
__HAL_CRYP_DISABLE(hcryp);
- /* Select final phase & ALGODIR bit must be set to ‘0’. */
+ /* Select final phase & ALGODIR bit must be set to '0'. */
MODIFY_REG(hcryp->Instance->CR, CRYP_CR_GCM_CCMPH | CRYP_CR_ALGODIR, CRYP_PHASE_FINAL | CRYP_OPERATINGMODE_ENCRYPT);
/* Enable the CRYP peripheral */
@@ -334,7 +345,7 @@ HAL_StatusTypeDef HAL_CRYPEx_AESCCM_GenerateAuthTAG(CRYP_HandleTypeDef *hcryp, u
#if !defined (CRYP_VER_2_2)
else /* data has to be swapped according to the DATATYPE */
{
- if (hcryp->Init.DataType == CRYP_DATATYPE_8B)
+ if (hcryp->Init.DataType == CRYP_BYTE_SWAP)
{
hcryp->Instance->DIN = __REV(*(uint32_t *)(ctr0addr));
ctr0addr += 4U;
@@ -344,7 +355,7 @@ HAL_StatusTypeDef HAL_CRYPEx_AESCCM_GenerateAuthTAG(CRYP_HandleTypeDef *hcryp, u
ctr0addr += 4U;
hcryp->Instance->DIN = __REV(*(uint32_t *)(ctr0addr));
}
- else if (hcryp->Init.DataType == CRYP_DATATYPE_16B)
+ else if (hcryp->Init.DataType == CRYP_HALFWORD_SWAP)
{
hcryp->Instance->DIN = __ROR(*(uint32_t *)(ctr0addr), 16U);
ctr0addr += 4U;
@@ -354,7 +365,7 @@ HAL_StatusTypeDef HAL_CRYPEx_AESCCM_GenerateAuthTAG(CRYP_HandleTypeDef *hcryp, u
ctr0addr += 4U;
hcryp->Instance->DIN = __ROR(*(uint32_t *)(ctr0addr), 16U);
}
- else if (hcryp->Init.DataType == CRYP_DATATYPE_1B)
+ else if (hcryp->Init.DataType == CRYP_BIT_SWAP)
{
hcryp->Instance->DIN = __RBIT(*(uint32_t *)(ctr0addr));
ctr0addr += 4U;
@@ -445,4 +456,3 @@ HAL_StatusTypeDef HAL_CRYPEx_AESCCM_GenerateAuthTAG(CRYP_HandleTypeDef *hcryp, u
/**
* @}
*/
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/