diff --git a/Cargo.lock b/Cargo.lock index fc6d0629..47dcdddb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -341,9 +341,8 @@ checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" [[package]] name = "crypto-bigint" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42a0d26b245348befa0c121944541476763dcc46ede886c88f9d12e1697d27c3" +version = "0.7.4" +source = "git+https://github.com/RustCrypto/crypto-bigint#ec6615fad09d26f8518378f1fdfe96a635ddab2d" dependencies = [ "cpubits", "ctutils", @@ -505,8 +504,7 @@ checksum = "91622ff5e7162018101f2fea40d6ebf4a78bbe5a49736a2020649edf9693679e" [[package]] name = "elliptic-curve" version = "0.14.0-rc.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51c58d86e2f3cebbf2dfd94c4bf049585c7def71058ba506bfdafcb57652a34b" +source = "git+https://github.com/RustCrypto/traits#d1ca96d9a456337c74e1aa8e1582a7e26447dbef" dependencies = [ "base16ct", "crypto-bigint", diff --git a/Cargo.toml b/Cargo.toml index a97ed3d3..a3339cff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,3 +71,6 @@ ml-dsa = { path = "./ml-dsa" } rfc6979 = { path = "./rfc6979" } slh-dsa = { path = "./slh-dsa" } xmss = { path = "./xmss" } + +crypto-bigint = { git = "https://github.com/RustCrypto/crypto-bigint" } +elliptic-curve = { git = "https://github.com/RustCrypto/traits" } diff --git a/ecdsa/src/hazmat.rs b/ecdsa/src/hazmat.rs index ee38b467..058578c0 100644 --- a/ecdsa/src/hazmat.rs +++ b/ecdsa/src/hazmat.rs @@ -1,6 +1,7 @@ //! Low-level ECDSA primitives. //! -//! # ⚠️ Warning: Hazmat! +//!
+//! Security️ Warning: Hazardous Materials! //! //! YOU PROBABLY DON'T WANT TO USE THESE! //! @@ -9,6 +10,7 @@ //! If you are an end user / non-expert in cryptography, do not use these! //! Failure to use them correctly can lead to catastrophic failures including //! FULL PRIVATE KEY RECOVERY! +//!
use crate::{EcdsaCurve, Error, Result}; use core::cmp; @@ -16,13 +18,12 @@ use elliptic_curve::{FieldBytes, array::typenum::Unsigned}; #[cfg(feature = "algorithm")] use { - crate::{ - RecoveryId, Signature, SignatureSize, - elliptic_curve::{FieldBytesEncoding, array::ArraySize}, - }, + crate::{RecoveryId, Signature, SignatureSize}, elliptic_curve::{ CurveArithmetic, NonZeroScalar, ProjectivePoint, Scalar, + array::ArraySize, ff::PrimeField, + field, group::{Curve as _, Group}, ops::{Invert, MulByGeneratorVartime, Reduce}, point::AffineCoordinates, @@ -179,7 +180,7 @@ where let k = NonZeroScalar::::from_repr(rfc6979::generate_k::( &d.to_repr(), - &C::ORDER.encode_field_bytes(), + &field::uint_to_bytes::(&C::ORDER), &z2.to_repr(), ad, )) diff --git a/ecdsa/src/recovery.rs b/ecdsa/src/recovery.rs index 8320ee93..b3cd42ca 100644 --- a/ecdsa/src/recovery.rs +++ b/ecdsa/src/recovery.rs @@ -10,14 +10,16 @@ use { }, digest::{Digest, FixedOutputReset, Update}, elliptic_curve::{ - AffinePoint, FieldBytesEncoding, FieldBytesSize, Group, PrimeField, ProjectivePoint, + AffinePoint, CurveArithmetic, FieldBytes, FieldBytesSize, Group, PrimeField, + ProjectivePoint, Scalar, + array::ArraySize, bigint::CheckedAdd, + field, + ops::Invert, ops::{LinearCombination, Reduce}, point::DecompressPoint, sec1::{self, FromSec1Point, ToSec1Point}, - }, - elliptic_curve::{ - CurveArithmetic, FieldBytes, Scalar, array::ArraySize, ops::Invert, subtle::CtOption, + subtle::CtOption, }, signature::{ DigestSigner, MultipartSigner, RandomizedDigestSigner, Signer, @@ -363,11 +365,12 @@ where let z = Scalar::::reduce(&bits2field::(prehash)?); let r_bytes = if recovery_id.is_x_reduced() { - C::Uint::decode_field_bytes(&r.to_repr()) + let uint = field::bytes_to_uint::(&r.to_repr()) .checked_add(&C::ORDER) .into_option() - .ok_or_else(Error::new)? - .encode_field_bytes() + .ok_or_else(Error::new)?; + + field::uint_to_bytes::(&uint) } else { r.to_repr() };