#crypto #aes #rijndael #block-cipher

no-std aes-soft

AES (Rijndael) block ciphers bit-sliced implementation

11 unstable releases (5 breaking)

0.6.4 Nov 16, 2020
0.6.2 Oct 28, 2020
0.4.0 Jun 5, 2020
0.3.3 Dec 23, 2018
0.1.0 Mar 4, 2018

#3 in Cryptography

Download history 52181/week @ 2020-11-07 56110/week @ 2020-11-14 53926/week @ 2020-11-21 55154/week @ 2020-11-28 57029/week @ 2020-12-05 54756/week @ 2020-12-12 49317/week @ 2020-12-19 36108/week @ 2020-12-26 54109/week @ 2021-01-02 65760/week @ 2021-01-09 66306/week @ 2021-01-16 71407/week @ 2021-01-23 75926/week @ 2021-01-30 72945/week @ 2021-02-06 76450/week @ 2021-02-13 71470/week @ 2021-02-20

195,226 downloads per month
Used in 373 crates (23 directly)



RustCrypto: block ciphers Project Chat dependency status

Collection of block ciphers and block modes written in pure Rust.


Currently only the aes crate provides constant-time implementation. If you do not really know what you are doing, it's generally recommended not to use other cipher implementations in this repository.

Additionally, crates in this repository have not yet received any formal cryptographic and security reviews.


Supported algorithms

Name Crate name crates.io Docs Build Status
AES (Rijndael) aes crates.io Documentation aes build
Blowfish blowfish crates.io Documentation build
CAST5 (CAST-128) cast5 crates.io Documentation build
DES + 3DES (DEA, 3DEA) des crates.io Documentation build
IDEA idea crates.io Documentation build
Kuznyechik (GOST R 34.12-2015) kuznyechik crates.io Documentation build
Magma (GOST 28147-89 and GOST R 34.12-2015) magma crates.io Documentation build
RC2 (ARC2) rc2 crates.io Documentation build
Serpent serpent crates.io Documentation build
SM4 sm4 crates.io Documentation build
Twofish twofish crates.io Documentation build
Threefish threefish crates.io Documentation build

Additional crates

Crate name crates.io Docs Build Status
block-modes crates.io Documentation build
gost-modes crates.io Documentation build

Minimum Supported Rust Version

All crates in this repository support Rust 1.22 or higher. (except aesni and aes crates, which require Rust 1.27) In future minimum supported Rust version can be changed, but it will be done with the minor version bump.


Block cipher crates provide only bare block cipher implementations. For most applications you will need to use some block cipher mode of operation which are generically implemented in the block-modes crate.

Some block modes (CTR, CFB, OFV) transform block ciphers into stream ciphers.Such modes are published under separate crates in the RustCrypto/stream-ciphers repository.

Lets use AES128-CBC with PKCS7 padding to show an example:

use aes::Aes128;
use block_modes::{BlockMode, Cbc};
use block_modes::block_padding::Pkcs7;
use hex_literal::hex;

// create an alias for convenience
type Aes128Cbc = Cbc<Aes128, Pkcs7>;

let key = hex!("000102030405060708090a0b0c0d0e0f");
let iv = hex!("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff");
let plaintext = b"Hello world!";
let cipher = Aes128Cbc::new_var(&key, &iv).unwrap();

// buffer must have enough space for message+padding
let mut buffer = [0u8; 32];
// copy message to the buffer
let pos = plaintext.len();
let ciphertext = cipher.encrypt(&mut buffer, pos).unwrap();

assert_eq!(ciphertext, hex!("1b7a4c403124ae2fb52bedc534d82fa8"));

// re-create cipher mode instance and decrypt the message
let cipher = Aes128Cbc::new_var(&key, &iv).unwrap();
let mut buf = ciphertext.to_vec();
let decrypted_ciphertext = cipher.decrypt(&mut buf).unwrap();

assert_eq!(decrypted_ciphertext, plaintext);

With an enabled std feature (which is enabled by default) you can use encrypt_vec and decrypt_vec methods:

let cipher = Aes128Cbc::new_var(&key, &iv).unwrap();
let ciphertext = cipher.encrypt_vec(plaintext);

assert_eq!(ciphertext, hex!("1b7a4c403124ae2fb52bedc534d82fa8"));

let cipher = Aes128Cbc::new_var(&key, &iv).unwrap();
let decrypted_ciphertext = cipher.decrypt_vec(&ciphertext).unwrap();

assert_eq!(decrypted_ciphertext, plaintext);

Note that this example does not use any authentification which can lead to serious vulnarabilities! For Message Authentication Code implementations take a look at RustCrypto/MACs repository.


All crates licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.