Skip to content

Commit 15e58d2

Browse files
committed
Use blobby re-export from ecdsa, bump blobby to 0.4
Fixes #1483
1 parent 73e250d commit 15e58d2

File tree

15 files changed

+70
-52
lines changed

15 files changed

+70
-52
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ ed448-goldilocks = { path = "ed448-goldilocks" }
2626
hash2curve = { path = "hash2curve" }
2727
primefield = { path = "primefield" }
2828
primeorder = { path = "primeorder" }
29+
30+
ecdsa = { git = "https://github.com/baloo/signatures.git", branch = "baloo/ecdsa/re-export-blobby" }
31+
rfc6979 = { git = "https://github.com/RustCrypto/signatures.git" }

k256/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ sha2 = { version = "0.11.0-rc.2", optional = true, default-features = false }
3232
signature = { version = "3.0.0-rc.4", optional = true }
3333

3434
[dev-dependencies]
35-
blobby = "0.3"
3635
criterion = "0.7"
3736
ecdsa-core = { version = "0.17.0-rc.7", package = "ecdsa", default-features = false, features = ["dev"] }
3837
hex = "0.4.3"
@@ -53,7 +52,7 @@ bits = ["arithmetic", "elliptic-curve/bits"]
5352
critical-section = ["elliptic-curve/critical-section", "precomputed-tables"]
5453
digest = ["ecdsa-core/digest", "ecdsa-core/hazmat"]
5554
ecdh = ["arithmetic", "elliptic-curve/ecdh"]
56-
ecdsa = ["arithmetic", "ecdsa-core/signing", "ecdsa-core/verifying", "sha256"]
55+
ecdsa = ["arithmetic", "ecdsa-core/algorithm", "sha256"]
5756
expose-field = ["arithmetic"]
5857
hash2curve = ["arithmetic", "dep:hash2curve", "dep:primeorder", "primeorder/hash2curve"]
5958
group-digest = ["hash2curve", "sha2"]

k256/src/ecdsa.rs

