From 253dfde60e6106ceeda696b86cb2f605ce3cd557 Mon Sep 17 00:00:00 2001 From: derekpierre Date: Tue, 6 Jun 2023 11:11:31 -0400 Subject: [PATCH] Remove unnecessary/excession make_factory method from SessionSecretFactory. --- .../nucypher_core/__init__.pyi | 4 ---- nucypher-core-python/src/lib.rs | 6 ------ nucypher-core-wasm/src/lib.rs | 5 ----- nucypher-core/src/dkg.rs | 19 ++++++++----------- 4 files changed, 8 insertions(+), 26 deletions(-) diff --git a/nucypher-core-python/nucypher_core/__init__.pyi b/nucypher-core-python/nucypher_core/__init__.pyi index e96c3263..fce1d08b 100644 --- a/nucypher-core-python/nucypher_core/__init__.pyi +++ b/nucypher-core-python/nucypher_core/__init__.pyi @@ -534,7 +534,3 @@ class SessionSecretFactory: def make_key(self, label: bytes) -> SessionStaticSecret: ... - - def make_factory(self, label: bytes) -> RequestKeyFactory: - ... - diff --git a/nucypher-core-python/src/lib.rs b/nucypher-core-python/src/lib.rs index 63b84d8e..5aa09c55 100644 --- a/nucypher-core-python/src/lib.rs +++ b/nucypher-core-python/src/lib.rs @@ -737,12 +737,6 @@ impl SessionSecretFactory { } } - pub fn make_factory(&self, label: &[u8]) -> SessionSecretFactory { - SessionSecretFactory { - backend: self.backend.make_factory(label), - } - } - fn __str__(&self) -> String { self.backend.to_string() } diff --git a/nucypher-core-wasm/src/lib.rs b/nucypher-core-wasm/src/lib.rs index a4ca38ec..a84f4fc3 100644 --- a/nucypher-core-wasm/src/lib.rs +++ b/nucypher-core-wasm/src/lib.rs @@ -633,11 +633,6 @@ impl SessionSecretFactory { SessionStaticSecret(self.0.make_key(label)) } - #[wasm_bindgen(js_name = makeFactory)] - pub fn make_factory(&self, label: &[u8]) -> Self { - Self(self.0.make_factory(label)) - } - #[allow(clippy::inherent_to_string)] #[wasm_bindgen(js_name = toString)] pub fn to_string(&self) -> String { diff --git a/nucypher-core/src/dkg.rs b/nucypher-core/src/dkg.rs index 564eed1e..3ca231cf 100644 --- a/nucypher-core/src/dkg.rs +++ b/nucypher-core/src/dkg.rs @@ -264,6 +264,7 @@ pub mod session { type SessionSecretFactorySeed = GenericArray; /// Error thrown when invalid random seed provided for creating key factory. + #[derive(Debug)] pub struct InvalidSessionSecretFactorySeedLength; impl fmt::Display for InvalidSessionSecretFactorySeedLength { @@ -319,14 +320,6 @@ pub mod session { ChaCha20Rng::from_seed(<[u8; 32]>::try_from(seed.as_secret().as_slice()).unwrap()); SessionStaticSecret::random_from_rng(&mut rng) } - - /// Creates a `SessionSecretFactory` deterministically from the given label. - pub fn make_factory(&self, label: &[u8]) -> Self { - let prefix = b"SESSION_SECRET_FACTORY_DERIVATION/"; - let info = [prefix, label].concat(); - let derived_seed = kdf::(self.0.as_secret(), Some(&info)); - Self(derived_seed) - } } impl fmt::Display for SessionSecretFactory { @@ -590,6 +583,7 @@ mod tests { }; use generic_array::typenum::Unsigned; + use rand_core::RngCore; use crate::dkg::session::SessionStaticSecret; use crate::dkg::{ @@ -652,9 +646,12 @@ mod tests { assert_ne!(requester_public_key, not_same_requester_public_key); // ensure that two secret factories with the same seed generate the same keys - let secret_factory_label = b"seeded_secret_factory_label".to_vec().into_boxed_slice(); - let seeded_secret_factory_1 = secret_factory.make_factory(&secret_factory_label.as_ref()); - let seeded_secret_factory_2 = secret_factory.make_factory(&secret_factory_label.as_ref()); + let mut secret_factory_seed = [0u8; 32]; + rand::thread_rng().fill_bytes(&mut secret_factory_seed); + let seeded_secret_factory_1 = + SessionSecretFactory::from_secure_randomness(&secret_factory_seed).unwrap(); + let seeded_secret_factory_2 = + SessionSecretFactory::from_secure_randomness(&secret_factory_seed).unwrap(); let key_label = b"seeded_factory_key_label".to_vec().into_boxed_slice(); let sk_1 = seeded_secret_factory_1.make_key(&key_label);