From fe1a25e7638bbc17b0d6e3fa03e9900fc198be7b Mon Sep 17 00:00:00 2001 From: Theophile BREZOT Date: Wed, 21 Sep 2022 09:17:49 +0200 Subject: [PATCH] Add test on `X225519KeyPair` --- src/asymmetric_crypto/curve25519.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/asymmetric_crypto/curve25519.rs b/src/asymmetric_crypto/curve25519.rs index 49d0d2c..a114279 100644 --- a/src/asymmetric_crypto/curve25519.rs +++ b/src/asymmetric_crypto/curve25519.rs @@ -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() { @@ -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() + ); + } }