https://github.com/konimarti/aes.c3l
AES128/192/256 in pure C3
https://github.com/konimarti/aes.c3l
aes aes-encryption aes-encryption-decryption c3 c3lang
Last synced: 5 months ago
JSON representation
AES128/192/256 in pure C3
- Host: GitHub
- URL: https://github.com/konimarti/aes.c3l
- Owner: konimarti
- License: mit
- Created: 2024-11-19T15:51:08.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-09-24T15:13:12.000Z (9 months ago)
- Last Synced: 2025-10-07T10:01:11.887Z (8 months ago)
- Topics: aes, aes-encryption, aes-encryption-decryption, c3, c3lang
- Language: C3
- Homepage:
- Size: 37.1 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## AES implementation for C3
This is an implementation of the AES ECB, CTR and CBC encryption algorithms for
C3 based on the [tiny-AES-c](http://github.com/kokke/tiny-AES-c) project.
It supports 128, 192 and 256 bit key sizes.
API overview:
```cpp
import crypto::aes;
// Initialize the context with one of:
AesCtx *ctx = AesCtx{}.init(aes::AES128, key);
AesCtx *ctx = AesCtx{}.init_with_iv(aes::AES128, key, iv);
// Start encrypting and decrypting with either the ECB, CBC or CTR modes.
// Each mode defines a namespace (`crypto::aes::ecb`, `crypto::aes::cbc`,
// `crypto::aes::ctr`) with the following function signatures:
fn void encrypt_buffer(AesCtx *ctx, char[] text, char[] cipher)
fn void decrypt_buffer(AesCtx *ctx, char[] cipher, char[] text)
fn char[] encrypt(AesCtx *ctx, char[] text, Allocator allocator = mem)
fn char[] decrypt(AesCtx *ctx, char[] cipher, Allocator allocator = mem)
fn char[] tencrypt(AesCtx *ctx, char[] text)
fn char[] tdecrypt(AesCtx *ctx, char[] cipher)
```
### Example: AES128 ECB encryption
```cpp
module app;
import crypto::aes;
import std::io;
fn void main()
{
char[] key = x"2b7e151628aed2a6abf7158809cf4f3c";
char[] text = x"6bc1bee22e409f96e93d7e117393172a";
char[] cipher = ecb::encrypt_new((AesCtx){}.init(aes::AES128, key), text);
defer free(cipher);
assert(cipher == x"3ad77bb40d7a3660a89ecaf32466ef97");
}
```
### Installation
Clone the repository with
```git clone http://github.com/konimarti/aes.c3l```
to the `./lib` folder of your C3 project and add the following to
`project.json`:
```json
{
"dependency-search-paths": [ "lib" ],
"dependencies": [ "aes" ]
}
```
If you didn't clone it into the `lib` folder, adjust your
`dependency-search-paths` accordingly.