diff --git a/Cargo.lock b/Cargo.lock index b8d39c69a..86c57423a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -364,8 +364,7 @@ dependencies = [ [[package]] name = "ecdsa" version = "0.17.0-rc.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abbc927a7e946a78fbff19c283bc5d4f8960d9000049a7e2b0d84cb2730613c4" +source = "git+https://github.com/RustCrypto/signatures.git?rev=2adc05328a2d7fb6f62421748f8e340936d3a18d#2adc05328a2d7fb6f62421748f8e340936d3a18d" dependencies = [ "der", "digest", @@ -386,8 +385,7 @@ checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" [[package]] name = "elliptic-curve" version = "0.14.0-rc.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1786d08ca7d401fcc540b2fab11ec37b224ced5a0455c451656f83d80e681ddb" +source = "git+https://github.com/RustCrypto/traits.git?rev=2ec3e144f69af5d3836d5d2b545b36105f6d69f9#2ec3e144f69af5d3836d5d2b545b36105f6d69f9" dependencies = [ "base16ct", "base64ct", @@ -427,8 +425,7 @@ checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" [[package]] name = "ff" version = "0.14.0-pre.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d42dd26f5790eda47c1a2158ea4120e32c35ddc9a7743c98a292accc01b54ef3" +source = "git+https://github.com/zkcrypto/ff.git?rev=8e139e2fb25ab61a5d362394af0a34b10c03d59b#8e139e2fb25ab61a5d362394af0a34b10c03d59b" dependencies = [ "bitvec", "ff_derive", @@ -439,8 +436,7 @@ dependencies = [ [[package]] name = "ff_derive" version = "0.14.0-pre.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9266df7c7c72e5a865a447aca13bf480d7310eaa4f84de117c33e361d4da8888" +source = "git+https://github.com/zkcrypto/ff.git?rev=8e139e2fb25ab61a5d362394af0a34b10c03d59b#8e139e2fb25ab61a5d362394af0a34b10c03d59b" dependencies = [ "addchain", "num-bigint 0.3.3", diff --git a/Cargo.toml b/Cargo.toml index 126bda128..3548c5662 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,3 +17,11 @@ members = [ [profile.dev] opt-level = 2 + +[patch.crates-io] +# https://github.com/RustCrypto/signatures/pull/972 +# https://github.com/RustCrypto/traits/pull/1869 +# https://github.com/zkcrypto/ff/pull/137 +ecdsa = { git = "https://github.com/RustCrypto/signatures.git", rev = "2adc05328a2d7fb6f62421748f8e340936d3a18d" } +elliptic-curve = { git = "https://github.com/RustCrypto/traits.git", rev = "2ec3e144f69af5d3836d5d2b545b36105f6d69f9" } +ff = { git = "https://github.com/zkcrypto/ff.git", rev = "8e139e2fb25ab61a5d362394af0a34b10c03d59b" } diff --git a/bign256/benches/scalar.rs b/bign256/benches/scalar.rs index 4667a1e90..7fecb354e 100644 --- a/bign256/benches/scalar.rs +++ b/bign256/benches/scalar.rs @@ -8,14 +8,14 @@ use hex_literal::hex; fn test_scalar_x() -> Scalar { Scalar::from_repr( - hex!("519b423d715f8b581f4fa8ee59f4771a5b44c8130b4e3eacca54a56dda72b464").into(), + &hex!("519b423d715f8b581f4fa8ee59f4771a5b44c8130b4e3eacca54a56dda72b464").into(), ) .unwrap() } fn test_scalar_y() -> Scalar { Scalar::from_repr( - hex!("0f56db78ca460b055c500064824bed999a25aaf48ebb519ac201537b85479813").into(), + &hex!("0f56db78ca460b055c500064824bed999a25aaf48ebb519ac201537b85479813").into(), ) .unwrap() } @@ -23,7 +23,7 @@ fn test_scalar_y() -> Scalar { fn bench_point_mul(group: &mut BenchmarkGroup) { let p = ProjectivePoint::GENERATOR; let m = test_scalar_x(); - let s = Scalar::from_repr(m.into()).unwrap(); + let s = Scalar::from_repr(&m.into()).unwrap(); group.bench_function("point-scalar mul", |b| b.iter(|| p * s)); } diff --git a/bign256/src/arithmetic/field.rs b/bign256/src/arithmetic/field.rs index bdbd48c0d..f53123179 100644 --- a/bign256/src/arithmetic/field.rs +++ b/bign256/src/arithmetic/field.rs @@ -94,8 +94,8 @@ impl PrimeField for FieldElement { type Repr = FieldBytes; #[inline] - fn from_repr(bytes: FieldBytes) -> CtOption { - Self::from_bytes(&bytes) + fn from_repr(bytes: &FieldBytes) -> CtOption { + Self::from_bytes(bytes) } #[inline] diff --git a/bign256/src/arithmetic/scalar.rs b/bign256/src/arithmetic/scalar.rs index d12e52a22..33b513dbb 100644 --- a/bign256/src/arithmetic/scalar.rs +++ b/bign256/src/arithmetic/scalar.rs @@ -130,8 +130,8 @@ impl IsHigh for Scalar { impl PrimeField for Scalar { type Repr = FieldBytes; - fn from_repr(repr: Self::Repr) -> CtOption { - Self::from_bytes(&repr) + fn from_repr(repr: &Self::Repr) -> CtOption { + Self::from_bytes(repr) } fn to_repr(&self) -> Self::Repr { diff --git a/bign256/src/ecdsa/signing.rs b/bign256/src/ecdsa/signing.rs index 09d82b989..90a3fbb57 100644 --- a/bign256/src/ecdsa/signing.rs +++ b/bign256/src/ecdsa/signing.rs @@ -112,7 +112,7 @@ impl PrehashSigner for SigningKey { let h = Scalar::reduce_bytes(&h_word); //2. Generate 𝑘 ← rand(1,..,𝑞-1) - let k = Scalar::from_repr(rfc6979::generate_k::( + let k = Scalar::from_repr(&rfc6979::generate_k::( &self.secret_scalar.to_repr(), &FieldBytesEncoding::::encode_field_bytes(&BignP256::ORDER), &h.to_bytes(), diff --git a/bp256/src/arithmetic/field.rs b/bp256/src/arithmetic/field.rs index e15de1833..d9880c54a 100644 --- a/bp256/src/arithmetic/field.rs +++ b/bp256/src/arithmetic/field.rs @@ -90,8 +90,8 @@ impl PrimeField for FieldElement { const DELTA: Self = Self::from_u64(121); #[inline] - fn from_repr(bytes: FieldBytes) -> CtOption { - Self::from_bytes(&bytes) + fn from_repr(bytes: &FieldBytes) -> CtOption { + Self::from_bytes(bytes) } #[inline] diff --git a/bp256/src/arithmetic/scalar.rs b/bp256/src/arithmetic/scalar.rs index c9e7eeb78..fc1e4b288 100644 --- a/bp256/src/arithmetic/scalar.rs +++ b/bp256/src/arithmetic/scalar.rs @@ -116,8 +116,8 @@ impl PrimeField for Scalar { const DELTA: Self = Self::from_u64(9); #[inline] - fn from_repr(bytes: FieldBytes) -> CtOption { - Self::from_bytes(&bytes) + fn from_repr(bytes: &FieldBytes) -> CtOption { + Self::from_bytes(bytes) } #[inline] diff --git a/bp384/src/arithmetic/field.rs b/bp384/src/arithmetic/field.rs index 3708d3bc0..04bb1c1d9 100644 --- a/bp384/src/arithmetic/field.rs +++ b/bp384/src/arithmetic/field.rs @@ -93,8 +93,8 @@ impl PrimeField for FieldElement { const DELTA: Self = Self::from_u64(9); #[inline] - fn from_repr(bytes: FieldBytes) -> CtOption { - Self::from_bytes(&bytes) + fn from_repr(bytes: &FieldBytes) -> CtOption { + Self::from_bytes(bytes) } #[inline] diff --git a/bp384/src/arithmetic/scalar.rs b/bp384/src/arithmetic/scalar.rs index afac0b560..526d64a09 100644 --- a/bp384/src/arithmetic/scalar.rs +++ b/bp384/src/arithmetic/scalar.rs @@ -124,8 +124,8 @@ impl PrimeField for Scalar { const DELTA: Self = Self::from_u64(16); #[inline] - fn from_repr(bytes: FieldBytes) -> CtOption { - Self::from_bytes(&bytes) + fn from_repr(bytes: &FieldBytes) -> CtOption { + Self::from_bytes(bytes) } #[inline] diff --git a/k256/benches/ecdsa.rs b/k256/benches/ecdsa.rs index a1891e909..72ab2805d 100644 --- a/k256/benches/ecdsa.rs +++ b/k256/benches/ecdsa.rs @@ -14,7 +14,7 @@ use std::hint::black_box; fn test_scalar_d() -> NonZeroScalar { NonZeroScalar::new( Scalar::from_repr( - [ + &[ 0xbb, 0x48, 0x8a, 0xef, 0x41, 0x6a, 0x41, 0xd7, 0x68, 0x0d, 0x1c, 0xf0, 0x1d, 0x70, 0xf5, 0x9b, 0x60, 0xd7, 0xf5, 0xf7, 0x7e, 0x30, 0xe7, 0x8b, 0x8b, 0xf9, 0xd2, 0xd8, 0x82, 0xf1, 0x56, 0xa6, diff --git a/k256/benches/scalar.rs b/k256/benches/scalar.rs index 6db9b2b25..da009e150 100644 --- a/k256/benches/scalar.rs +++ b/k256/benches/scalar.rs @@ -12,7 +12,7 @@ use std::hint::black_box; fn test_scalar_x() -> Scalar { Scalar::from_repr( - [ + &[ 0xbb, 0x48, 0x8a, 0xef, 0x41, 0x6a, 0x41, 0xd7, 0x68, 0x0d, 0x1c, 0xf0, 0x1d, 0x70, 0xf5, 0x9b, 0x60, 0xd7, 0xf5, 0xf7, 0x7e, 0x30, 0xe7, 0x8b, 0x8b, 0xf9, 0xd2, 0xd8, 0x82, 0xf1, 0x56, 0xa6, @@ -24,7 +24,7 @@ fn test_scalar_x() -> Scalar { fn test_scalar_y() -> Scalar { Scalar::from_repr( - [ + &[ 0x67, 0xe2, 0xf6, 0x80, 0x71, 0xed, 0x82, 0x81, 0xe8, 0xae, 0xd6, 0xbc, 0xf1, 0xc5, 0x20, 0x7c, 0x5e, 0x63, 0x37, 0x22, 0xd9, 0x20, 0xaf, 0xd6, 0xae, 0x22, 0xd0, 0x6e, 0xeb, 0x80, 0x35, 0xe3, @@ -37,7 +37,7 @@ fn test_scalar_y() -> Scalar { fn bench_point_mul(group: &mut BenchmarkGroup<'_, M>) { let p = ProjectivePoint::GENERATOR; let m = hex!("AA5E28D6A97A2479A65527F7290311A3624D4CC0FA1578598EE3C2613BF99522"); - let s = Scalar::from_repr(m.into()).unwrap(); + let s = Scalar::from_repr(&m.into()).unwrap(); group.bench_function("point-scalar mul", |b| { b.iter(|| black_box(p) * black_box(s)) }); @@ -46,7 +46,7 @@ fn bench_point_mul(group: &mut BenchmarkGroup<'_, M>) { fn bench_point_lincomb(group: &mut BenchmarkGroup<'_, M>) { let p = ProjectivePoint::GENERATOR; let m = hex!("AA5E28D6A97A2479A65527F7290311A3624D4CC0FA1578598EE3C2613BF99522"); - let s = Scalar::from_repr(m.into()).unwrap(); + let s = Scalar::from_repr(&m.into()).unwrap(); group.bench_function("lincomb via mul+add", |b| { b.iter(|| black_box(p) * black_box(s) + black_box(p) * black_box(s)) }); diff --git a/k256/src/arithmetic/field.rs b/k256/src/arithmetic/field.rs index b44ab13e0..414b4ed74 100644 --- a/k256/src/arithmetic/field.rs +++ b/k256/src/arithmetic/field.rs @@ -317,8 +317,8 @@ impl PrimeField for FieldElement { ])); const DELTA: Self = Self::from_u64(9); - fn from_repr(repr: Self::Repr) -> CtOption { - Self::from_bytes(&repr) + fn from_repr(repr: &Self::Repr) -> CtOption { + Self::from_bytes(repr) } fn to_repr(&self) -> Self::Repr { diff --git a/k256/src/arithmetic/projective.rs b/k256/src/arithmetic/projective.rs index 24909bd25..e4750fc17 100644 --- a/k256/src/arithmetic/projective.rs +++ b/k256/src/arithmetic/projective.rs @@ -912,7 +912,7 @@ mod tests { MUL_TEST_VECTORS .iter() .cloned() - .map(|(k, x, y)| (Scalar::from_repr(k.into()).unwrap(), (x, y))), + .map(|(k, x, y)| (Scalar::from_repr(&k.into()).unwrap(), (x, y))), ) { let res = (generator * &k).to_affine(); diff --git a/k256/src/arithmetic/scalar.rs b/k256/src/arithmetic/scalar.rs index bda88bd76..4a37f68fc 100644 --- a/k256/src/arithmetic/scalar.rs +++ b/k256/src/arithmetic/scalar.rs @@ -233,7 +233,7 @@ impl Field for Scalar { // TODO: pre-generate several scalars to bring the probability of non-constant-timeness down? loop { rng.try_fill_bytes(&mut bytes)?; - if let Some(scalar) = Scalar::from_repr(bytes).into() { + if let Some(scalar) = Scalar::from_repr(&bytes).into() { return Ok(scalar); } } @@ -329,8 +329,8 @@ impl PrimeField for Scalar { /// /// Returns None if the byte array does not contain a big-endian integer in the range /// [0, p). - fn from_repr(bytes: FieldBytes) -> CtOption { - let inner = U256::from_be_byte_array(bytes); + fn from_repr(bytes: &FieldBytes) -> CtOption { + let inner = U256::from_be_byte_array(*bytes); CtOption::new(Self(inner), inner.ct_lt(&Secp256k1::ORDER)) } @@ -904,7 +904,7 @@ mod tests { fn from(x: &BigUint) -> Self { debug_assert!(x < &Scalar::modulus_as_biguint()); let bytes = biguint_to_bytes(x); - Self::from_repr(bytes.into()).unwrap() + Self::from_repr(&bytes.into()).unwrap() } } @@ -1221,7 +1221,7 @@ mod tests { proptest! { #[test] fn fuzzy_roundtrip_to_bytes(a in scalar()) { - let a_back = Scalar::from_repr(a.to_bytes()).unwrap(); + let a_back = Scalar::from_repr(&a.to_bytes()).unwrap(); assert_eq!(a, a_back); } diff --git a/p192/src/arithmetic/field.rs b/p192/src/arithmetic/field.rs index f55ddbb3e..476888d4a 100644 --- a/p192/src/arithmetic/field.rs +++ b/p192/src/arithmetic/field.rs @@ -95,8 +95,8 @@ impl PrimeField for FieldElement { const DELTA: Self = Self::from_u64(121); #[inline] - fn from_repr(bytes: FieldBytes) -> CtOption { - Self::from_bytes(&bytes) + fn from_repr(bytes: &FieldBytes) -> CtOption { + Self::from_bytes(bytes) } #[inline] diff --git a/p192/src/arithmetic/scalar.rs b/p192/src/arithmetic/scalar.rs index 00e85558d..972c16553 100644 --- a/p192/src/arithmetic/scalar.rs +++ b/p192/src/arithmetic/scalar.rs @@ -178,8 +178,8 @@ impl PrimeField for Scalar { const DELTA: Self = Self::from_u64(43046721); #[inline] - fn from_repr(bytes: FieldBytes) -> CtOption { - Self::from_bytes(&bytes) + fn from_repr(bytes: &FieldBytes) -> CtOption { + Self::from_bytes(bytes) } #[inline] diff --git a/p224/src/arithmetic/field.rs b/p224/src/arithmetic/field.rs index 1025e0cc7..a68a8160c 100644 --- a/p224/src/arithmetic/field.rs +++ b/p224/src/arithmetic/field.rs @@ -273,8 +273,8 @@ impl PrimeField for FieldElement { Self::from_hex("00000000697b16135c4a62fca5c4f35ea6d5784cf3808e775aad34ec3d046867"); #[inline] - fn from_repr(bytes: FieldBytes) -> CtOption { - Self::from_bytes(&bytes) + fn from_repr(bytes: &FieldBytes) -> CtOption { + Self::from_bytes(bytes) } #[inline] diff --git a/p224/src/arithmetic/scalar.rs b/p224/src/arithmetic/scalar.rs index cf7b32e73..a552076a2 100644 --- a/p224/src/arithmetic/scalar.rs +++ b/p224/src/arithmetic/scalar.rs @@ -173,8 +173,8 @@ impl PrimeField for Scalar { const DELTA: Self = Self::from_u64(16); #[inline] - fn from_repr(bytes: FieldBytes) -> CtOption { - Self::from_bytes(&bytes) + fn from_repr(bytes: &FieldBytes) -> CtOption { + Self::from_bytes(bytes) } #[inline] diff --git a/p256/benches/scalar.rs b/p256/benches/scalar.rs index 2de4d74ef..cce75a755 100644 --- a/p256/benches/scalar.rs +++ b/p256/benches/scalar.rs @@ -8,14 +8,14 @@ use p256::{ProjectivePoint, Scalar, elliptic_curve::group::ff::PrimeField}; fn test_scalar_x() -> Scalar { Scalar::from_repr( - hex!("519b423d715f8b581f4fa8ee59f4771a5b44c8130b4e3eacca54a56dda72b464").into(), + &hex!("519b423d715f8b581f4fa8ee59f4771a5b44c8130b4e3eacca54a56dda72b464").into(), ) .unwrap() } fn test_scalar_y() -> Scalar { Scalar::from_repr( - hex!("0f56db78ca460b055c500064824bed999a25aaf48ebb519ac201537b85479813").into(), + &hex!("0f56db78ca460b055c500064824bed999a25aaf48ebb519ac201537b85479813").into(), ) .unwrap() } @@ -23,7 +23,7 @@ fn test_scalar_y() -> Scalar { fn bench_point_mul(group: &mut BenchmarkGroup<'_, M>) { let p = ProjectivePoint::GENERATOR; let m = test_scalar_x(); - let s = Scalar::from_repr(m.into()).unwrap(); + let s = Scalar::from_repr(&m.into()).unwrap(); group.bench_function("point-scalar mul", |b| b.iter(|| p * s)); } diff --git a/p256/src/arithmetic/field.rs b/p256/src/arithmetic/field.rs index e62b38f53..5fa3e2464 100644 --- a/p256/src/arithmetic/field.rs +++ b/p256/src/arithmetic/field.rs @@ -179,8 +179,8 @@ impl PrimeField for FieldElement { const ROOT_OF_UNITY_INV: Self = Self::ROOT_OF_UNITY.invert_unchecked(); const DELTA: Self = Self::from_u64(36); - fn from_repr(bytes: FieldBytes) -> CtOption { - Self::from_bytes(&bytes) + fn from_repr(bytes: &FieldBytes) -> CtOption { + Self::from_bytes(bytes) } fn to_repr(&self) -> FieldBytes { diff --git a/p256/src/arithmetic/scalar.rs b/p256/src/arithmetic/scalar.rs index 10c58c30e..2e8e521b6 100644 --- a/p256/src/arithmetic/scalar.rs +++ b/p256/src/arithmetic/scalar.rs @@ -208,7 +208,7 @@ impl Field for Scalar { // iterations is vanishingly small. loop { rng.try_fill_bytes(&mut bytes)?; - if let Some(scalar) = Scalar::from_repr(bytes).into() { + if let Some(scalar) = Scalar::from_repr(&bytes).into() { return Ok(scalar); } } @@ -292,8 +292,8 @@ impl PrimeField for Scalar { /// /// Returns None if the byte array does not contain a big-endian integer in the range /// [0, p). - fn from_repr(bytes: FieldBytes) -> CtOption { - let inner = U256::from_be_byte_array(bytes); + fn from_repr(bytes: &FieldBytes) -> CtOption { + let inner = U256::from_be_byte_array(*bytes); CtOption::new(Self(inner), inner.ct_lt(&NistP256::ORDER)) } @@ -736,7 +736,7 @@ mod tests { let mut bytes = FieldBytes::default(); bytes[24..].copy_from_slice(k.to_be_bytes().as_ref()); - let scalar = Scalar::from_repr(bytes).unwrap(); + let scalar = Scalar::from_repr(&bytes).unwrap(); assert_eq!(bytes, scalar.to_bytes()); } diff --git a/p384/benches/scalar.rs b/p384/benches/scalar.rs index c53d1b1ab..67070d295 100644 --- a/p384/benches/scalar.rs +++ b/p384/benches/scalar.rs @@ -7,13 +7,13 @@ use hex_literal::hex; use p384::{ProjectivePoint, Scalar, elliptic_curve::group::ff::PrimeField}; fn test_scalar_x() -> Scalar { - Scalar::from_repr( + Scalar::from_repr(& hex!("201b432d8df14324182d6261db3e4b3f46a8284482d52e370da41e6cbdf45ec2952f5db7ccbce3bc29449f4fb080ac97").into() ).unwrap() } fn test_scalar_y() -> Scalar { - Scalar::from_repr( + Scalar::from_repr(& hex!("23d9f4ea6d87b7d6163d64256e3449255db14786401a51daa7847161bf56d494325ad2ac8ba928394e01061d882c3528").into() ).unwrap() } @@ -21,7 +21,7 @@ fn test_scalar_y() -> Scalar { fn bench_point_mul(group: &mut BenchmarkGroup<'_, M>) { let p = ProjectivePoint::GENERATOR; let m = test_scalar_x(); - let s = Scalar::from_repr(m.into()).unwrap(); + let s = Scalar::from_repr(&m.into()).unwrap(); group.bench_function("point-scalar mul", |b| b.iter(|| p * s)); } diff --git a/p384/src/arithmetic/field.rs b/p384/src/arithmetic/field.rs index cf876991a..126133568 100644 --- a/p384/src/arithmetic/field.rs +++ b/p384/src/arithmetic/field.rs @@ -121,8 +121,8 @@ impl PrimeField for FieldElement { const DELTA: Self = Self::from_u64(49); #[inline] - fn from_repr(bytes: FieldBytes) -> CtOption { - Self::from_bytes(&bytes) + fn from_repr(bytes: &FieldBytes) -> CtOption { + Self::from_bytes(bytes) } #[inline] diff --git a/p384/src/arithmetic/scalar.rs b/p384/src/arithmetic/scalar.rs index 5907e614c..4b69e7aa4 100644 --- a/p384/src/arithmetic/scalar.rs +++ b/p384/src/arithmetic/scalar.rs @@ -199,8 +199,8 @@ impl PrimeField for Scalar { const DELTA: Self = Self::from_u64(4); #[inline] - fn from_repr(bytes: FieldBytes) -> CtOption { - Self::from_bytes(&bytes) + fn from_repr(bytes: &FieldBytes) -> CtOption { + Self::from_bytes(bytes) } #[inline] @@ -313,7 +313,7 @@ mod tests { let mut bytes = FieldBytes::default(); bytes[40..].copy_from_slice(k.to_be_bytes().as_ref()); - let scalar = Scalar::from_repr(bytes).unwrap(); + let scalar = Scalar::from_repr(&bytes).unwrap(); assert_eq!(bytes, scalar.to_bytes()); } diff --git a/p521/benches/scalar.rs b/p521/benches/scalar.rs index 12a7e3cc2..64a4e9eb8 100644 --- a/p521/benches/scalar.rs +++ b/p521/benches/scalar.rs @@ -8,13 +8,13 @@ use p521::{ProjectivePoint, Scalar, elliptic_curve::group::ff::PrimeField}; use std::hint::black_box; fn test_scalar_x() -> Scalar { - black_box(Scalar::from_repr( + black_box(Scalar::from_repr(& hex!("01d7bb864c5b5ecae019296cf9b5c63a166f5f1113942819b1933d889a96d12245777a99428f93de4fc9a18d709bf91889d7f8dddd522b4c364aeae13c983e9fae46").into() ).unwrap()) } fn test_scalar_y() -> Scalar { - black_box(Scalar::from_repr( + black_box(Scalar::from_repr(& hex!("017e49b8ea8f9d1b7c0378e378a7a42e68e12cf78779ed41dcd29a090ae7e0f883b0d0f2cbc8f0473c0ad6732bea40d371a7f363bc6537d075bd1a4c23e558b0bc73").into() ).unwrap()) } @@ -22,7 +22,7 @@ fn test_scalar_y() -> Scalar { fn bench_point_mul(group: &mut BenchmarkGroup<'_, M>) { let p = ProjectivePoint::GENERATOR; let m = test_scalar_x(); - let s = Scalar::from_repr(m.into()).unwrap(); + let s = Scalar::from_repr(&m.into()).unwrap(); group.bench_function("point-scalar mul", |b| b.iter(|| p * s)); } diff --git a/p521/src/arithmetic/field.rs b/p521/src/arithmetic/field.rs index 5c5220eb9..e1d72a413 100644 --- a/p521/src/arithmetic/field.rs +++ b/p521/src/arithmetic/field.rs @@ -478,8 +478,8 @@ impl PrimeField for FieldElement { const DELTA: Self = Self::from_u64(9); #[inline] - fn from_repr(bytes: FieldBytes) -> CtOption { - Self::from_bytes(&bytes) + fn from_repr(bytes: &FieldBytes) -> CtOption { + Self::from_bytes(bytes) } #[inline] diff --git a/p521/src/arithmetic/scalar.rs b/p521/src/arithmetic/scalar.rs index 85f1dc11b..e22436e59 100644 --- a/p521/src/arithmetic/scalar.rs +++ b/p521/src/arithmetic/scalar.rs @@ -589,8 +589,8 @@ impl PrimeField for Scalar { const DELTA: Self = Self::from_u64(6561); #[inline] - fn from_repr(bytes: FieldBytes) -> CtOption { - Self::from_bytes(&bytes) + fn from_repr(bytes: &FieldBytes) -> CtOption { + Self::from_bytes(bytes) } #[inline] diff --git a/primeorder/src/affine.rs b/primeorder/src/affine.rs index fb64e80d1..e6c55bfec 100644 --- a/primeorder/src/affine.rs +++ b/primeorder/src/affine.rs @@ -132,7 +132,7 @@ where FieldBytes: Copy, { fn decompress(x_bytes: &FieldBytes, y_is_odd: Choice) -> CtOption { - C::FieldElement::from_repr(*x_bytes).and_then(|x| { + C::FieldElement::from_repr(x_bytes).and_then(|x| { let alpha = x * &x * &x + &(C::EQUATION_A * &x) + &C::EQUATION_B; let beta = alpha.sqrt(); @@ -182,8 +182,8 @@ where Self::decompress(x, Choice::from(y_is_odd as u8)) } sec1::Coordinates::Uncompressed { x, y } => { - C::FieldElement::from_repr(*y).and_then(|y| { - C::FieldElement::from_repr(*x).and_then(|x| { + C::FieldElement::from_repr(y).and_then(|y| { + C::FieldElement::from_repr(x).and_then(|x| { let lhs = y * &y; let rhs = x * &x * &x + &(C::EQUATION_A * &x) + &C::EQUATION_B; CtOption::new(Self { x, y, infinity: 0 }, lhs.ct_eq(&rhs)) diff --git a/primeorder/src/dev.rs b/primeorder/src/dev.rs index 30dcebb5e..da6865e3d 100644 --- a/primeorder/src/dev.rs +++ b/primeorder/src/dev.rs @@ -141,7 +141,7 @@ macro_rules! test_projective_arithmetic { $mul_vectors .iter() .cloned() - .map(|(k, x, y)| (<$scalar>::from_repr(k.into()).unwrap(), (x, y))), + .map(|(k, x, y)| (<$scalar>::from_repr(&k.into()).unwrap(), (x, y))), ) { let p = generator * &k; diff --git a/sm2/src/arithmetic/field.rs b/sm2/src/arithmetic/field.rs index 8226a8fcb..4cf699fdb 100644 --- a/sm2/src/arithmetic/field.rs +++ b/sm2/src/arithmetic/field.rs @@ -103,8 +103,8 @@ impl PrimeField for FieldElement { const DELTA: Self = Self::from_u64(169); #[inline] - fn from_repr(bytes: FieldBytes) -> CtOption { - Self::from_bytes(&bytes) + fn from_repr(bytes: &FieldBytes) -> CtOption { + Self::from_bytes(bytes) } #[inline] diff --git a/sm2/src/arithmetic/scalar.rs b/sm2/src/arithmetic/scalar.rs index 2865daaea..faa9bafa4 100644 --- a/sm2/src/arithmetic/scalar.rs +++ b/sm2/src/arithmetic/scalar.rs @@ -157,8 +157,8 @@ impl PrimeField for Scalar { const DELTA: Self = Self::from_u64(9); #[inline] - fn from_repr(bytes: FieldBytes) -> CtOption { - Self::from_bytes(&bytes) + fn from_repr(bytes: &FieldBytes) -> CtOption { + Self::from_bytes(bytes) } #[inline] diff --git a/sm2/src/dsa/signing.rs b/sm2/src/dsa/signing.rs index 107e07454..9e845270c 100644 --- a/sm2/src/dsa/signing.rs +++ b/sm2/src/dsa/signing.rs @@ -203,7 +203,7 @@ fn sign_prehash_rfc6979(secret_scalar: &Scalar, prehash: &[u8], data: &[u8]) -> let e = Scalar::reduce_bytes(FieldBytes::from_slice(prehash)); // A3: pick a random number k in [1, n-1] via a random number generator - let k = Scalar::from_repr(rfc6979::generate_k::( + let k = Scalar::from_repr(&rfc6979::generate_k::( &secret_scalar.to_repr(), &FieldBytesEncoding::::encode_field_bytes(&Sm2::ORDER), &e.to_bytes(),