Skip to content

Commit cfb2454

Browse files
authored
Merge branch 'master' into tf/restrict-visibility
2 parents 3929d82 + 305bad5 commit cfb2454

File tree

19 files changed

+192
-116
lines changed

19 files changed

+192
-116
lines changed

Cargo.lock

Lines changed: 11 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dsa/src/generate/secret_number.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{Components, signing_key::SigningKey};
66
use alloc::vec;
77
use core::cmp::min;
88
use crypto_bigint::{BoxedUint, NonZero, RandomBits, Resize};
9-
use rfc6979::hmac::EagerHash;
9+
use digest::block_api::EagerHash;
1010
use signature::rand_core::TryCryptoRng;
1111
use zeroize::Zeroizing;
1212

dsa/src/signing_key.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ use crypto_bigint::{
1313
BoxedUint, NonZero, Resize,
1414
modular::{BoxedMontyForm, BoxedMontyParams},
1515
};
16-
use digest::Update;
17-
use rfc6979::hmac::EagerHash;
16+
use digest::{Update, block_api::EagerHash};
1817
use signature::{
1918
DigestSigner, MultipartSigner, RandomizedDigestSigner, Signer,
2019
hazmat::{PrehashSigner, RandomizedPrehashSigner},

dsa/src/verifying_key.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ use crypto_bigint::{
88
BoxedUint, NonZero, Resize,
99
modular::{BoxedMontyForm, BoxedMontyParams},
1010
};
11-
use digest::Update;
12-
use rfc6979::hmac::EagerHash;
11+
use digest::{Update, block_api::EagerHash};
1312
use signature::{DigestVerifier, MultipartVerifier, Verifier, hazmat::PrehashVerifier};
1413

1514
#[cfg(feature = "pkcs8")]

dsa/tests/deterministic.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#![cfg(feature = "hazmat")]
22
use crypto_bigint::BoxedUint;
3-
use digest::Update;
3+
use digest::{Update, block_api::EagerHash};
44
use dsa::{Components, Signature, SigningKey, VerifyingKey};
5-
use rfc6979::hmac::EagerHash;
65
use sha1::Sha1;
76
use sha2::{Sha224, Sha256, Sha384, Sha512};
87
use signature::DigestSigner;

ecdsa/Cargo.toml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ zeroize = { version = "1.5", default-features = false }
2323

2424
# optional dependencies
2525
der = { version = "0.8.0-rc.8", optional = true }
26-
digest = { version = "0.11.0-rc.1", optional = true, default-features = false, features = ["oid"] }
27-
hmac = { version = "0.13.0-rc.1", default-features = false, optional = true }
26+
digest = { version = "0.11.0-rc.2", optional = true, default-features = false, features = ["oid"] }
2827
rfc6979 = { version = "0.5.0-rc.1", optional = true }
2928
serdect = { version = "0.4", optional = true, default-features = false, features = ["alloc"] }
3029
sha2 = { version = "0.11.0-rc.2", optional = true, default-features = false, features = ["oid"] }
@@ -40,11 +39,10 @@ default = ["digest"]
4039
alloc = ["elliptic-curve/alloc", "signature/alloc", "spki/alloc"]
4140
std = ["alloc", "elliptic-curve/std"]
4241

43-
arithmetic = ["dep:hmac", "dep:rfc6979", "elliptic-curve/arithmetic"]
44-
algorithm = ["dep:rfc6979", "arithmetic", "digest", "hazmat"]
45-
dev = ["arithmetic", "digest", "elliptic-curve/dev", "hazmat"]
42+
algorithm = ["dep:rfc6979", "digest", "elliptic-curve/arithmetic", "hazmat"]
43+
dev = ["algorithm", "digest/dev", "elliptic-curve/dev"]
4644
der = ["dep:der"]
47-
digest = ["dep:digest", "dep:hmac", "elliptic-curve/digest", "signature/digest"]
45+
digest = ["dep:digest", "elliptic-curve/digest", "signature/digest"]
4846
hazmat = []
4947
pkcs8 = ["der", "digest", "elliptic-curve/pkcs8"]
5048
pem = ["elliptic-curve/pem", "pkcs8"]

ecdsa/src/der.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ fn find_scalar_range(outer: &[u8], inner: &[u8]) -> Result<Range<usize>> {
393393
Ok(Range { start, end })
394394
}
395395

396-
#[cfg(all(test, feature = "arithmetic"))]
396+
#[cfg(all(test, feature = "algorithm"))]
397397
mod tests {
398398
use elliptic_curve::dev::MockCurve;
399399

ecdsa/src/dev.rs

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use crate::EcdsaCurve;
77
use elliptic_curve::dev::MockCurve;
88

9+
pub use digest::dev::blobby;
10+
911
impl EcdsaCurve for MockCurve {
1012
const NORMALIZE_S: bool = false;
1113
}
@@ -148,14 +150,13 @@ macro_rules! new_wycheproof_test {
148150
($name:ident, $test_name: expr, $curve:path) => {
149151
use $crate::{
150152
Signature,
151-
elliptic_curve::{bigint::Integer, sec1::EncodedPoint},
153+
elliptic_curve::sec1::EncodedPoint,
152154
signature::Verifier,
153155
};
154156

155157
#[test]
156158
fn $name() {
157-
use blobby::Blob5Iterator;
158-
use elliptic_curve::{array::typenum::Unsigned, bigint::Encoding as _};
159+
use $crate::elliptic_curve::{self, array::typenum::Unsigned};
159160

160161
// Build a field element but allow for too-short input (left pad with zeros)
161162
// or too-long input (check excess leftmost bytes are zeros).
@@ -208,16 +209,48 @@ macro_rules! new_wycheproof_test {
208209
}
209210
}
210211

211-
let data = include_bytes!(concat!("test_vectors/data/", $test_name, ".blb"));
212+
#[derive(Debug,Clone,Copy)]
213+
struct TestVector {
214+
/// X coordinates of the public key
215+
pub wx: &'static [u8],
216+
/// Y coordinates of the public key
217+
pub wy: &'static [u8],
218+
/// Payload to verify
219+
pub msg: &'static [u8],
220+
/// Der encoding of the signature
221+
pub sig: &'static [u8],
222+
/// Whether the signature should verify (`[1]`) or fail (`[0]`)
223+
pub pass_: &'static [u8],
224+
}
212225

213-
for (i, row) in Blob5Iterator::new(data).unwrap().enumerate() {
214-
let [wx, wy, msg, sig, status] = row.unwrap();
215-
let pass = match status[0] {
216-
0 => false,
217-
1 => true,
218-
_ => panic!("invalid value for pass flag"),
219-
};
220-
if let Some(desc) = run_test(wx, wy, msg, sig, pass) {
226+
impl TestVector {
227+
pub fn pass(&self) -> bool {
228+
match self.pass_ {
229+
&[0] => false,
230+
&[1] => true,
231+
other => panic!(
232+
concat!(
233+
"Unsupported value for pass in `",
234+
$test_name,
235+
"`.\n",
236+
"found=`{other:?}`,\n",
237+
"expected=[0] or [1]"
238+
),
239+
other=other
240+
),
241+
}
242+
}
243+
}
244+
245+
$crate::dev::blobby::parse_into_structs!(
246+
include_bytes!(concat!("test_vectors/data/", $test_name, ".blb"));
247+
static TEST_VECTORS: &[
248+
TestVector { wx, wy, msg, sig, pass_ }
249+
];
250+
);
251+
252+
for (i, tv) in TEST_VECTORS.iter().enumerate() {
253+
if let Some(desc) = run_test(tv.wx, tv.wy, tv.msg, tv.sig, tv.pass()) {
221254
panic!(
222255
"\n\
223256
Failed test №{}: {}\n\
@@ -226,10 +259,21 @@ macro_rules! new_wycheproof_test {
226259
msg:\t{:?}\n\
227260
sig:\t{:?}\n\
228261
pass:\t{}\n",
229-
i, desc, wx, wy, msg, sig, pass,
262+
i, desc, tv.wx, tv.wy, tv.msg, tv.sig, tv.pass(),
230263
);
231264
}
232265
}
233266
}
234267
};
235268
}
269+
270+
#[cfg(test)]
271+
mod tests {
272+
use super::*;
273+
274+
impl crate::hazmat::DigestAlgorithm for MockCurve {
275+
type Digest = sha2::Sha256;
276+
}
277+
278+
new_wycheproof_test!(wycheproof_mock, "wycheproof-mock", MockCurve);
279+
}

ecdsa/src/hazmat.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ use crate::{EcdsaCurve, Error, Result};
1414
use core::cmp;
1515
use elliptic_curve::{FieldBytes, array::typenum::Unsigned};
1616

17-
#[cfg(feature = "arithmetic")]
17+
#[cfg(feature = "algorithm")]
1818
use {
19-
crate::{RecoveryId, SignatureSize},
19+
crate::{
20+
RecoveryId, Signature, SignatureSize,
21+
elliptic_curve::{FieldBytesEncoding, array::ArraySize},
22+
},
2023
elliptic_curve::{
2124
CurveArithmetic, NonZeroScalar, ProjectivePoint, Scalar,
2225
ff::PrimeField,
@@ -27,14 +30,8 @@ use {
2730
},
2831
};
2932

30-
#[cfg(feature = "arithmetic")]
31-
use crate::{
32-
Signature,
33-
elliptic_curve::{FieldBytesEncoding, array::ArraySize},
34-
};
35-
36-
#[cfg(any(feature = "arithmetic", feature = "digest"))]
37-
use hmac::EagerHash;
33+
#[cfg(feature = "digest")]
34+
use digest::block_api::EagerHash;
3835

3936
/// Bind a preferred [`Digest`] algorithm to an elliptic curve type.
4037
///
@@ -102,7 +99,7 @@ pub fn bits2field<C: EcdsaCurve>(bits: &[u8]) -> Result<FieldBytes<C>> {
10299
///
103100
/// This will return an error if a zero-scalar was generated. It can be tried again with a
104101
/// different `k`.
105-
#[cfg(feature = "arithmetic")]
102+
#[cfg(feature = "algorithm")]
106103
#[allow(non_snake_case)]
107104
pub fn sign_prehashed<C>(
108105
d: &NonZeroScalar<C>,
@@ -159,7 +156,7 @@ where
159156
/// entropy `ad`.
160157
///
161158
/// [RFC6979]: https://datatracker.ietf.org/doc/html/rfc6979
162-
#[cfg(feature = "arithmetic")]
159+
#[cfg(feature = "algorithm")]
163160
pub fn sign_prehashed_rfc6979<C, D>(
164161
d: &NonZeroScalar<C>,
165162
z: &FieldBytes<C>,
@@ -201,7 +198,7 @@ where
201198
/// # Low-S Normalization
202199
///
203200
/// This is a low-level function that does *NOT* apply the `EcdsaCurve::NORMALIZE_S` checks.
204-
#[cfg(feature = "arithmetic")]
201+
#[cfg(feature = "algorithm")]
205202
pub fn verify_prehashed<C>(
206203
q: &ProjectivePoint<C>,
207204
z: &FieldBytes<C>,

ecdsa/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ use elliptic_curve::{
9494
#[cfg(feature = "alloc")]
9595
use alloc::vec::Vec;
9696

97-
#[cfg(feature = "arithmetic")]
97+
#[cfg(feature = "algorithm")]
9898
use {
9999
core::str,
100100
elliptic_curve::{
@@ -301,7 +301,7 @@ where
301301
}
302302
}
303303

304-
#[cfg(feature = "arithmetic")]
304+
#[cfg(feature = "algorithm")]
305305
impl<C> Signature<C>
306306
where
307307
C: EcdsaCurve + CurveArithmetic,
@@ -424,7 +424,7 @@ where
424424
}
425425
}
426426

427-
#[cfg(feature = "arithmetic")]
427+
#[cfg(feature = "algorithm")]
428428
impl<C> str::FromStr for Signature<C>
429429
where
430430
C: EcdsaCurve + CurveArithmetic,

0 commit comments

Comments
 (0)