Update v9.3
https://github.com/acagliano/hashlib/releases/tag/v9.3
Major Changes to AES implementation
New API for AES
Arguments for Flags
Test away!
https://github.com/acagliano/hashlib/releases/tag/v9.3
Major Changes to AES implementation
- aes_loadkey() is now aes_init()
- Most of the cipher initialization now happens via the aes_init() function, including the nonce, the cipher mode, and the padding mode, and other functionalities.
- Cipher configuration parameters passed as flags bitwise-OR'd together.
- Padding in CBC mode is now added internally within the last block of encryption. Callable functions for padding are no longer used and have been removed.
- Cipher state "contexts" loaded with init() are stateful and one-directional.Once a context is used for encryption or decryption, attempting to use it for the opposite operation will return an error. Two-way communication now needs two contexts initialized with the same key and parameters, but the correct nonce.
- Encrypt and decrypt are now chainable operations. This means that `aes_encrypt(msg1+msg2)` is functionally-identical to `aes_encrypt(msg1) + aes_encrypt(msg2)`, once padding is cleared (if applicable). Same is true for decrypt.
New API for AES
Code Select
aes_init(aes_ctx* ctx, const void* key, size_t keylen, const void* iv, uint24_t flags);
aes_encrypt(aes_ctx* ctx, void* plaintext, size_t len, void* ciphertext);
aes_decrypt(aes_ctx* ctx, void* ciphertext, size_t len, void* plaintext);
Arguments for Flags
Code Select
// cipher mode (2-bit flag)
AES_MODE_CBC // default
AES_MODE_CTR
// padding mode (2-bit flag)
PAD_PKCS7 // default
PAD_ISO2
// CTR mode nonce length (4-bit flag)
AES_CTR_NONCELEN(len) // default = 8 bytes
// CTR mode counter length (4-bit flag)
AES_CTR_COUNTERLEN(len) // default = 8 bytes
// Ex1: Set CTR mode, with 8 byte nonce length and 4 byte counter length
aes_init(&ctx, key, sizeof key, iv, AES_MODE_CTR | AES_CTR_NONCELEN(8) | AES_CTR_COUNTERLEN(4));
// Ex2: Set CBC mode, with padding mode ISO-9797 M2
aes_init(&ctx, key, sizeof key, iv, AES_MODE_CBC | PAD_ISO2);
Test away!