Skip to content

Commit be4ecac

Browse files
committed
Route the single-block RFC 5649 key wrap/unwrap through the ECB crypto callback when HAVE_AES_ECB and ForceZero the temporary key-material buffer.
1 parent 29bc950 commit be4ecac

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

wolfcrypt/src/aes.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16543,9 +16543,17 @@ int wc_AesKeyWrap_Pad_ex(Aes* aes, const byte* in, word32 inSz, byte* out,
1654316543
XMEMCPY(tmp, aiv, KEYWRAP_BLOCK_SIZE);
1654416544
XMEMCPY(tmp + KEYWRAP_BLOCK_SIZE, out + KEYWRAP_BLOCK_SIZE,
1654516545
KEYWRAP_BLOCK_SIZE);
16546+
#ifdef HAVE_AES_ECB
16547+
/* Route through wc_AesEcbEncrypt so an ECB crypto callback can service
16548+
* the block (matches AesKeyWrapRaw); it saves its own registers. */
16549+
ret = wc_AesEcbEncrypt(aes, out, tmp, WC_AES_BLOCK_SIZE);
16550+
#else
1654616551
VECTOR_REGISTERS_PUSH;
1654716552
ret = wc_AesEncryptDirect(aes, out, tmp);
1654816553
VECTOR_REGISTERS_POP;
16554+
#endif
16555+
/* tmp held AIV | plaintext key material */
16556+
ForceZero(tmp, sizeof(tmp));
1654916557
}
1655016558
else {
1655116559
/* run the RFC 3394 loop with the AIV as the initial value */
@@ -16631,13 +16639,21 @@ int wc_AesKeyUnWrap_Pad_ex(Aes* aes, const byte* in, word32 inSz, byte* out,
1663116639
if (n == 1) {
1663216640
/* single block: AIV|P[1] = DEC(K, C[0]|C[1]) */
1663316641
byte tmp[WC_AES_BLOCK_SIZE];
16642+
#ifdef HAVE_AES_ECB
16643+
/* Route through wc_AesEcbDecrypt so an ECB crypto callback can service
16644+
* the block (matches AesKeyUnWrapRaw); it saves its own registers. */
16645+
ret = wc_AesEcbDecrypt(aes, tmp, in, WC_AES_BLOCK_SIZE);
16646+
#else
1663416647
VECTOR_REGISTERS_PUSH;
1663516648
ret = wc_AesDecryptDirect(aes, tmp, in);
1663616649
VECTOR_REGISTERS_POP;
16650+
#endif
1663716651
if (ret == 0) {
1663816652
XMEMCPY(a, tmp, KEYWRAP_BLOCK_SIZE);
1663916653
XMEMCPY(out, tmp + KEYWRAP_BLOCK_SIZE, KEYWRAP_BLOCK_SIZE);
1664016654
}
16655+
/* tmp held AIV | plaintext key material */
16656+
ForceZero(tmp, sizeof(tmp));
1664116657
}
1664216658
else {
1664316659
/* recover A and padded plaintext via the RFC 3394 loop (no check) */

0 commit comments

Comments
 (0)