From 24e9ae4df3f9fe9277283b5e41c0ad9606cd2b07 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Mon, 27 Nov 2023 16:45:49 +0100 Subject: add tests for maximum length ID handling --- src/hibe/bbg.rs | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) (limited to 'src/hibe/bbg.rs') diff --git a/src/hibe/bbg.rs b/src/hibe/bbg.rs index dc2a129..06dbb51 100644 --- a/src/hibe/bbg.rs +++ b/src/hibe/bbg.rs @@ -237,6 +237,29 @@ mod test { assert_eq!(message, decryption); } + #[test] + fn encrypt_decrypt_max_length_identity() { + let mut rng = rand::thread_rng(); + let bbg = BonehBoyenGoh::new(5); + let (public_key, master_key) = bbg.setup(&mut rng).unwrap(); + let identity = &[ + Scalar::from(1u32), + Scalar::from(2u32), + Scalar::from(3u32), + Scalar::from(4u32), + Scalar::from(5u32), + ]; + let secret_key = bbg + .generate_key(&mut rng, &public_key, &master_key, identity.as_slice()) + .unwrap(); + let message = Gt::generator() * Scalar::from(4u32); + let ciphertext = bbg + .encrypt(&mut rng, &public_key, identity.as_slice(), &message) + .unwrap(); + let decryption = bbg.decrypt(&public_key, &secret_key, &ciphertext).unwrap(); + assert_eq!(message, decryption); + } + #[test] fn encrypt_decrypt_derived() { let mut rng = rand::thread_rng(); @@ -300,6 +323,70 @@ mod test { assert_ne!(message, decryption); } + #[test] + fn derive_max_length() { + let mut rng = rand::thread_rng(); + let bbg = BonehBoyenGoh::new(5); + let (public_key, master_key) = bbg.setup(&mut rng).unwrap(); + let identity = &[Scalar::from(1u32), Scalar::from(2u32), Scalar::from(3u32), Scalar::from(4u32), Scalar::from(5u32)]; + let secret_key_0 = bbg + .generate_key(&mut rng, &public_key, &master_key, &[]) + .unwrap(); + let secret_key_1 = bbg + .derive_key( + &mut rng, + &public_key, + &secret_key_0, + &identity[..0], + &identity[0], + ) + .unwrap(); + let secret_key_2 = bbg + .derive_key( + &mut rng, + &public_key, + &secret_key_1, + &identity[..1], + &identity[1], + ) + .unwrap(); + let secret_key_3 = bbg + .derive_key( + &mut rng, + &public_key, + &secret_key_2, + &identity[..2], + &identity[2], + ) + .unwrap(); + let secret_key_4 = bbg + .derive_key( + &mut rng, + &public_key, + &secret_key_3, + &identity[..3], + &identity[3], + ) + .unwrap(); + let secret_key_5 = bbg + .derive_key( + &mut rng, + &public_key, + &secret_key_4, + &identity[..4], + &identity[4], + ) + .unwrap(); + let message = Gt::generator() * Scalar::from(4u32); + let ciphertext = bbg + .encrypt(&mut rng, &public_key, identity.as_slice(), &message) + .unwrap(); + let decryption = bbg + .decrypt(&public_key, &secret_key_5, &ciphertext) + .unwrap(); + assert_eq!(message, decryption); + } + #[test] fn encapsulate_decapsulate_keygen() { let mut rng = rand::thread_rng(); -- cgit v1.2.3