Topic: AES CTR

Hi,

I'm trying to implement an a bstraction layer for Crypto functionality, when i took a look at the forum to find how to implement
AES-CTR using WolfSSL i saw that the function declaration is bit different fom other Crypto libraries.

after research i can say that the IV parameter can be set to the AES context by:
wc_AesSetIV(Aes* aes, const byte* iv)

but still missing the option to pass the:
* stream block
* offset inside the stream block

can you please or refer to an example in how to use wolfSSL APIs in order to implement AES-CTR

Thanks

Share

Re: AES CTR

Hi mohammad.abomokh,

For example usage please see file <wolfssl-root>/wolfcrypt/test/test.c and in the "aes_test()" function see section wrapped in:

 #ifdef WOLFSSL_AES_COUNTER

Also including excerpt from "chapter 18: wolfCrypt API Reference" of the wolfSSL Manual: https://www.wolfssl.com/wolfSSL/Docs-wo … i-aes.html


wc_AesCtrEncrypt
Synopsis:
#include <wolfssl/wolfcrypt/aes.h>

void wc_AesCtrEncrypt(Aes* aes, byte* out, const byte* in, word32 sz);

Description:
Encrypts/Decrypts a message from the input buffer in, and places the resulting cipher text in the output buffer out using CTR mode with AES. This function is only enabled if WOLFSSL_AES_COUNTER is enabled at compile time. The AES structure should be initialized through AesSetKey before calling this function. Note that this function is used for both decryption and encryption.

Return Values:
No return value for this function.

Parameters:
aes - pointer to the AES object used to decrypt data
out - pointer to the output buffer in which to store the cipher text of the encrypted message
in - pointer to the input buffer containing plain text to be encrypted
sz - size of the input plain text

Example:
Aes enc_dec;
// initialize enc_dec with AesSetKeyDirect, using direction AES_ENCRYPTION

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_dec, cipher, msg, sizeof(msg)); // encrypt plain
wc_AesCtrEncrypt(&enc_dec, decrypted, cipher, sizeof(cipher)); // decrypt cipher text

See Also:
wc_AesSetKey

Regards,

Kaleb

Re: AES CTR

Thanks for the quick response.

Share