@@ -1600,13 +1600,14 @@ int aes_init(void)
16001600 /* register AES crypto callback */
16011601 wc_CryptoCb_RegisterDevice (devId , wc_tsip_AesCipher , NULL );
16021602
1603- /* AES_ENCRYPTION is used for both directions in CTR */
1604- /* unwrapped key never leaves TSIP and is referenced by tsip_keyIdx */
1603+ /* AES_ENCRYPTION is used for both directions in CTR
1604+ * IV is set later with "wc_AesSetIV" */
16051605 wc_AesSetKeyDirect (& aes_enc , enc_key -> encrypted_user_key ,
1606- ENCRYPT_KEY_SIZE , enc_key -> initial_vector , AES_ENCRYPTION );
1606+ ENCRYPT_KEY_SIZE , NULL , AES_ENCRYPTION );
16071607 wc_AesSetKeyDirect (& aes_dec , enc_key -> encrypted_user_key ,
1608- ENCRYPT_KEY_SIZE , enc_key -> initial_vector , AES_ENCRYPTION );
1608+ ENCRYPT_KEY_SIZE , NULL , AES_ENCRYPTION );
16091609
1610+ /* set IV nonce use in aes_set_iv */
16101611 XMEMCPY (encrypt_iv_nonce , enc_key -> initial_vector , ENCRYPT_NONCE_SIZE );
16111612 encrypt_initialized = 1 ;
16121613 }
@@ -1619,7 +1620,6 @@ int aes_init(void)
16191620 ENCRYPT_TMP_SECRET_OFFSET );
16201621#endif
16211622 uint8_t ff [ENCRYPT_KEY_SIZE ];
1622- uint8_t iv_buf [ENCRYPT_NONCE_SIZE ];
16231623 uint8_t * stored_nonce ;
16241624
16251625#ifdef NVM_FLASH_WRITEONCE
@@ -1641,11 +1641,13 @@ int aes_init(void)
16411641 if (XMEMCMP (key , ff , ENCRYPT_KEY_SIZE ) == 0 )
16421642 return -1 ;
16431643
1644+ /* AES_ENCRYPTION is used for both directions in CTR
1645+ * IV is set later with "wc_AesSetIV" */
1646+ wc_AesSetKeyDirect (& aes_enc , key , ENCRYPT_KEY_SIZE , NULL , AES_ENCRYPTION );
1647+ wc_AesSetKeyDirect (& aes_dec , key , ENCRYPT_KEY_SIZE , NULL , AES_ENCRYPTION );
1648+
1649+ /* set IV nonce use in aes_set_iv */
16441650 XMEMCPY (encrypt_iv_nonce , stored_nonce , ENCRYPT_NONCE_SIZE );
1645- XMEMCPY (iv_buf , stored_nonce , ENCRYPT_NONCE_SIZE );
1646- /* AES_ENCRYPTION is used for both directions in CTR */
1647- wc_AesSetKeyDirect (& aes_enc , key , ENCRYPT_KEY_SIZE , iv_buf , AES_ENCRYPTION );
1648- wc_AesSetKeyDirect (& aes_dec , key , ENCRYPT_KEY_SIZE , iv_buf , AES_ENCRYPTION );
16491651 encrypt_initialized = 1 ;
16501652#endif
16511653 return 0 ;
0 commit comments