Skip to content

Commit

Permalink
Add test on X225519KeyPair
Browse files Browse the repository at this point in the history
  • Loading branch information
tbrezot committed Sep 21, 2022
1 parent b82ca5c commit fe1a25e
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/asymmetric_crypto/curve25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,7 @@ impl ZeroizeOnDrop for X25519KeyPair {}

#[cfg(test)]
mod test {
use crate::{
asymmetric_crypto::curve25519::{
X25519PrivateKey, X25519PublicKey, X25519_PK_LENGTH, X25519_SK_LENGTH,
},
entropy::CsRng,
KeyTrait,
};
use crate::{asymmetric_crypto::curve25519::*, entropy::CsRng, KeyTrait};

#[test]
fn test_private_key_serialization() {
Expand All @@ -372,4 +366,18 @@ mod test {
let recovered = super::X25519PublicKey::try_from(bytes).unwrap();
assert_eq!(pk, recovered);
}

#[test]
fn test_dh_key_pair() {
let mut rng = CsRng::new();
let kp1 = X25519KeyPair::new(&mut rng);
let kp2 = X25519KeyPair::new(&mut rng);
// check the keys are randomly generated
assert_ne!(kp1, kp2);
// check DH Key exchange is possible
assert_eq!(
kp1.public_key() * kp2.private_key(),
kp2.public_key() * kp1.private_key()
);
}
}

0 comments on commit fe1a25e

Please sign in to comment.