@@ -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