# AEGIS for Rust
This is a Rust implementation of the
[AEGIS](https://datatracker.ietf.org/doc/draft-irtf-cfrg-aegis-aead/)
authenticated cipher, ported from the Zig standard library.
AEGIS is extremely fast on CPUs with AES acceleration, has a large nonce size,
and is key committing.
# [API documentation](https://docs.rs/aegis)
# Cargo flags
- `std`: allow dynamic allocations
`std` is the default.
- `pure-rust`: don't use the `cc` crate to take advantage of the implementations from [`libaegis`](https://github.com/jedisct1/libaegis). Setting this flag will substantially degrade performance.
A benchmark can be run that way:
```sh
export RUSTFLAGS="-C target-cpu=native"
cargo bench
```
For benchmarking, `RUSTFLAGS` is set so that the AES-GCM implementations can take advantage of hardware acceleration.
# Benchmarks
Benchmarks take a 16384 bytes input block. Results are in bytes per second.
## Rust implementations
Crates:
- `aes-gcm`
- `boring`
- `chacha20poly1305`
- `aegis128l`
## AMD Zen4
| aes128-gcm (`aes-gcm` crate) | 1.73 G/s |
| aes256-gcm (`aes-gcm` crate) | 1.86 G/s |
| chacha20-poly1305 | 2.47 G/s |
| aes256-gcm (`boring` crate) | 5.14 G/s |
| aes128-gcm (`boring` crate) | 5.92 G/s |
| aegis256 | 14.36 G/s |
| aegis256x2 | 26.92 G/s |
| aegis256x4 | 42.82 G/s |
| aegis128l | 23.35 G/s |
| aegis128x2 | 42.68 G/s |
| aegis128x4 | 55.28 G/s |
## AMD Zen2
| aes256-gcm (`aes-gcm` crate) | 934.41 M/s |
| aes128-gcm (`aes-gcm` crate) | 973.18 M/s |
| chacha20-poly1305 | 1.35 G/s |
| aes256-gcm (`boring` crate) | 3.31 G/s |
| aes128-gcm (`boring` crate) | 3.61 G/s |
| aegis128l | 13.70 G/s |
## Macbook Pro - Apple M1
| aes256-gcm (`aes-gcm` crate) | 139.66 M/s |
| aes128-gcm (`aes-gcm` crate) | 173.09 M/s |
| chacha20-poly1305 | 265.48 M/s |
| aes256-gcm (`boring` crate) | 5.14 G/s |
| aes128-gcm (`boring` crate) | 6.08 G/s |
| aegis256 | 7.94 G/s |
| aegis256x2 | 10.56 G/s |
| aegis256x4 | 11.20 G/s |
| aegis128l | 14.27 G/s |
| aegis128x2 | 15.98 G/s |
| aegis128x4 | 12.01 G/s |
## WebAssembly (Wasmtime, Zen4)
| aes256-gcm | 62.97 M/s |
| aes128-gcm | 73.83 M/s |
| chacha20-poly1305 | 88.92 M/s |
| aegis128l | 537.49 M/s |
## WebAssembly (Wasmtime, Apple M1)
| aes256-gcm | 49.43 M/s |
| aes128-gcm | 59.37 M/s |
| chacha20-poly1305 | 177.85 M/s |
| aegis128l | 533.85 M/s |
## Other implementations, AMD Zen2
| chacha20-poly1305 (OpenSSL) | 2.67 G/s |
| aes256-gcm (OpenSSL) | 4.97 G/s |
| aes128-gcm (OpenSSL) | 6.89 G/s |
| aes128-ocb (OpenSSL) | 7.10 G/s |
| aegis128l (Zig) | 14.08 G/s |