Skip to content

Commit f7179f5

Browse files
committed
Issue #883 - Removed AesContext and AesCmacCtx from SecureElementNvCtx_t
1 parent b00527b commit f7179f5

File tree

2 files changed

+16
-25
lines changed

2 files changed

+16
-25
lines changed

src/peripherals/atecc608a-tnglora-se/atecc608a-tnglora-se.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ typedef struct sSecureElementNvCtx
8484
* Pin storage
8585
*/
8686
uint8_t Pin[SE_PIN_SIZE];
87-
/*!
88-
* CMAC computation context variable
89-
*/
90-
atca_aes_cmac_ctx_t AtcaAesCmacCtx;
9187
/*!
9288
* LoRaWAN key list
9389
*/
@@ -275,19 +271,20 @@ static SecureElementStatus_t ComputeCmac( uint8_t* micBxBuffer, uint8_t* buffer,
275271
return retval;
276272
}
277273

278-
ATCA_STATUS status =
279-
atcab_aes_cmac_init( &SeNvmCtx.AtcaAesCmacCtx, keyItem->KeySlotNumber, keyItem->KeyBlockIndex );
274+
atca_aes_cmac_ctx_t atcaAesCmacCtx;
275+
ATCA_STATUS status =
276+
atcab_aes_cmac_init( &atcaAesCmacCtx, keyItem->KeySlotNumber, keyItem->KeyBlockIndex );
280277

281278
if( ATCA_SUCCESS == status )
282279
{
283280
if( micBxBuffer != NULL )
284281
{
285-
atcab_aes_cmac_update( &SeNvmCtx.AtcaAesCmacCtx, micBxBuffer, 16 );
282+
atcab_aes_cmac_update( &atcaAesCmacCtx, micBxBuffer, 16 );
286283
}
287284

288-
atcab_aes_cmac_update( &SeNvmCtx.AtcaAesCmacCtx, buffer, size );
285+
atcab_aes_cmac_update( &atcaAesCmacCtx, buffer, size );
289286

290-
atcab_aes_cmac_finish( &SeNvmCtx.AtcaAesCmacCtx, Cmac, 16 );
287+
atcab_aes_cmac_finish( &atcaAesCmacCtx, Cmac, 16 );
291288

292289
*cmac = ( uint32_t )( ( uint32_t ) Cmac[3] << 24 | ( uint32_t ) Cmac[2] << 16 | ( uint32_t ) Cmac[1] << 8 |
293290
( uint32_t ) Cmac[0] );

src/peripherals/soft-se/soft-se.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,6 @@ typedef struct sSecureElementNvCtx
7373
* Pin storage
7474
*/
7575
uint8_t Pin[SE_PIN_SIZE];
76-
/*
77-
* AES computation context variable
78-
*/
79-
aes_context AesContext;
80-
/*
81-
* CMAC computation context variable
82-
*/
83-
AES_CMAC_CTX AesCmacCtx[1];
8476
/*
8577
* Key List
8678
*/
@@ -167,24 +159,25 @@ static SecureElementStatus_t ComputeCmac( uint8_t* micBxBuffer, uint8_t* buffer,
167159
}
168160

169161
uint8_t Cmac[16];
162+
AES_CMAC_CTX aesCmacCtx[1];
170163

171-
AES_CMAC_Init( SeNvmCtx.AesCmacCtx );
164+
AES_CMAC_Init( aesCmacCtx );
172165

173166
Key_t* keyItem;
174167
SecureElementStatus_t retval = GetKeyByID( keyID, &keyItem );
175168

176169
if( retval == SECURE_ELEMENT_SUCCESS )
177170
{
178-
AES_CMAC_SetKey( SeNvmCtx.AesCmacCtx, keyItem->KeyValue );
171+
AES_CMAC_SetKey( aesCmacCtx, keyItem->KeyValue );
179172

180173
if( micBxBuffer != NULL )
181174
{
182-
AES_CMAC_Update( SeNvmCtx.AesCmacCtx, micBxBuffer, 16 );
175+
AES_CMAC_Update( aesCmacCtx, micBxBuffer, 16 );
183176
}
184177

185-
AES_CMAC_Update( SeNvmCtx.AesCmacCtx, buffer, size );
178+
AES_CMAC_Update( aesCmacCtx, buffer, size );
186179

187-
AES_CMAC_Final( Cmac, SeNvmCtx.AesCmacCtx );
180+
AES_CMAC_Final( Cmac, aesCmacCtx );
188181

189182
// Bring into the required format
190183
*cmac = ( uint32_t )( ( uint32_t ) Cmac[3] << 24 | ( uint32_t ) Cmac[2] << 16 | ( uint32_t ) Cmac[1] << 8 |
@@ -327,20 +320,21 @@ SecureElementStatus_t SecureElementAesEncrypt( uint8_t* buffer, uint16_t size, K
327320
return SECURE_ELEMENT_ERROR_BUF_SIZE;
328321
}
329322

330-
memset1( SeNvmCtx.AesContext.ksch, '\0', 240 );
323+
aes_context aesContext;
324+
memset1( aesContext.ksch, '\0', 240 );
331325

332326
Key_t* pItem;
333327
SecureElementStatus_t retval = GetKeyByID( keyID, &pItem );
334328

335329
if( retval == SECURE_ELEMENT_SUCCESS )
336330
{
337-
aes_set_key( pItem->KeyValue, 16, &SeNvmCtx.AesContext );
331+
aes_set_key( pItem->KeyValue, 16, &aesContext );
338332

339333
uint8_t block = 0;
340334

341335
while( size != 0 )
342336
{
343-
aes_encrypt( &buffer[block], &encBuffer[block], &SeNvmCtx.AesContext );
337+
aes_encrypt( &buffer[block], &encBuffer[block], &aesContext );
344338
block = block + 16;
345339
size = size - 16;
346340
}

0 commit comments

Comments
 (0)