From 3d9180983c0e69d5b5a6737e826b5946e8ae2674 Mon Sep 17 00:00:00 2001 From: Sergey Kaunov Date: Sat, 9 Dec 2023 16:24:39 +0000 Subject: [PATCH] Fix issue with `crate` crate and mistakes of merge (#81) --- rust-k256/Cargo.toml | 2 -- rust-k256/src/lib.rs | 11 ++++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/rust-k256/Cargo.toml b/rust-k256/Cargo.toml index 860a5e6..98ae3a4 100644 --- a/rust-k256/Cargo.toml +++ b/rust-k256/Cargo.toml @@ -6,8 +6,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -crate = "0.0.2" -# ring = "0.16.20" rand_core = "0.6.3" hex-literal = "0.3.4" hash2field = "0.4.0" diff --git a/rust-k256/src/lib.rs b/rust-k256/src/lib.rs index 5b367ae..ecb8e6d 100644 --- a/rust-k256/src/lib.rs +++ b/rust-k256/src/lib.rs @@ -59,7 +59,7 @@ fn sha256hash6signals( } // Hashes two values to the curve -fn hash_to_curve(m: &[u8], pk: &ProjectivePoint) -> Result { +fn hash_to_curve(m: &[u8], pk: &ProjectivePoint) -> Result { Secp256k1::hash_from_bytes::>( &[[m, &encode_pt(pk)].concat().as_slice()], //b"CURVE_XMD:SHA-256_SSWU_RO_", @@ -90,14 +90,15 @@ impl PlumeSignature<'_> { // c = hash2(g, g^sk, hash[m, g^sk], hash[m, pk]^sk, gr, hash[m, pk]^r) pub fn verify_signals(&self) -> bool { // don't forget to check `c` is `Output` in the #API - let c = panic::catch_unwind(|| {Output::::from_slice(self.c);}); + let c = panic::catch_unwind(|| {Output::::from_slice(self.c)}); if c.is_err() {return false;} + let c = c.unwrap(); // TODO should we allow `c` input greater than BaseField::MODULUS? // TODO `reduce_nonzero` doesn't seems to be correct here. `NonZeroScalar` should be appropriate. - let c_scalar = &Scalar::reduce_nonzero(U256::from_be_byte_array(c.unwrap().to_owned())); + let c_scalar = &Scalar::reduce_nonzero(U256::from_be_byte_array(c.to_owned())); - let r_point = ProjectivePoint::GENERATOR * self.s - self.pk * &c_scalar; + let r_point = ProjectivePoint::GENERATOR * self.s - self.pk * c_scalar; let hashed_to_curve = hash_to_curve(self.message, self.pk); if hashed_to_curve.is_err() { @@ -105,7 +106,7 @@ impl PlumeSignature<'_> { } let hashed_to_curve = hashed_to_curve.unwrap(); - let hashed_to_curve_r = hashed_to_curve * self.s - self.nullifier * &c_scalar; + let hashed_to_curve_r = hashed_to_curve * self.s - self.nullifier * c_scalar; if let Some(PlumeSignatureV1Fields { r_point: sig_r_point,