Crate aes[−][src]
Pure Rust implementation of the Advanced Encryption Standard (a.k.a. Rijndael)
It provides two different backends based on what target features are specified:
- “soft” portable constant-time implementation based on fixslicing.
Enabling the
compact
Cargo feature will reduce the code size of this backend at the cost of decreased performance (using a modified form of the fixslicing technique called “semi-fixslicing”). - AES-NI accelerated implementation for
i686
/x86_64
target architectures withtarget-feature=+aes
, as well as an accelerated AES-CTR implementation withtarget-feature=+aes,+ssse3
Crate switches between implementations automatically at compile time. (i.e. it does not use run-time feature detection)
Usage example
use aes::Aes128; use aes::cipher::{ BlockCipher, BlockEncrypt, BlockDecrypt, NewBlockCipher, generic_array::GenericArray, }; let key = GenericArray::from_slice(&[0u8; 16]); let mut block = GenericArray::clone_from_slice(&[0u8; 16]); let mut block8 = GenericArray::clone_from_slice(&[block; 8]); // Initialize cipher let cipher = Aes128::new(&key); let block_copy = block.clone(); // Encrypt block in-place cipher.encrypt_block(&mut block); // And decrypt it back cipher.decrypt_block(&mut block); assert_eq!(block, block_copy); // We can encrypt 8 blocks simultaneously using // instruction-level parallelism let block8_copy = block8.clone(); cipher.encrypt_par_blocks(&mut block8); cipher.decrypt_par_blocks(&mut block8); assert_eq!(block8, block8_copy);
For implementations of block cipher modes of operation see
block-modes
crate.
Re-exports
pub use cipher; |
Structs
Aes128 | AES-128 block cipher instance |
Aes128Ctr | ctr AES-128 in CTR mode |
Aes192 | AES-192 block cipher instance |
Aes192Ctr | ctr AES-192 in CTR mode |
Aes256 | AES-256 block cipher instance |
Aes256Ctr | ctr AES-256 in CTR mode |
Traits
BlockCipher | Trait which marks a type as being a block cipher. |
BlockDecrypt | Decrypt-only functionality for block ciphers. |
BlockEncrypt | Encrypt-only functionality for block ciphers. |
NewBlockCipher | Instantiate a |
Type Definitions
Block | 128-bit AES block |
ParBlocks | 8 x 128-bit AES blocks to be processed in parallel |