Integrate tiny-aes-c into C and C++ projects
masterDepending on your language, include the appropriate header file:
- For C projects:
#include "aes.h" - For C++ projects:
#include "aes.hpp"
repository·master·Indexed 26 days ago
https://github.com/kokke/tiny-aes-cA small, portable, and lightweight C implementation of AES supporting ECB, CTR, and CBC modes. Designed for embedded systems prioritizing small binary size and low memory footprint over high performance. Supports 128-bit, 192-bit, and 256-bit key sizes via configuration symbols.
Depending on your language, include the appropriate header file:
#include "aes.h"#include "aes.hpp"You can customize the AES implementation by defining specific symbols in aes.h before compilation:
The default key size is 128-bit. To use other sizes, define:
AES192 for 192-bitAES256 for 256-bitTo enable specific modes, define the corresponding symbols:
CBCCTRECBUse the following functions to set up the AES_ctx structure. The library uses C99 <stdint.h> annotated types.
AES_init_ctx(struct AES_ctx* ctx, const uint8_t* key): Initializes the context with a provided key.AES_init_ctx_iv(struct AES_ctx* ctx, const uint8_t* key, const uint8_t* iv): Initializes the context with a key and an Initialization Vector (IV).AES_ctx_set_iv(struct AES_ctx* ctx, const uint8_t* iv): Resets the IV at a random point during operation./* Initialize context calling one of: */
void AES_init_ctx(struct AES_ctx* ctx, const uint8_t* key);
void AES_init_ctx_iv(struct AES_ctx* ctx, const uint8_t* key, const uint8_t* iv);
/* ... or reset IV at random point: */
void AES_ctx_set_iv(struct AES_ctx* ctx, const uint8_t* iv);Once the context is initialized, use the mode-specific functions to process data.
Important Requirements:
/* Then start encrypting and decrypting with the functions below: */
void AES_ECB_encrypt(const struct AES_ctx* ctx, uint8_t* buf);
void AES_ECB_decrypt(const struct AES_ctx* ctx, uint8_t* buf);
void AES_CBC_encrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length);
void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length);
/* Same function for encrypting as for decrypting in CTR mode */
void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length);