Skip to content

Commit

Permalink
hal: openisa: pass MIC status from CAUv3 on stack
Browse files Browse the repository at this point in the history
Pass the status of the MIC validation to the caller

Signed-off-by: Cristi Caciuloiu <cristian.caciuloiu@nxp.com>
  • Loading branch information
cristic-devel authored and MaureenHelm committed Feb 12, 2020
1 parent 9bfbe35 commit 3b54187
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions vega_sdk_riscv/devices/RV32M1/drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ zephyr_sources_ifdef(CONFIG_SPI_RV32M1_LPSPI fsl_lpspi.c)
zephyr_sources_ifdef(CONFIG_PWM_RV32M1_TPM fsl_tpm.c)
zephyr_sources_ifdef(CONFIG_SOC_FLASH_RV32M1 fsl_flash.c)
zephyr_sources_ifdef(CONFIG_ENTROPY_RV32M1_TRNG fsl_trng.c)
zephyr_sources_ifdef(CONFIG_HAS_RV32M1_CAU3_BLE fsl_cau3_ble.c)
10 changes: 8 additions & 2 deletions vega_sdk_riscv/devices/RV32M1/drivers/fsl_cau3_ble.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-3-Clause
*/

#include "fsl_cau3.h"
#include "fsl_cau3_ble.h"

/*******************************************************************************
* Definitions
Expand Down Expand Up @@ -1218,6 +1218,7 @@ static int cau3_aes_ccm_decrypt(CAU3_Type *base,
uint32_t nonceSz,
const uint8_t *authTag,
uint32_t authTagSz,
uint8_t *authPassed,
const uint8_t *authIn,
uint32_t authInSz)
{
Expand Down Expand Up @@ -1273,7 +1274,10 @@ static int cau3_aes_ccm_decrypt(CAU3_Type *base,
if (memcmp(xPtr, tPtr, authTagSz) != 0) {
// If the authTag check fails, don't keep the decrypted data.
memset(out, 0, inSz);
*authPassed = 0;
return (completionStatus);
} else {
*authPassed = 1;
}

cau3_aes_ccm_clear_mem(xPtr, aPtr, CAU3_AES_BLOCK_SIZE);
Expand Down Expand Up @@ -1319,15 +1323,17 @@ uint32_t CAU3_AES_CCM_DecryptTag(CAU3_Type *base,
size_t authTagSize)
{
status_t completionStatus;
uint8_t authPassed = 0;

completionStatus = cau3_aes_ccm_decrypt(base, handle->keySlot, plainText, cipherText, plainTextSize,
nonce, nonceSize, authTag, authTagSize, aad, aadSize);
nonce, nonceSize, authTag, authTagSize, &authPassed, aad, aadSize);

if (completionStatus != kStatus_Success)
CAU3_ForceError(base, handle->taskDone);
else
completionStatus = cau3_execute_null_task(base, handle->taskDone);

handle->micPassed = authPassed;
return (completionStatus);
}

Expand Down
4 changes: 4 additions & 0 deletions vega_sdk_riscv/devices/RV32M1/drivers/fsl_cau3_ble.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ typedef struct _cau3_handle
{
cau3_task_done_t taskDone; /*!< Specify CAU3 task done signalling to Host CPU. */
cau3_key_slot_t keySlot; /*!< For operations with key (such as AES encryption/decryption), specify CAU3 key slot. */
uint8_t micPassed; /*!< For decryption, store the status of the MIC validation. */
} cau3_handle_t;

/*! @} */
Expand Down Expand Up @@ -126,6 +127,9 @@ typedef enum _cau3_hash_algo_t {
/*! @brief CAU3 HASH Context size. */
#define CAU3_HASH_CTX_SIZE 58

/*! @brief MAC size for BLE (called MIC). */
#define CAU3_BLE_MIC_SIZE 4

/*! @brief Storage type used to save hash context. */
typedef struct _cau3_hash_ctx_t
{
Expand Down

0 comments on commit 3b54187

Please sign in to comment.