Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
13 changes: 7 additions & 6 deletions ecdsa/src/hazmat.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Low-level ECDSA primitives.
//!
//! # ⚠️ Warning: Hazmat!
//! <div class="warning">
//! <b>Security️ Warning: Hazardous Materials!</b>
//!
//! YOU PROBABLY DON'T WANT TO USE THESE!
//!
Expand All @@ -9,20 +10,20 @@
//! 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!
//! </div>

use crate::{EcdsaCurve, Error, Result};
use core::cmp;
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,
Expand Down Expand Up @@ -179,7 +180,7 @@ where

let k = NonZeroScalar::<C>::from_repr(rfc6979::generate_k::<D, _>(
&d.to_repr(),
&C::ORDER.encode_field_bytes(),
&field::uint_to_bytes::<C>(&C::ORDER),
&z2.to_repr(),
ad,
))
Expand Down
17 changes: 10 additions & 7 deletions ecdsa/src/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -363,11 +365,12 @@ where
let z = Scalar::<C>::reduce(&bits2field::<C>(prehash)?);

let r_bytes = if recovery_id.is_x_reduced() {
C::Uint::decode_field_bytes(&r.to_repr())
let uint = field::bytes_to_uint::<C>(&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::<C>(&uint)
} else {
r.to_repr()
};
Expand Down
Loading