/** * @brief Decrypt pCypherData in AES CTR decryption mode, * the decyphered data are available in pPlainData. * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains * the configuration information for CRYP module * @param pCypherData: Pointer to the cyphertext buffer * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16. * @param pPlainData: Pointer to the plaintext buffer * @param Timeout: Specify Timeout value * @note This API is provided only to maintain compatibility with legacy software. Users should directly * resort to generic HAL_CRYPEx_AES() API instead (usage recommended). * @retval HAL status */ HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout) { /* Re-initialize AES IP with proper parameters */ if (HAL_CRYP_DeInit(hcryp) != HAL_OK) { return HAL_ERROR; } hcryp->Init.OperatingMode = CRYP_ALGOMODE_DECRYPT; hcryp->Init.ChainingMode = CRYP_CHAINMODE_AES_CTR; hcryp->Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE; if (HAL_CRYP_Init(hcryp) != HAL_OK) { return HAL_ERROR; } return HAL_CRYPEx_AES(hcryp, pCypherData, Size, pPlainData, Timeout); }
static int st_hal_cryp_cbc( mbedtls_aes_context *ctx, uint32_t opmode, size_t length, unsigned char iv[16], uint8_t *input, uint8_t *output) { int status = 0; ctx->hcryp_aes.Init.pInitVect = &iv[0]; // used in process, not in the init if ((ctx->hcryp_aes.Init.OperatingMode != opmode) || \ (ctx->hcryp_aes.Init.ChainingMode != CRYP_CHAINMODE_AES_CBC) || \ (ctx->hcryp_aes.Init.KeyWriteFlag != CRYP_KEY_WRITE_ENABLE)) { /* Re-initialize AES IP with proper parameters */ if (HAL_CRYP_DeInit(&ctx->hcryp_aes) != HAL_OK) return HAL_ERROR; ctx->hcryp_aes.Init.OperatingMode = opmode; ctx->hcryp_aes.Init.ChainingMode = CRYP_CHAINMODE_AES_CBC; ctx->hcryp_aes.Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE; if (HAL_CRYP_Init(&ctx->hcryp_aes) != HAL_OK) return HAL_ERROR; } status = HAL_CRYPEx_AES(&ctx->hcryp_aes, input, length, output, 10); return status; }