This is a C language implementation of AES-256 encryption and decryption in CBC mode.
Data must be padded to 16-byte blocks.
Encrypts data using AES-256 in CBC mode.
Returns 1 on success, 0 on error.
int aes_256_cbc_encrypt(
const uint8_t key[32],
const uint8_t iv[16],
const uint8_t *plaintext,
size_t plaintext_len,
uint8_t *ciphertext
);
-
key - 32-byte encryption key
-
iv - 16-byte initialization vector
-
plaintext - input data to encrypt (16-byte padded)
-
plaintext_len - length of plaintext in bytes
-
ciphertext - output buffer for encrypted data
Decrypts data using AES-256 in CBC mode.
Returns 1 on success, 0 on error.
int aes_256_cbc_decrypt(
const uint8_t key[32],
const uint8_t iv[16],
const uint8_t *ciphertext,
size_t ciphertext_len,
uint8_t *plaintext
);
-
key - 32-byte encryption key
-
iv - 16-byte initialization vector
-
ciphertext - encrypted data to decrypt (16-byte blocks)
-
ciphertext_len - length of ciphertext in bytes
-
plaintext - output buffer for decrypted data
© 2025 Nuran Askarov
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.