kokke/tiny-AES-c logo

kokke/tiny-AES-c

Free

Small portable AES128/192/256 in C

FreeFree tier
Type
Open Source

About kokke/tiny-AES-c

A small and portable implementation of the AES encryption algorithms (ECB, CTR, and CBC modes) in C. Supports key sizes of 128, 192, and 256 bits via compile-time defines (AES192, AES256). Designed for minimal code size and memory footprint — uses less than 200 bytes of RAM and 1–2 KB of ROM when compiled for ARM targets. The library provides a simple API for initialization, encryption, and decryption, and allows selective compilation of modes (CBC, CTR, ECB). No padding is included; users must ensure buffer lengths are multiples of 16 bytes for CBC/ECB. The code has been tested on 64-bit x86, 32-bit ARM, and 8-bit AVR platforms. Released under the Unlicense (public domain). Ideal for embedded systems, IoT devices, and other resource-constrained environments where a lightweight AES implementation is needed.

Key Features

Supports AES key sizes 128, 192, and 256 bits
Implements ECB, CTR, and CBC encryption modes
Minimal code size and RAM/ROM footprint (<200 bytes RAM, <2KB ROM on ARM)
Portable across 64-bit x86, 32-bit ARM, and 8-bit AVR platforms
Simple C API with initialization, IV setting, and encrypt/decrypt functions
Selectable modes via compile-time defines (CBC, CTR, ECB)
Includes C++ header (aes.hpp) for C++ projects
Public domain (Unlicense) licensing

Pros & Cons

Pros
  • Extremely small code size compared to other AES libraries
  • Simple API and easy integration
  • Supports multiple key sizes and encryption modes
  • Portable across multiple architectures (x86, ARM, AVR)
  • Public domain license allows unrestricted use
  • Low memory footprint suitable for constrained hardware
Cons
  • No built-in padding (user must ensure block-aligned buffers for ECB/CBC)
  • ECB mode considered insecure for most applications and not implemented in streaming
  • No error checking or protection against out-of-bounds memory access from malicious input
  • Not optimized for high performance; designed for size over speed

Best For

Embedded systems and IoT devices with limited memoryLightweight encryption in resource-constrained environmentsEducational projects learning AES implementationProjects requiring a small, portable AES libraryFirmware and microcontroller applications

FAQ

What AES key sizes does tiny-AES-c support?
The default key size is 128 bits. You can switch to 192 or 256 bits by defining the symbols AES192 or AES256 in aes.h.
What encryption modes are available?
ECB, CTR, and CBC modes are implemented. Modes can be selectively included by defining the symbols CBC, CTR, or ECB in aes.h.
Does the library provide padding?
No padding is included. For CBC and ECB modes, all buffers must be multiples of 16 bytes. PKCS7 padding is recommended if padding is needed.
How small is the code?
When compiled for ARM with only CTR mode, the code size is about 903 bytes (THUMB) or 1171 bytes (ARM). RAM usage is under 200 bytes.
Is the library suitable for high-performance applications?
No. This library is designed for small code size and simplicity, not speed. For higher performance, consider Mbed TLS or OpenSSL.