ecdsa: use new Reduce trait (#1030)

Uses the `Reduce` trait added in RustCrypto/traits#1949
This commit is contained in:
Tony Arcieri
2025-08-04 21:44:24 -06:00
committed by GitHub
parent 282873b764
commit 18be0266f9
4 changed files with 11 additions and 11 deletions
Generated
+4 -4
View File
@@ -261,9 +261,9 @@ checksum = "43da5946c66ffcc7745f48db692ffbb10a83bfe0afd96235c5c2a4fb23994929"
[[package]]
name = "crypto-bigint"
version = "0.7.0-pre.7"
version = "0.7.0-rc.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85ff38607b7ebe30e4715eeb0a0427ff42e3b6b47b2df55a775e767ef2658ccd"
checksum = "737a2363b81de8cc95d8780d84aecb4b3c6f41e4473759da6636072b5514c875"
dependencies = [
"hybrid-array",
"num-traits",
@@ -409,8 +409,8 @@ checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
[[package]]
name = "elliptic-curve"
version = "0.14.0-rc.10"
source = "git+https://github.com/RustCrypto/traits#a10ef181945a480bba5d2fb36ad6f3f78a3474db"
version = "0.14.0-rc.11"
source = "git+https://github.com/RustCrypto/traits#526970708925a6030483d55fb00e62a9781505b4"
dependencies = [
"base16ct",
"crypto-bigint",
+1 -1
View File
@@ -18,7 +18,7 @@ rust-version = "1.85"
[dependencies]
der = { version = "0.8.0-rc.7", features = ["alloc"] }
digest = "0.11.0-rc.0"
crypto-bigint = { version = "=0.7.0-pre.7", default-features = false, features = ["alloc", "zeroize"] }
crypto-bigint = { version = "0.7.0-rc.0", default-features = false, features = ["alloc", "zeroize"] }
crypto-primes = { version = "=0.7.0-pre.1", default-features = false }
rfc6979 = { version = "0.5.0-rc.0" }
sha2 = { version = "0.11.0-rc.0", default-features = false }
+5 -5
View File
@@ -113,7 +113,7 @@ where
C: EcdsaCurve + CurveArithmetic,
SignatureSize<C>: ArraySize,
{
let z = <Scalar<C> as Reduce<C::Uint>>::reduce_bytes(z);
let z = Scalar::<C>::reduce(z);
// Compute scalar inversion of 𝑘.
let k_inv = k.invert();
@@ -123,7 +123,7 @@ where
// Lift x-coordinate of 𝑹 (element of base field) into a serialized big
// integer, then reduce it into an element of the scalar field.
let r = Scalar::<C>::reduce_bytes(&R.x());
let r = Scalar::<C>::reduce(&R.x());
// Compute 𝒔 as a signature over 𝒓 and 𝒛.
let s = *k_inv * (z + (r * d.as_ref()));
@@ -176,7 +176,7 @@ where
// transform and an extra modular reduction:
//
// h = bits2int(H(m)) mod q
let z2 = <Scalar<C> as Reduce<C::Uint>>::reduce_bytes(z);
let z2 = Scalar::<C>::reduce(z);
let k = NonZeroScalar::<C>::from_repr(rfc6979::generate_k::<D, _>(
&d.to_repr(),
@@ -211,7 +211,7 @@ where
C: EcdsaCurve + CurveArithmetic,
SignatureSize<C>: ArraySize,
{
let z = Scalar::<C>::reduce_bytes(z);
let z = Scalar::<C>::reduce(z);
let (r, s) = sig.split_scalars();
let s_inv = *s.invert_vartime();
let u1 = z * s_inv;
@@ -220,7 +220,7 @@ where
.to_affine()
.x();
if *r == Scalar::<C>::reduce_bytes(&x) {
if *r == Scalar::<C>::reduce(&x) {
Ok(())
} else {
Err(Error::new())
+1 -1
View File
@@ -373,7 +373,7 @@ where
recovery_id: RecoveryId,
) -> Result<Self> {
let (r, s) = signature.split_scalars();
let z = <Scalar<C> as Reduce<C::Uint>>::reduce_bytes(&bits2field::<C>(prehash)?);
let z = Scalar::<C>::reduce(&bits2field::<C>(prehash)?);
let r_bytes = if recovery_id.is_x_reduced() {
Option::<C::Uint>::from(