From a2670eac7db1670cd29885b56212bd0c9a596c83 Mon Sep 17 00:00:00 2001 From: supinie <86788874+supinie@users.noreply.github.com> Date: Thu, 23 May 2024 17:33:41 +0100 Subject: [PATCH] adds encap decap test --- src/tests/kem.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/tests/kem.rs diff --git a/src/tests/kem.rs b/src/tests/kem.rs new file mode 100644 index 0000000..7ea4c1e --- /dev/null +++ b/src/tests/kem.rs @@ -0,0 +1,25 @@ +#![allow(warnings)] +#[cfg(test)] +mod kem_tests { + use crate::kem::*; + use proptest::prelude::*; + + prop_compse! { + fn new_keypair() + (k in 2..=4) + -> (PublicKey, PrivateKey) { + generate_key_pair(None, k).unwrap() + } + } + + proptest! { + #[test] + fn encapsulate_decapsulate((pk, sk) in new_keypair()) { + let (ciphertext, shared_secret) = pk.encapsulate().unwrap(); + + let decap_secret = sk.decapsulate(ciphertext).unwrap(); + + assert_eq!(shared_secret, decap_secret); + } + } +}