C library for encrypting & decrypting data with AES-128/192/256. (WIP)
WIP
Suppose, we need to encrypt data in inbuf
with AES-128-CTR & put the encrypted
data into outbuf
:
/* ... ... are to be replaced with appropriate values. */
const unsigned char inbuf[100] = ... data ...; /* Plain text. */
const unsigned char key[16] = ... key ...; /* Key to encrypt `inbuf` with. */
unsigned char outbuf[100]; /* Destination of encrypted data. */
First, we would initialize the AES context with aes_init
function:
AesContext ctx;
aes_init(&ctx, KEY_TYPE_AES128, key);
Then, we would use aes_ctr_xcrypt()
to encrypt the data:
/* Set initial IV. Replace with appropriate value. */
const unsigned char iv[16] = ... iv ...;
unsigned char new_iv[16]; /* New IV. */
aes_ctr_xcrypt(&ctx, sizeof outbuf, outbuf, inbuf, iv, new_iv);
For more information, see aes.h.
Initialize AesContext
using aes_init(ctx, key_size, key)
where
ctx
is pointer toAesContext
key_size
= 128, 192, 256 for AES-128, AES-192 & AES-256 respectivelykey
is pointer to AES key
- For encrypting data using ECB mode, use
aes_ecb_encrypt
. - For decrypting data using ECB mode, use
aes_ecb_decrypt
.
- For encrypting data using CBC mode, use
aes_cbc_encrypt
. - For decrypting data using CBC mode, use
aes_cbc_decrypt
.
For encrypting or decrypting data using CTR mode, use aes_ctr_xcrypt
.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, shall be licensed as below, without any additional terms or conditions.
© 2021 arnavyc <[email protected]>
Licensed under the BSD Zero Clause License. See LICENSE file in the project root, or https://opensource.org/licenses/0BSD for full license information.
The SPDX license identifier for this project is 0BSD
.