diff options
author | Daniel Schadt <kingdread@gmx.de> | 2023-11-27 16:45:49 +0100 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2023-11-27 16:45:49 +0100 |
commit | 24e9ae4df3f9fe9277283b5e41c0ad9606cd2b07 (patch) | |
tree | 4148334c43d1f0126425764ac0ff85115bac3ad7 /src/hibe | |
parent | 865127129a1e913866390ac8193ec89acec3756a (diff) | |
download | hohibe-24e9ae4df3f9fe9277283b5e41c0ad9606cd2b07.tar.gz hohibe-24e9ae4df3f9fe9277283b5e41c0ad9606cd2b07.tar.bz2 hohibe-24e9ae4df3f9fe9277283b5e41c0ad9606cd2b07.zip |
add tests for maximum length ID handling
Diffstat (limited to 'src/hibe')
-rw-r--r-- | src/hibe/bbg.rs | 87 |
1 files changed, 87 insertions, 0 deletions
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 @@ -238,6 +238,29 @@ mod test { } #[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(); let bbg = BonehBoyenGoh::new(5); @@ -301,6 +324,70 @@ mod test { } #[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(); let bbg = BonehBoyenGoh::new(5); |