Add a simple test that makes sure both implementations match.

This commit is contained in:
2019-07-08 16:15:32 -05:00
parent e84f6a865e
commit 5b122b8c0c
3 changed files with 37 additions and 9 deletions

View File

@@ -1,4 +1,32 @@
#[cfg(all(any(target_arch="x86", target_arch="x86_64"),
target_feature = "aes"))]
pub mod aesni;
pub mod portable;
pub mod portable;
#[cfg(all(any(target_arch="x86", target_arch="x86_64"),
target_feature = "aes",
test))]
mod flexible {
use super::aesni;
use super::portable;
use super::portable::aes256::{RandomBlock,RandomKey};
quickcheck! {
fn aes128_implementations_match(key: RandomBlock, block: RandomBlock) -> bool {
let aesni_key = aesni::AES128::new(&key.block);
let portable_key = portable::AES128::new(&key.block);
let aesni_cipher = aesni_key.encrypt(&block.block);
let portable_cipher = portable_key.encrypt(&block.block);
aesni_cipher == portable_cipher
}
fn aes256_implementations_match(key: RandomKey, block: RandomBlock) -> bool {
let aesni_key = aesni::AES256::new(&key.key);
let portable_key = portable::AES256::new(&key.key);
let aesni_cipher = aesni_key.encrypt(&block.block);
let portable_cipher = portable_key.encrypt(&block.block);
aesni_cipher == portable_cipher
}
}
}