Crate aesni [] [src]

AES block cipher implementation using AES-NI instruction set.

This crate does not implement any software fallback and does not automatically check CPUID, so if you are using this crate make sure to run software on appropriate hardware or to check AES-NI availability using check_aesni() function with an appropriate software fallback in case of its unavailability.

Additionally this crate currently requires nigthly Rust compiler due to the usage of unstable asm and simd features.

Ciphers functionality is accessed using BlockCipher trait from block-cipher-trait crate.

Usage example

use aesni::{Aes128, BlockCipher};
 
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 = aesni::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_blocks(&mut block8);
cipher.decrypt_blocks(&mut block8);
assert_eq!(block8, block8_copy);

Related documents

Re-exports

pub extern crate block_cipher_trait;

Structs

Aes128

AES-128 block cipher

Aes192

AES-192 block cipher

Aes256

AES-256 block cipher

CtrAes128

AES128 in CTR mode

CtrAes192

AES192 in CTR mode

CtrAes256

AES256 in CTR mode

Traits

BlockCipher

The trait which defines in-place encryption and decryption over single block or several blocks in parallel.

Functions

check_aesni

Check if CPU has AES-NI using CPUID instruction.