2024-07-16 12:38 AM
I'm using an STSAFE-A110 chip with SPL02 profile on a custom board and trying to get StSafeA_WrapLocalEnvelope() function working. I've already successfully paired my chip with my MCU/FW by writing the default host MAC key from the ST examples to the STSAFE chip:
// Call nrf_crypto_init() at start-up.
//
// Return value checks are omitted below for brivity, but
// the original code had them in place and no errors were detected.
void StSafeA_AES_MAC_Start(void **ppAesMacCtx)
{
uint8_t iv[NRF_CRYPTO_MBEDTLS_AES_IV_SIZE] = {0};
*ppAesMacCtx = &cbc_mac_128_ctx;
nrf_crypto_aes_init(*ppAesMacCtx,
&g_nrf_crypto_aes_cbc_mac_128_pad_pkcs7_info,
NRF_CRYPTO_MAC_CALCULATE);
nrf_crypto_aes_key_set(*ppAesMacCtx, (uint8_t*)gHostMacKey);
nrf_crypto_aes_iv_set(*ppAesMacCtx, iv);
}
void StSafeA_AES_MAC_Update(uint8_t *pInData, uint16_t InDataLength, void *pAesMacCtx)
{
uint8_t mac[16] = {0};
nrf_crypto_aes_update(pAesMacCtx,
(uint8_t *)pInData,
InDataLength,
(uint8_t *)mac);
}
static uint8_t gMac[16] = {0};
__weak void StSafeA_AES_MAC_LastUpdate(uint8_t *pInData, uint16_t InDataLength, void *pAesMacCtx)
{
size_t outLen = sizeof(gMac);
nrf_crypto_aes_finalize(pAesMacCtx,
(uint8_t *)pInData,
InDataLength,
(uint8_t *)gMac,
&outLen);
}
__weak void StSafeA_AES_MAC_Final(uint8_t *pOutMac, void **ppAesMacCtx)
{
memcpy(pOutMac, gMac, sizeof(gMac));
nrf_crypto_aes_uninit(*ppAesMacCtx);
*ppAesMacCtx = NULL;
}
Thank you!