2020 int ret = 0;
2121 byte key[] = { some 16, 24 or 32 byte key };
2222 byte iv[] = { some 16 byte iv };
23+ if (ret = wc_AesInit(gmac.aes, HEAP_HINT, INVALID_DEVID) != 0) {
24+ // failed to initialize aes key
25+ }
2326 if (ret = wc_AesSetKey(&enc, key, AES_BLOCK_SIZE, iv,
2427 AES_ENCRYPTION) != 0) {
2528 // failed to set aes key
@@ -94,7 +97,8 @@ int wc_AesSetIV(Aes* aes, const byte* iv);
9497 \code
9598 Aes enc;
9699 int ret = 0;
97- // initialize enc with AesSetKey, using direction AES_ENCRYPTION
100+ // initialize enc with wc_AesInit and wc_AesSetKey, using direction
101+ // AES_ENCRYPTION
98102 byte msg[AES_BLOCK_SIZE * n]; // multiple of 16 bytes
99103 // fill msg with data
100104 byte cipher[AES_BLOCK_SIZE * n]; // Some multiple of 16 bytes
@@ -103,6 +107,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv);
103107 }
104108 \endcode
105109
110+ \sa wc_AesInit
106111 \sa wc_AesSetKey
107112 \sa wc_AesSetIV
108113 \sa wc_AesCbcDecrypt
@@ -146,7 +151,8 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out,
146151 \code
147152 Aes dec;
148153 int ret = 0;
149- // initialize dec with AesSetKey, using direction AES_DECRYPTION
154+ // initialize dec with wc_AesInit and wc_AesSetKey, using direction
155+ // AES_DECRYPTION
150156 byte cipher[AES_BLOCK_SIZE * n]; // some multiple of 16 bytes
151157 // fill cipher with cipher text
152158 byte plain [AES_BLOCK_SIZE * n];
@@ -155,6 +161,7 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out,
155161 }
156162 \endcode
157163
164+ \sa wc_AesInit
158165 \sa wc_AesSetKey
159166 \sa wc_AesCbcEncrypt
160167*/
@@ -187,11 +194,10 @@ int wc_AesCbcDecrypt(Aes* aes, byte* out,
187194 \code
188195 Aes enc;
189196 Aes dec;
190- // initialize enc and dec with AesSetKeyDirect, using direction
191- AES_ENCRYPTION
192- // since the underlying API only calls Encrypt and by default calling
193- encrypt on
194- // a cipher results in a decryption of the cipher
197+ // initialize enc and dec with wc_AesInit and wc_AesSetKeyDirect, using
198+ // direction AES_ENCRYPTION since the underlying API only calls Encrypt
199+ // and by default calling encrypt on a cipher results in a decryption of
200+ // the cipher
195201
196202 byte msg[AES_BLOCK_SIZE * n]; //n being a positive integer making msg
197203 some multiple of 16 bytes
@@ -229,7 +235,8 @@ int wc_AesCtrEncrypt(Aes* aes, byte* out,
229235 _Example_
230236 \code
231237 Aes enc;
232- // initialize enc with AesSetKey, using direction AES_ENCRYPTION
238+ // initialize enc with wc_AesInit and wc_AesSetKey, using direction
239+ // AES_ENCRYPTION
233240 byte msg [AES_BLOCK_SIZE]; // 16 bytes
234241 // initialize msg with plain text to encrypt
235242 byte cipher[AES_BLOCK_SIZE];
@@ -263,7 +270,8 @@ int wc_AesEncryptDirect(Aes* aes, byte* out, const byte* in);
263270 _Example_
264271 \code
265272 Aes dec;
266- // initialize enc with AesSetKey, using direction AES_DECRYPTION
273+ // initialize enc with wc_AesInit and wc_AesSetKey, using direction
274+ // AES_DECRYPTION
267275 byte cipher [AES_BLOCK_SIZE]; // 16 bytes
268276 // initialize cipher with cipher text to decrypt
269277 byte msg[AES_BLOCK_SIZE];
@@ -303,6 +311,10 @@ int wc_AesDecryptDirect(Aes* aes, byte* out, const byte* in);
303311 int ret = 0;
304312 byte key[] = { some 16, 24, or 32 byte key };
305313 byte iv[] = { some 16 byte iv };
314+
315+ if (ret = wc_AesInit(&enc, HEAP_HINT, INVALID_DEVID) != 0) {
316+ // failed to initialize aes key
317+ }
306318 if (ret = wc_AesSetKeyDirect(&enc, key, sizeof(key), iv,
307319 AES_ENCRYPTION) != 0) {
308320 // failed to set aes key
@@ -335,6 +347,9 @@ int wc_AesSetKeyDirect(Aes* aes, const byte* key, word32 len,
335347 Aes enc;
336348 int ret = 0;
337349 byte key[] = { some 16, 24,32 byte key };
350+ if (ret = wc_AesInit(&enc, HEAP_HINT, INVALID_DEVID) != 0) {
351+ // failed to initialize aes key
352+ }
338353 if (ret = wc_AesGcmSetKey(&enc, key, sizeof(key)) != 0) {
339354 // failed to set aes key
340355 }
@@ -373,7 +388,7 @@ int wc_AesGcmSetKey(Aes* aes, const byte* key, word32 len);
373388 _Example_
374389 \code
375390 Aes enc;
376- // initialize aes structure by calling wc_AesGcmSetKey
391+ // initialize Aes structure by calling wc_AesInit() and wc_AesGcmSetKey
377392
378393 byte plain[AES_BLOCK_LENGTH * n]; //n being a positive integer
379394 making plain some multiple of 16 bytes
@@ -424,7 +439,8 @@ int wc_AesGcmEncrypt(Aes* aes, byte* out,
424439 _Example_
425440 \code
426441 Aes enc; //can use the same struct as was passed to wc_AesGcmEncrypt
427- // initialize aes structure by calling wc_AesGcmSetKey if not already done
442+ // initialize aes structure by calling wc_AesInit and wc_AesGcmSetKey
443+ // if not already done
428444
429445 byte cipher[AES_BLOCK_LENGTH * n]; //n being a positive integer
430446 making cipher some multiple of 16 bytes
@@ -529,6 +545,7 @@ int wc_GmacUpdate(Gmac* gmac, const byte* iv, word32 ivSz,
529545 Aes enc;
530546 key[] = { some 16, 24, or 32 byte length key };
531547
548+ wc_AesInit(&aes, HEAP_HINT, INVALID_DEVID); // Make sure devId updated
532549 wc_AesCcmSetKey(&aes, key, sizeof(key));
533550 \endcode
534551
@@ -564,7 +581,7 @@ int wc_AesCcmSetKey(Aes* aes, const byte* key, word32 keySz);
564581 _Example_
565582 \code
566583 Aes enc;
567- // initialize enc with wc_AesCcmSetKey
584+ // initialize enc with wc_AesInit and wc_AesCcmSetKey
568585
569586 nonce[] = { initialize nonce };
570587 plain[] = { some plain text message };
@@ -616,7 +633,7 @@ int wc_AesCcmEncrypt(Aes* aes, byte* out,
616633 _Example_
617634 \code
618635 Aes dec;
619- // initialize dec with wc_AesCcmSetKey
636+ // initialize dec with wc_AesInit and wc_AesCcmSetKey
620637
621638 nonce[] = { initialize nonce };
622639 cipher[] = { encrypted message };
0 commit comments