A safe and small Rust implementation of AES cipher.
This Rust implementation is ported from the C implementation in OpenSSL 1.1.1 stable with these highlights:
- Safe Rust code only.
- Zero dependencies.
- Fast (thanks to algorithms in OpenSSL 1.1.1, see some benchmark).
Currently, this cipher supports 128-bit, 192-bit and 256-bit keys with the following modes:
- CBC mode: automatic padding is included.
- CFB mode: no padding as it is not needed. Only 128-bit segment size (i.e. CFB128) is supported.
// Example for AES-128 CBC mode use libaes::Cipher; let my_key = b"This is the key!"; // key is 16 bytes, i.e. 128-bit let plaintext = b"A plaintext"; let iv = b"This is 16 bytes"; // Create a new 128-bit cipher let cipher = Cipher::new_128(my_key); // Encryption let encrypted = cipher.cbc_encrypt(iv, plaintext); // Decryption let decrypted = cipher.cbc_decrypt(iv, &encrypted[..]);
AES cipher struct
128-bit are 16 bytes
192-bit are 24 bytes
256-bit are 32 bytes