aboutsummaryrefslogtreecommitdiff
path: root/openssl/src
diff options
context:
space:
mode:
author0xa <[email protected]>2016-12-09 21:26:58 +0000
committer0xa <[email protected]>2016-12-09 21:31:26 +0000
commit5340895249164e0761996b5adbdb4587122880dc (patch)
treea1770e4d35d60e0bf1177333981a8e4905bb8173 /openssl/src
parentUse EVP_bf_cfb64 instead of EVP_bf_cfb (diff)
downloadrust-openssl-5340895249164e0761996b5adbdb4587122880dc.tar.xz
rust-openssl-5340895249164e0761996b5adbdb4587122880dc.zip
Add Blowfish tests
Diffstat (limited to 'openssl/src')
-rw-r--r--openssl/src/symm.rs74
1 files changed, 74 insertions, 0 deletions
diff --git a/openssl/src/symm.rs b/openssl/src/symm.rs
index 1a46411d..d2cb0cc8 100644
--- a/openssl/src/symm.rs
+++ b/openssl/src/symm.rs
@@ -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]
fn test_rc4() {
@@ -632,6 +661,51 @@ mod tests {
}
#[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]
fn test_des_cbc() {
let pt = "54686973206973206120746573742e";