aboutsummaryrefslogtreecommitdiff
path: root/src/hibe/mod.rs
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2023-11-26 18:45:59 +0100
committerDaniel Schadt <kingdread@gmx.de>2023-11-26 18:45:59 +0100
commitf2a90a51ce3045e676ba105caf96d5037e03d4b4 (patch)
treeb6e1cd8ccba7223e79283242c28ad50c904e23f2 /src/hibe/mod.rs
downloadhohibe-f2a90a51ce3045e676ba105caf96d5037e03d4b4.tar.gz
hohibe-f2a90a51ce3045e676ba105caf96d5037e03d4b4.tar.bz2
hohibe-f2a90a51ce3045e676ba105caf96d5037e03d4b4.zip
initial commit
Diffstat (limited to 'src/hibe/mod.rs')
-rw-r--r--src/hibe/mod.rs72
1 files changed, 72 insertions, 0 deletions
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<R: Rng>(&self, rng: R) -> Result<(Self::PublicKey, Self::MasterKey)>;
+
+ fn generate_key<R: Rng>(
+ &self,
+ rng: R,
+ public_key: &Self::PublicKey,
+ master_key: &Self::MasterKey,
+ identity: &[Self::Identity],
+ ) -> Result<Self::PrivateKey>;
+
+ fn derive_key<R: Rng>(
+ &self,
+ rng: R,
+ public_key: &Self::PublicKey,
+ parent_key: &Self::PrivateKey,
+ parent_name: &[Self::Identity],
+ child: &Self::Identity,
+ ) -> Result<Self::PrivateKey>;
+}
+
+pub trait HibeCrypt: Hibe {
+ type Message;
+ type Ciphertext;
+
+ fn encrypt<R: Rng>(
+ &self,
+ rng: R,
+ public_key: &Self::PublicKey,
+ identity: &[Self::Identity],
+ message: &Self::Message,
+ ) -> Result<Self::Ciphertext>;
+
+ fn decrypt(
+ &self,
+ public_key: &Self::PublicKey,
+ key: &Self::PrivateKey,
+ ciphertext: &Self::Ciphertext,
+ ) -> Result<Self::Message>;
+}
+
+pub trait HibeKem: Hibe {
+ type Key;
+ type EncapsulatedKey;
+
+ fn encapsulate<R: Rng>(
+ &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<Self::Key>;
+}
+