mod generic;
pub use self::generic::*;
#[test]
fn test_sm4_setup_cipher() {
let key: [u8; Sm4::KEY_LEN] = [
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
];
let cipher = Sm4::new(&key);
assert_eq!(cipher.rk[0][0], 0xf12186f9);
assert_eq!(cipher.rk[Sm4::NR - 1][3], 0x9124a012);
}
#[test]
fn test_sm4_enc_and_dec() {
let key: [u8; Sm4::KEY_LEN] = [
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
];
let plaintext: [u8; Sm4::BLOCK_LEN] = [
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
];
let cipher = Sm4::new(&key);
let mut ciphertext = plaintext.clone();
cipher.encrypt(&mut ciphertext);
assert_eq!(&ciphertext[..], &[
0x68, 0x1e, 0xdf, 0x34, 0xd2, 0x06, 0x96, 0x5e,
0x86, 0xb3, 0xe9, 0x4f, 0x53, 0x6e, 0x42, 0x46,
]);
cipher.decrypt(&mut ciphertext);
assert_eq!(&ciphertext[..], &plaintext[..]);
}