diff options
author | Brian Warner <warner@lothar.com> | 2018-10-15 17:13:55 -0700 |
---|---|---|
committer | Brian Warner <warner@lothar.com> | 2018-10-15 17:19:56 -0700 |
commit | a23222c9c1cb604b62ccf133ff3f9ce0ca95bddf (patch) | |
tree | 2f0c6dc83ad2a53c684ad60dec69984ecff9ff5c /spake2/src/lib.rs | |
parent | 1afa40d15b0c2cecc989bdfc67a5251aa5cd5954 (diff) | |
parent | f6e9d07dffa9a9b39f203c23043f93337ebe1ab6 (diff) | |
download | PAKEs-a23222c9c1cb604b62ccf133ff3f9ce0ca95bddf.tar.xz |
Add 'spake2/' from commit 'f6e9d07dffa9a9b39f203c23043f93337ebe1ab6'
git-subtree-dir: spake2
git-subtree-mainline: 1afa40d15b0c2cecc989bdfc67a5251aa5cd5954
git-subtree-split: f6e9d07dffa9a9b39f203c23043f93337ebe1ab6
This moves https://github.com/warner/spake2.rs into the "spake2/"
subdirectory of https://github.com/RustCrypto/PAKEs .
I'll move the release tags over next, then update the travis config and
READMEs.
Diffstat (limited to 'spake2/src/lib.rs')
-rw-r--r-- | spake2/src/lib.rs | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/spake2/src/lib.rs b/spake2/src/lib.rs new file mode 100644 index 0000000..c2858ba --- /dev/null +++ b/spake2/src/lib.rs @@ -0,0 +1,109 @@ +#![forbid(unsafe_code)] +#![cfg_attr(test, deny(warnings))] + +extern crate curve25519_dalek; +extern crate hex; +extern crate hkdf; +extern crate num_bigint; +extern crate rand; +extern crate sha2; + +mod spake2; +pub use spake2::*; + +#[cfg(test)] +mod tests { + use spake2::{Ed25519Group, ErrorType, Identity, Password, SPAKE2, SPAKEErr}; + + #[test] + fn test_basic() { + let (s1, msg1) = SPAKE2::<Ed25519Group>::start_a( + &Password::new(b"password"), + &Identity::new(b"idA"), + &Identity::new(b"idB"), + ); + let (s2, msg2) = SPAKE2::<Ed25519Group>::start_b( + &Password::new(b"password"), + &Identity::new(b"idA"), + &Identity::new(b"idB"), + ); + let key1 = s1.finish(msg2.as_slice()).unwrap(); + let key2 = s2.finish(msg1.as_slice()).unwrap(); + assert_eq!(key1, key2); + } + + #[test] + fn test_mismatch() { + let (s1, msg1) = SPAKE2::<Ed25519Group>::start_a( + &Password::new(b"password"), + &Identity::new(b"idA"), + &Identity::new(b"idB"), + ); + let (s2, msg2) = SPAKE2::<Ed25519Group>::start_b( + &Password::new(b"password2"), + &Identity::new(b"idA"), + &Identity::new(b"idB"), + ); + let key1 = s1.finish(msg2.as_slice()).unwrap(); + let key2 = s2.finish(msg1.as_slice()).unwrap(); + assert_ne!(key1, key2); + } + + #[test] + fn test_reflected_message() { + let (s1, msg1) = SPAKE2::<Ed25519Group>::start_a( + &Password::new(b"password"), + &Identity::new(b"idA"), + &Identity::new(b"idB"), + ); + let r = s1.finish(msg1.as_slice()); + assert_eq!( + r.unwrap_err(), + SPAKEErr { + kind: ErrorType::BadSide, + } + ); + } + + #[test] + fn test_bad_length() { + let (s1, msg1) = SPAKE2::<Ed25519Group>::start_a( + &Password::new(b"password"), + &Identity::new(b"idA"), + &Identity::new(b"idB"), + ); + let mut msg2 = Vec::<u8>::with_capacity(msg1.len() + 1); + msg2.resize(msg1.len() + 1, 0u8); + let r = s1.finish(&msg2); + assert_eq!( + r.unwrap_err(), + SPAKEErr { + kind: ErrorType::WrongLength, + } + ); + } + + #[test] + fn test_basic_symmetric() { + let (s1, msg1) = SPAKE2::<Ed25519Group>::start_symmetric( + &Password::new(b"password"), + &Identity::new(b"idS"), + ); + let (s2, msg2) = SPAKE2::<Ed25519Group>::start_symmetric( + &Password::new(b"password"), + &Identity::new(b"idS"), + ); + let key1 = s1.finish(msg2.as_slice()).unwrap(); + let key2 = s2.finish(msg1.as_slice()).unwrap(); + assert_eq!(key1, key2); + } + + #[test] + fn it_works() {} + + #[test] + #[should_panic(expected = "nope")] + fn it_panics() { + assert!(false, "nope"); + } +} |