This Wrapper/Library provides AES-256 encryption and decryption functions using GCM and CTR modes. It leverages OpenSSL for cryptographic operations and is designed to be fast and efficient.
- AES-256-GCM Encryption and Decryption
- AES-256-CTR Encryption and Decryption
- Easy-to-use C API
- Python bindings for testing
- OpenSSL library
- C compiler (e.g., GCC)
- Python 3.x
ctypesmodule in Python
aes256.c: C implementation of AES-256 encryption and decryption functions.aes256.h: Header file for AES-256 functions.Makefile: Makefile for building the shared library.test_aes256.py: Python script for testing the AES-256 functions.
-
Clone the repository:
git clone <repository-url> cd <repository-directory>
-
Build the shared library:
make
This will compile
aes256.cand create thelibaes256.soshared library.
Include the header file and link against the compiled shared library in your C project:
-
Include the header:
#include "aes256.h"
-
Example usage:
AES256_CTX ctx; uint8_t key[AES256_KEY_SIZE] = { ... }; // 32 bytes uint8_t iv[AES256_IV_SIZE] = { ... }; // 12 bytes for GCM uint8_t plaintext[] = "Hello, World!"; uint8_t ciphertext[sizeof(plaintext)]; uint8_t tag[AES256_TAG_SIZE]; // 16 bytes for GCM // Initialize context aes256_init(&ctx, key, iv); // Encrypt aes256_gcm_encrypt(&ctx, plaintext, sizeof(plaintext), NULL, 0, ciphertext, tag); // Decrypt uint8_t decrypted[sizeof(plaintext)]; aes256_gcm_decrypt(&ctx, ciphertext, sizeof(ciphertext), NULL, 0, tag, decrypted);
The test_aes256.py script demonstrates how to use the shared library from Python using the ctypes module.
-
Ensure the shared library is in the same directory as the Python script or in a directory included in your
LD_LIBRARY_PATH. -
Run the Python test script:
python3 test_aes256.py
This script tests both AES-256-GCM and AES-256-CTR encryption and decryption functions and prints the results.
The test_aes256.py script tests the AES-256 encryption and decryption functions.