From f2a90a51ce3045e676ba105caf96d5037e03d4b4 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Sun, 26 Nov 2023 18:45:59 +0100 Subject: initial commit --- src/hibe/mod.rs | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/hibe/mod.rs (limited to 'src/hibe/mod.rs') diff --git a/src/hibe/mod.rs b/src/hibe/mod.rs new file mode 100644 index 0000000..20d83a6 --- /dev/null +++ b/src/hibe/mod.rs @@ -0,0 +1,72 @@ +use super::error::Result; + +use rand::Rng; + +mod bbg; +pub use self::bbg::BonehBoyenGoh; + +pub trait Hibe { + type PrivateKey; + type MasterKey; + type PublicKey; + type Identity; + + fn setup(&self, rng: R) -> Result<(Self::PublicKey, Self::MasterKey)>; + + fn generate_key( + &self, + rng: R, + public_key: &Self::PublicKey, + master_key: &Self::MasterKey, + identity: &[Self::Identity], + ) -> Result; + + fn derive_key( + &self, + rng: R, + public_key: &Self::PublicKey, + parent_key: &Self::PrivateKey, + parent_name: &[Self::Identity], + child: &Self::Identity, + ) -> Result; +} + +pub trait HibeCrypt: Hibe { + type Message; + type Ciphertext; + + fn encrypt( + &self, + rng: R, + public_key: &Self::PublicKey, + identity: &[Self::Identity], + message: &Self::Message, + ) -> Result; + + fn decrypt( + &self, + public_key: &Self::PublicKey, + key: &Self::PrivateKey, + ciphertext: &Self::Ciphertext, + ) -> Result; +} + +pub trait HibeKem: Hibe { + type Key; + type EncapsulatedKey; + + fn encapsulate( + &self, + rng: R, + public_key: &Self::PublicKey, + identity: &[Self::Identity], + ) -> Result<(Self::Key, Self::EncapsulatedKey)>; + + fn decapsulate( + &self, + public_key: &Self::PublicKey, + key: &Self::PrivateKey, + encapsulation: &Self::EncapsulatedKey, + ) -> Result; +} + -- cgit v1.2.3