Add Blowfish tests
This commit is contained in:
parent
0850f605b1
commit
5340895249
|
|
@ -525,6 +525,35 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn cipher_test_nopad(ciphertype: super::Cipher, pt: &str, ct: &str, key: &str, iv: &str) {
|
||||||
|
let pt = Vec::from_hex(pt).unwrap();
|
||||||
|
let ct = Vec::from_hex(ct).unwrap();
|
||||||
|
let key = Vec::from_hex(key).unwrap();
|
||||||
|
let iv = Vec::from_hex(iv).unwrap();
|
||||||
|
|
||||||
|
let computed = {
|
||||||
|
let mut c = Crypter::new(ciphertype, Mode::Decrypt, &key, Some(&iv)).unwrap();
|
||||||
|
c.pad(false);
|
||||||
|
let mut out = vec![0; ct.len() + ciphertype.block_size()];
|
||||||
|
let count = c.update(&ct, &mut out).unwrap();
|
||||||
|
let rest = c.finalize(&mut out[count..]).unwrap();
|
||||||
|
out.truncate(count + rest);
|
||||||
|
out
|
||||||
|
};
|
||||||
|
let expected = pt;
|
||||||
|
|
||||||
|
if computed != expected {
|
||||||
|
println!("Computed: {}", computed.to_hex());
|
||||||
|
println!("Expected: {}", expected.to_hex());
|
||||||
|
if computed.len() != expected.len() {
|
||||||
|
println!("Lengths differ: {} in computed vs {} expected",
|
||||||
|
computed.len(),
|
||||||
|
expected.len());
|
||||||
|
}
|
||||||
|
panic!("test failure");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rc4() {
|
fn test_rc4() {
|
||||||
|
|
||||||
|
|
@ -631,6 +660,51 @@ mod tests {
|
||||||
cipher_test(super::Cipher::aes_256_cfb8(), pt, ct, key, iv);
|
cipher_test(super::Cipher::aes_256_cfb8(), pt, ct, key, iv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_bf_cbc() {
|
||||||
|
// https://www.schneier.com/code/vectors.txt
|
||||||
|
|
||||||
|
let pt = "37363534333231204E6F77206973207468652074696D6520666F722000000000";
|
||||||
|
let ct = "6B77B4D63006DEE605B156E27403979358DEB9E7154616D959F1652BD5FF92CC";
|
||||||
|
let key = "0123456789ABCDEFF0E1D2C3B4A59687";
|
||||||
|
let iv = "FEDCBA9876543210";
|
||||||
|
|
||||||
|
cipher_test_nopad(super::Cipher::bf_cbc(), pt, ct, key, iv);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_bf_ecb() {
|
||||||
|
|
||||||
|
let pt = "5CD54CA83DEF57DA";
|
||||||
|
let ct = "B1B8CC0B250F09A0";
|
||||||
|
let key = "0131D9619DC1376E";
|
||||||
|
let iv = "0000000000000000";
|
||||||
|
|
||||||
|
cipher_test_nopad(super::Cipher::bf_ecb(), pt, ct, key, iv);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_bf_cfb64() {
|
||||||
|
|
||||||
|
let pt = "37363534333231204E6F77206973207468652074696D6520666F722000";
|
||||||
|
let ct = "E73214A2822139CAF26ECF6D2EB9E76E3DA3DE04D1517200519D57A6C3";
|
||||||
|
let key = "0123456789ABCDEFF0E1D2C3B4A59687";
|
||||||
|
let iv = "FEDCBA9876543210";
|
||||||
|
|
||||||
|
cipher_test_nopad(super::Cipher::bf_cfb64(), pt, ct, key, iv);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_bf_ofb() {
|
||||||
|
|
||||||
|
let pt = "37363534333231204E6F77206973207468652074696D6520666F722000";
|
||||||
|
let ct = "E73214A2822139CA62B343CC5B65587310DD908D0C241B2263C2CF80DA";
|
||||||
|
let key = "0123456789ABCDEFF0E1D2C3B4A59687";
|
||||||
|
let iv = "FEDCBA9876543210";
|
||||||
|
|
||||||
|
cipher_test_nopad(super::Cipher::bf_ofb(), pt, ct, key, iv);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_des_cbc() {
|
fn test_des_cbc() {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue