Topic: In-place aes CTR

Can i use the same buffer for input and output when calling wc_AesCtrEncrypt?

Share

Re: In-place aes CTR

Hi dbenor,

I had this question come up on another forum query recently. As a result I updated the wolfSSL API Reference document but those changes have not yet posted to the website.

The answer is NO you do not want to use the same buffer. Here is a code example of how to use wc_AesCtrEncrypt for both encryption and decryption:

Aes enc;
Aes dec;
/* initialize enc and dec with AesSetKeyDirect, using direction AES_ENCRYPTION
 * since the underlying API only calls Encrypt and by default calling encrypt on
 * a cipher results in a decryption of the cipher
 */

byte msg[AES_BLOCK_SIZE * n]; //n being a positive integer making msg some multiple of 16 bytes
// fill plain with message text
byte cipher[AES_BLOCK_SIZE * n];
byte decrypted[AES_BLOCK_SIZE * n];

wc_AesCtrEncrypt(&enc, cipher, msg, sizeof(msg)); // encrypt plain
wc_AesCtrEncrypt(&dec, decrypted, cipher, sizeof(cipher)); // decrypt cipher text

Regards,

Kaleb