Lines changed: 56 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,6 @@ mod tests {
274274

275275
#[test]
276276
fn wycheproof() {
277-
use blobby::Blob5Iterator;
278-
279277
// Build a field element but allow for too-short input (left pad with zeros)
280278
// or too-long input (check excess leftmost bytes are zeros).
281279
fn element_from_padded_slice<C: elliptic_curve::Curve>(
@@ -334,38 +332,66 @@ mod tests {
334332
}
335333
}
336334

337-
fn run(data: &[u8], p1363_sig: bool) {
338-
for (i, row) in Blob5Iterator::new(data).unwrap().enumerate() {
339-
let [wx, wy, msg, sig, status] = row.unwrap();
340-
let pass = match status[0] {
341-
0 => false,
342-
1 => true,
343-
_ => panic!("invalid value for pass flag"),
344-
};
345-
if let Some(desc) = run_test(wx, wy, msg, sig, pass, p1363_sig) {
346-
panic!(
347-
"\n\
348-
Failed test №{}: {}\n\
349-
wx:\t{:?}\n\
350-
wy:\t{:?}\n\
351-
msg:\t{:?}\n\
352-
sig:\t{:?}\n\
353-
pass:\t{}\n",
354-
i,
355-
desc,
356-
hex::encode(wx),
357-
hex::encode(wy),
358-
hex::encode(msg),
359-
hex::encode(sig),
360-
pass,
335+
#[derive(Debug, Clone, Copy)]
336+
struct TestVector {
337+
/// X coordinates of the public key
338+
pub wx: &'static [u8],
339+
/// Y coordinates of the public key
340+
pub wy: &'static [u8],
341+
/// Payload to verify
342+
pub msg: &'static [u8],
343+
/// Der encoding of the signature
344+
pub sig: &'static [u8],
345+
/// Whether the signature should verify (`[1]`) or fail (`[0]`)
346+
pub pass_: &'static [u8],
347+
}
348+
349+
impl TestVector {
350+
pub fn pass(&self) -> bool {
351+
self.pass_[0] == 1
352+
}
353+
}
354+
355+
macro_rules! run_test {
356+
($blob: expr, $p1363_sig: expr) => {
357+
{
358+
ecdsa_core::dev::blobby::parse_into_structs!(
359+
include_bytes!($blob);
360+
static TEST_VECTORS: &[
361+
TestVector { wx, wy, msg, sig, pass_ }
362+
];
361363
);
364+
365+
366+
for (i, tv) in TEST_VECTORS.iter().enumerate() {
367+
if let Some(desc) = run_test(tv.wx, tv.wy, tv.msg, tv.sig, tv.pass(), $p1363_sig) {
368+
panic!(
369+
"\n\
370+
Failed test №{}: {}\n\
371+
wx:\t{:?}\n\
372+
wy:\t{:?}\n\
373+
msg:\t{:?}\n\
374+
sig:\t{:?}\n\
375+
pass:\t{}\n",
376+
i,
377+
desc,
378+
hex::encode(tv.wx),
379+
hex::encode(tv.wy),
380+
hex::encode(tv.msg),
381+
hex::encode(tv.sig),
382+
tv.pass(),
383+
);
384+
}
385+
}
362386
}
363387
}
364388
}
365-
let data = include_bytes!(concat!("test_vectors/data/", "wycheproof", ".blb"));
366-
run(data, false);
367-
let data2 = include_bytes!(concat!("test_vectors/data/", "wycheproof-p1316", ".blb"));
368-
run(data2, true);
389+
390+
run_test!(concat!("test_vectors/data/", "wycheproof", ".blb"), false);
391+
run_test!(
392+
concat!("test_vectors/data/", "wycheproof-p1316", ".blb"),
393+
true
394+
);
369395
}
370396
}
371397
}
2 Bytes
Binary file not shown.
2 Bytes
Binary file not shown.

p192/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ std = ["alloc", "elliptic-curve/std"]
3939
arithmetic = ["dep:primefield", "dep:primeorder", "elliptic-curve/arithmetic"]
4040
bits = ["arithmetic", "elliptic-curve/bits"]
4141
digest = ["ecdsa-core/digest", "ecdsa-core/hazmat"]
42-
ecdsa = ["arithmetic", "ecdsa-core/signing", "ecdsa-core/verifying"]
42+
ecdsa = ["arithmetic", "ecdsa-core/algorithm"]
4343
pem = ["elliptic-curve/pem", "pkcs8"]
4444
pkcs8 = ["elliptic-curve/pkcs8"]
4545
serde = ["elliptic-curve/serde", "primeorder?/serde", "serdect"]

p224/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ serdect = { version = "0.4", optional = true, default-features = false }
2828
sha2 = { version = "0.11.0-rc.2", optional = true, default-features = false }
2929

3030
[dev-dependencies]
31-
blobby = "0.3"
3231
ecdsa-core = { version = "0.17.0-rc.7", package = "ecdsa", default-features = false, features = ["dev"] }
3332
hex-literal = "1"
3433
primeorder = { version = "=0.14.0-pre.9", features = ["dev"] }
@@ -43,7 +42,7 @@ arithmetic = ["dep:primefield", "dep:primeorder", "elliptic-curve/arithmetic"]
4342
bits = ["arithmetic", "elliptic-curve/bits"]
4443
digest = ["ecdsa-core/digest", "ecdsa-core/hazmat"]
4544
ecdh = ["arithmetic", "elliptic-curve/ecdh"]
46-
ecdsa = ["arithmetic", "ecdsa-core/signing", "ecdsa-core/verifying", "sha224"]
45+
ecdsa = ["arithmetic", "ecdsa-core/algorithm", "sha224"]
4746
pem = ["elliptic-curve/pem", "pkcs8"]
4847
pkcs8 = ["ecdsa-core?/pkcs8", "elliptic-curve/pkcs8"]
4948
serde = ["ecdsa-core?/serde", "elliptic-curve/serde", "primeorder?/serde", "serdect"]
2 Bytes
Binary file not shown.

p256/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ serdect = { version = "0.4", optional = true, default-features = false }
3030
sha2 = { version = "0.11.0-rc.2", optional = true, default-features = false }
3131

3232
[dev-dependencies]
33-
blobby = "0.3"
3433
criterion = "0.7"
3534
ecdsa-core = { version = "0.17.0-rc.7", package = "ecdsa", default-features = false, features = ["dev"] }
3635
hex-literal = "1"
@@ -48,7 +47,7 @@ arithmetic = ["dep:primefield", "dep:primeorder", "elliptic-curve/arithmetic"]
4847
bits = ["arithmetic", "elliptic-curve/bits"]
4948
digest = ["ecdsa-core/digest", "ecdsa-core/hazmat"]
5049
ecdh = ["arithmetic", "elliptic-curve/ecdh"]
51-
ecdsa = ["arithmetic", "ecdsa-core/signing", "ecdsa-core/verifying", "sha256"]
50+
ecdsa = ["arithmetic", "ecdsa-core/algorithm", "sha256"]
5251
expose-field = ["arithmetic"]
5352
hash2curve = ["arithmetic", "dep:hash2curve", "primeorder/hash2curve"]
5453
group-digest = ["hash2curve", "sha2"]

0 commit comments

Comments
 (0)