From bdc6c46ab55d259a32779ce28692c201986b23f0 Mon Sep 17 00:00:00 2001 From: Blair Noctis Date: Wed, 18 Oct 2023 20:58:52 +0800 Subject: [PATCH 1/4] fix: adapt to aead change of NewAead to KeyInit --- src/aead.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/aead.rs b/src/aead.rs index 75c4083..103b38b 100644 --- a/src/aead.rs +++ b/src/aead.rs @@ -25,7 +25,7 @@ regarded as a pointer, not a recommendation. // use rand_core::{RngCore,CryptoRng}; -use aead::{NewAead, generic_array::{GenericArray}}; +use aead::{KeyInit, KeySizeUser, generic_array::{GenericArray}}; use curve25519_dalek::digest::generic_array::typenum::{U32}; @@ -40,11 +40,11 @@ use crate::cert::AdaptorCertPublic; fn make_aead(mut t: T) -> AEAD -where T: SigningTranscript,AEAD: NewAead +where T: SigningTranscript,AEAD: KeyInit { - let mut key: GenericArray::KeySize> = Default::default(); + let mut key: GenericArray::KeySize> = Default::default(); t.challenge_bytes(b"",key.as_mut_slice()); - AEAD::new(key) + AEAD::new(&key) } impl SecretKey { @@ -66,11 +66,11 @@ impl SecretKey { /// /// Requires the AEAD have a 32 byte public key and does not support a context. pub fn aead32_unauthenticated(&self, public: &PublicKey) -> AEAD - where AEAD: NewAead + where AEAD: KeyInit { - let mut key: GenericArray::KeySize> = Default::default(); + let mut key: GenericArray::KeySize> = Default::default(); key.clone_from_slice( self.raw_key_exchange(public).as_bytes() ); - AEAD::new(key) + AEAD::new(&key) } } @@ -78,7 +78,7 @@ impl PublicKey { /// Initialize an AEAD to the public key `self` using an ephemeral key exchange. /// /// Returns the ephemeral public key and AEAD. - pub fn init_aead_unauthenticated(&self, ctx: &[u8]) -> (CompressedRistretto,AEAD) + pub fn init_aead_unauthenticated(&self, ctx: &[u8]) -> (CompressedRistretto,AEAD) { let ephemeral = Keypair::generate(); let aead = ephemeral.aead_unauthenticated(ctx,self); @@ -90,7 +90,7 @@ impl PublicKey { /// Returns the ephemeral public key and AEAD. /// Requires the AEAD have a 32 byte public key and does not support a context. pub fn init_aead32_unauthenticated(&self) -> (CompressedRistretto,AEAD) - where AEAD: NewAead + where AEAD: KeyInit { let secret = SecretKey::generate(); let aead = secret.aead32_unauthenticated(self); @@ -111,7 +111,7 @@ impl Keypair { } /// An AEAD from a key exchange with the specified public key. - pub fn aead_unauthenticated(&self, ctx: &[u8], public: &PublicKey) -> AEAD { + pub fn aead_unauthenticated(&self, ctx: &[u8], public: &PublicKey) -> AEAD { let mut t = merlin::Transcript::new(b"KEX"); t.append_message(b"ctx",ctx); self.commit_key_exchange(&mut t,b"kex",public); @@ -125,7 +125,7 @@ impl Keypair { ephemeral_pk: &PublicKey, static_pk: &PublicKey, ) -> AEAD - where T: SigningTranscript, AEAD: NewAead + where T: SigningTranscript, AEAD: KeyInit { self.commit_key_exchange(&mut t,b"epk",ephemeral_pk); self.commit_key_exchange(&mut t,b"epk",static_pk); @@ -138,7 +138,7 @@ impl Keypair { mut t: T, public: &PublicKey, ) -> (CompressedRistretto,AEAD) - where T: SigningTranscript, AEAD: NewAead + where T: SigningTranscript, AEAD: KeyInit { let key = t.witness_scalar(b"make_esk", &[&self.secret.nonce]); let ekey = SecretKey { key, nonce: self.secret.nonce.clone() }.to_keypair(); @@ -158,7 +158,7 @@ impl Keypair { cert_public: &AdaptorCertPublic, public: &PublicKey, ) -> SignatureResult - where T: SigningTranscript, AEAD: NewAead + where T: SigningTranscript, AEAD: KeyInit { let epk = public.open_adaptor_cert(t,cert_public) ?; Ok(self.aead_unauthenticated(b"",&epk)) @@ -169,7 +169,7 @@ impl Keypair { /// Along with the AEAD, we return the implicit Adaptor certificate /// from which the receiver recreates the ephemeral public key. pub fn sender_aead_with_adaptor_cert(&self, t: T, public: &PublicKey) -> (AdaptorCertPublic,AEAD) - where T: SigningTranscript+Clone, AEAD: NewAead + where T: SigningTranscript+Clone, AEAD: KeyInit { let (cert,secret) = self.issue_self_adaptor_cert(t); let aead = secret.to_keypair().aead_unauthenticated(b"",&public); From f06536c0eb40dcef6cfbff74590014de07a5e18b Mon Sep 17 00:00:00 2001 From: Blair Noctis Date: Wed, 18 Oct 2023 21:06:01 +0800 Subject: [PATCH 2/4] chore: cargo clippy src/aead.rs --- src/aead.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/aead.rs b/src/aead.rs index 103b38b..6cb1b67 100644 --- a/src/aead.rs +++ b/src/aead.rs @@ -51,7 +51,7 @@ impl SecretKey { /// Commit the results of a key exchange into a transcript #[inline(always)] pub(crate) fn raw_key_exchange(&self, public: &PublicKey) -> CompressedRistretto { - (&self.key * public.as_point()).compress() + (self.key * public.as_point()).compress() } /// Commit the results of a raw key exchange into a transcript @@ -141,7 +141,7 @@ impl Keypair { where T: SigningTranscript, AEAD: KeyInit { let key = t.witness_scalar(b"make_esk", &[&self.secret.nonce]); - let ekey = SecretKey { key, nonce: self.secret.nonce.clone() }.to_keypair(); + let ekey = SecretKey { key, nonce: self.secret.nonce }.to_keypair(); ekey.commit_key_exchange(&mut t,b"epk",public); self.commit_key_exchange(&mut t,b"epk",public); (ekey.public.into_compressed(), make_aead(t)) @@ -172,7 +172,7 @@ impl Keypair { where T: SigningTranscript+Clone, AEAD: KeyInit { let (cert,secret) = self.issue_self_adaptor_cert(t); - let aead = secret.to_keypair().aead_unauthenticated(b"",&public); + let aead = secret.to_keypair().aead_unauthenticated(b"", public); (cert, aead) } } From c6e918d1f6ab4133cdcefd54bc8cc3bee6277e3d Mon Sep 17 00:00:00 2001 From: Blair Noctis Date: Wed, 8 Nov 2023 20:57:11 +0800 Subject: [PATCH 3/4] fix: make aead depend on getrandom to enable Keypair::generate() --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 82f81e0..c501726 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,3 +65,4 @@ getrandom = ["rand_core/getrandom"] # wasm-bindgen = ["getrandom/wasm-bindgen"] # See https://github.com/rust-lang/cargo/issues/9210 # and https://github.com/w3f/schnorrkel/issues/65#issuecomment-786923588 +aead = ["dep:aead", "getrandom"] From c63cdeff9edccde2f39ae03fc5277c223c8864bf Mon Sep 17 00:00:00 2001 From: Blair Noctis Date: Wed, 8 Nov 2023 20:59:12 +0800 Subject: [PATCH 4/4] fix: RistrettoBoth::partial_cmp according to clippy --- src/points.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/points.rs b/src/points.rs index 3f9954a..0f60398 100644 --- a/src/points.rs +++ b/src/points.rs @@ -156,7 +156,7 @@ impl PartialEq for RistrettoBoth { impl PartialOrd for RistrettoBoth { fn partial_cmp(&self, other: &RistrettoBoth) -> Option<::core::cmp::Ordering> { - self.compressed.0.partial_cmp(&other.compressed.0) + Some(self.cmp(other)) } }