| Crates.io | aes-wasm |
| lib.rs | aes-wasm |
| version | 0.1.17 |
| created_at | 2023-05-23 19:38:39.463566+00 |
| updated_at | 2025-04-27 22:21:27.197889+00 |
| description | AES-GCM, AES-OCB, AEGIS, AES-CTR, CMAC-AES for WebAssembly |
| homepage | |
| repository | https://github.com/jedisct1/rust-aes-wasm |
| max_upload_size | |
| id | 872273 |
| size | 496,223 |
Fast, dependency-free AES and AEGIS ciphers for Rust and WASI (WebAssembly System Interface)
aes-wasm provides high-performance AEAD, stream cipher, and MAC primitives for use in WebAssembly/WASI environments. It is designed for speed, simplicity, and zero dependencies, making it ideal for cryptographic operations in WASI-based runtimes and server-side WASM applications.
Note: This crate is intended specifically for WASI (not web browsers or native environments).
Add to your Cargo.toml:
[dependencies]
aes-wasm = "*"
Note: Make sure your target is set to a WASI platform, such as
wasm32-wasi.
use aes_wasm::aes128gcm::{encrypt, decrypt, Key, Nonce};
let key = Key::default();
let nonce = Nonce::default();
let msg = b"hello world";
let ad = b"extra data";
let ciphertext = encrypt(msg, ad, &key, nonce);
let plaintext = decrypt(ciphertext, ad, &key, nonce).unwrap();
assert_eq!(plaintext, msg);
use aes_wasm::aes128ctr::{encrypt, decrypt, Key, IV};
let key = Key::default();
let iv = IV::default();
let msg = b"streaming!";
let ciphertext = encrypt(msg, &key, iv);
let plaintext = decrypt(ciphertext, &key, iv);
assert_eq!(plaintext, msg);
use aes_wasm::cmac_aes128::{mac, Key};
let key = Key::default();
let msg = b"authenticate me";
let tag = mac(msg, &key);
Benchmarks can be run with:
cargo wasix bench
| algorithm | crate | throughput |
|---|---|---|
| aes256-gcm | (aes crate) |
49.63 M/s |
| aes256-gcm | this crate | 98.86 M/s |
| aes128-gcm | (aes crate) |
59.87 M/s |
| aes128-gcm | this crate | 115.47 M/s |
| aes256-ocb | this crate | 168.43 M/s |
| aes128-ocb | this crate | 215.23 M/s |
| aes-128-cbc | (cbc crate) |
48.48 M/s |
| aes-128-cbc | this crate | 225.63 M/s |
| aes-256-cbc | (cbc crate) |
35.49 M/s |
| aes-256-cbc | this crate | 171.89 M/s |
| aegis-256 | this crate | 478.57 M/s |
| aegis-128l | (aegis crate) |
533.85 M/s |
| aegis-128l | this crate | 695.85 M/s |
| aes128-ctr | (ctr crate) |
104.63 M/s |
| aes128-ctr | this crate | 217.10 M/s |
| cmac-aes128 | (cmac crate) |
53.99 M/s |
| cmac-aes128 | this crate | 233.34 M/s |
| algorithm | crate | throughput |
|---|---|---|
| aes256-gcm | (aes crate) |
63.79 M/s |
| aes256-gcm | this crate | 129.44 M/s |
| aes128-gcm | (aes crate) |
75.09 M/s |
| aes128-gcm | this crate | 149.31 M/s |
| aes256-ocb | this crate | 205.39 M/s |
| aes128-ocb | this crate | 260.56 M/s |
| aegis-256 | this crate | 497.97 M/s |
| aegis-128l | (aegis crate) |
537.49 M/s |
| aegis-128l | this crate | 696.61 M/s |
| aes128-ctr | (ctr crate) |
151.26 M/s |
| aes128-ctr | this crate | 275.51 M/s |
| cmac-aes128 | (cmac crate) |
78.63 M/s |
| cmac-aes128 | this crate | 260.23 M/s |
This project is licensed under the MIT License. See LICENSE for details.