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
16 changes: 5 additions & 11 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 @@ -26,3 +26,6 @@ ed448-goldilocks = { path = "ed448-goldilocks" }
hash2curve = { path = "hash2curve" }
primefield = { path = "primefield" }
primeorder = { path = "primeorder" }

ecdsa = { git = "https://github.com/RustCrypto/signatures.git" }
rfc6979 = { git = "https://github.com/RustCrypto/signatures.git" }
3 changes: 1 addition & 2 deletions k256/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ sha2 = { version = "0.11.0-rc.2", optional = true, default-features = false }
signature = { version = "3.0.0-rc.4", optional = true }

[dev-dependencies]
blobby = "0.3"
criterion = "0.7"
ecdsa-core = { version = "0.17.0-rc.7", package = "ecdsa", default-features = false, features = ["dev"] }
hex = "0.4.3"
Expand All @@ -53,7 +52,7 @@ bits = ["arithmetic", "elliptic-curve/bits"]
critical-section = ["elliptic-curve/critical-section", "precomputed-tables"]
digest = ["ecdsa-core/digest", "ecdsa-core/hazmat"]
ecdh = ["arithmetic", "elliptic-curve/ecdh"]
ecdsa = ["arithmetic", "ecdsa-core/signing", "ecdsa-core/verifying", "sha256"]
ecdsa = ["arithmetic", "ecdsa-core/algorithm", "sha256"]
expose-field = ["arithmetic"]
hash2curve = ["arithmetic", "dep:hash2curve", "dep:primeorder", "primeorder/hash2curve"]
group-digest = ["hash2curve", "sha2"]
Expand Down
86 changes: 56 additions & 30 deletions k256/src/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,6 @@ mod tests {

#[test]
fn wycheproof() {
use blobby::Blob5Iterator;

// Build a field element but allow for too-short input (left pad with zeros)
// or too-long input (check excess leftmost bytes are zeros).
fn element_from_padded_slice<C: elliptic_curve::Curve>(
Expand Down Expand Up @@ -334,38 +332,66 @@ mod tests {
}
}

fn run(data: &[u8], p1363_sig: bool) {
for (i, row) in Blob5Iterator::new(data).unwrap().enumerate() {
let [wx, wy, msg, sig, status] = row.unwrap();
let pass = match status[0] {
0 => false,
1 => true,
_ => panic!("invalid value for pass flag"),
};
if let Some(desc) = run_test(wx, wy, msg, sig, pass, p1363_sig) {
panic!(
"\n\
Failed test №{}: {}\n\
wx:\t{:?}\n\
wy:\t{:?}\n\
msg:\t{:?}\n\
sig:\t{:?}\n\
pass:\t{}\n",
i,
desc,
hex::encode(wx),
hex::encode(wy),
hex::encode(msg),
hex::encode(sig),
pass,
#[derive(Debug, Clone, Copy)]
struct TestVector {
/// X coordinates of the public key
pub wx: &'static [u8],
/// Y coordinates of the public key
pub wy: &'static [u8],
/// Payload to verify
pub msg: &'static [u8],
/// Der encoding of the signature
pub sig: &'static [u8],
/// Whether the signature should verify (`[1]`) or fail (`[0]`)
pub pass_: &'static [u8],
}

impl TestVector {
pub fn pass(&self) -> bool {
self.pass_[0] == 1
}
}

macro_rules! run_test {
($blob: expr, $p1363_sig: expr) => {
{
ecdsa_core::dev::blobby::parse_into_structs!(
include_bytes!($blob);
static TEST_VECTORS: &[
TestVector { wx, wy, msg, sig, pass_ }
];
);


for (i, tv) in TEST_VECTORS.iter().enumerate() {
if let Some(desc) = run_test(tv.wx, tv.wy, tv.msg, tv.sig, tv.pass(), $p1363_sig) {
panic!(
"\n\
Failed test №{}: {}\n\
wx:\t{:?}\n\
wy:\t{:?}\n\
msg:\t{:?}\n\
sig:\t{:?}\n\
pass:\t{}\n",
i,
desc,
hex::encode(tv.wx),
hex::encode(tv.wy),
hex::encode(tv.msg),
hex::encode(tv.sig),
tv.pass(),
);
}
}
}
}
}
let data = include_bytes!(concat!("test_vectors/data/", "wycheproof", ".blb"));
run(data, false);
let data2 = include_bytes!(concat!("test_vectors/data/", "wycheproof-p1316", ".blb"));
run(data2, true);

run_test!(concat!("test_vectors/data/", "wycheproof", ".blb"), false);
run_test!(
concat!("test_vectors/data/", "wycheproof-p1316", ".blb"),
true
);
}
}
}
Binary file modified k256/src/test_vectors/data/wycheproof-p1316.blb
Binary file not shown.
Binary file modified k256/src/test_vectors/data/wycheproof.blb
Binary file not shown.
2 changes: 1 addition & 1 deletion p192/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ std = ["alloc", "elliptic-curve/std"]
arithmetic = ["dep:primefield", "dep:primeorder", "elliptic-curve/arithmetic"]
bits = ["arithmetic", "elliptic-curve/bits"]
digest = ["ecdsa-core/digest", "ecdsa-core/hazmat"]
ecdsa = ["arithmetic", "ecdsa-core/signing", "ecdsa-core/verifying"]
ecdsa = ["arithmetic", "ecdsa-core/algorithm"]
pem = ["elliptic-curve/pem", "pkcs8"]
pkcs8 = ["elliptic-curve/pkcs8"]
serde = ["elliptic-curve/serde", "primeorder?/serde", "serdect"]
Expand Down
3 changes: 1 addition & 2 deletions p224/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ serdect = { version = "0.4", optional = true, default-features = false }
sha2 = { version = "0.11.0-rc.2", optional = true, default-features = false }

[dev-dependencies]
blobby = "0.3"
ecdsa-core = { version = "0.17.0-rc.7", package = "ecdsa", default-features = false, features = ["dev"] }
hex-literal = "1"
primeorder = { version = "=0.14.0-pre.9", features = ["dev"] }
Expand All @@ -43,7 +42,7 @@ arithmetic = ["dep:primefield", "dep:primeorder", "elliptic-curve/arithmetic"]
bits = ["arithmetic", "elliptic-curve/bits"]
digest = ["ecdsa-core/digest", "ecdsa-core/hazmat"]
ecdh = ["arithmetic", "elliptic-curve/ecdh"]
ecdsa = ["arithmetic", "ecdsa-core/signing", "ecdsa-core/verifying", "sha224"]
ecdsa = ["arithmetic", "ecdsa-core/algorithm", "sha224"]
pem = ["elliptic-curve/pem", "pkcs8"]
pkcs8 = ["ecdsa-core?/pkcs8", "elliptic-curve/pkcs8"]
serde = ["ecdsa-core?/serde", "elliptic-curve/serde", "primeorder?/serde", "serdect"]
Expand Down
Binary file modified p224/src/test_vectors/data/wycheproof.blb
Binary file not shown.
3 changes: 1 addition & 2 deletions p256/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ serdect = { version = "0.4", optional = true, default-features = false }
sha2 = { version = "0.11.0-rc.2", optional = true, default-features = false }

[dev-dependencies]
blobby = "0.3"
criterion = "0.7"
ecdsa-core = { version = "0.17.0-rc.7", package = "ecdsa", default-features = false, features = ["dev"] }
hex-literal = "1"
Expand All @@ -48,7 +47,7 @@ arithmetic = ["dep:primefield", "dep:primeorder", "elliptic-curve/arithmetic"]
bits = ["arithmetic", "elliptic-curve/bits"]
digest = ["ecdsa-core/digest", "ecdsa-core/hazmat"]
ecdh = ["arithmetic", "elliptic-curve/ecdh"]
ecdsa = ["arithmetic", "ecdsa-core/signing", "ecdsa-core/verifying", "sha256"]
ecdsa = ["arithmetic", "ecdsa-core/algorithm", "sha256"]
expose-field = ["arithmetic"]
hash2curve = ["arithmetic", "dep:hash2curve", "primeorder/hash2curve"]
group-digest = ["hash2curve", "sha2"]
Expand Down
Binary file modified p256/src/test_vectors/data/wycheproof.blb
Binary file not shown.
3 changes: 1 addition & 2 deletions p384/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ serdect = { version = "0.4", optional = true, default-features = false }
sha2 = { version = "0.11.0-rc.2", optional = true, default-features = false }

[dev-dependencies]
blobby = "0.3"
criterion = "0.7"
ecdsa-core = { version = "0.17.0-rc.7", package = "ecdsa", default-features = false, features = ["dev"] }
hex-literal = "1"
Expand All @@ -53,7 +52,7 @@ arithmetic = [
bits = ["arithmetic", "elliptic-curve/bits"]
digest = ["ecdsa-core/digest", "ecdsa-core/hazmat"]
ecdh = ["arithmetic", "elliptic-curve/ecdh"]
ecdsa = ["arithmetic", "ecdsa-core/signing", "ecdsa-core/verifying", "sha384"]
ecdsa = ["arithmetic", "ecdsa-core/algorithm", "sha384"]
expose-field = ["arithmetic"]
hash2curve = ["arithmetic", "dep:hash2curve", "primeorder/hash2curve"]
group-digest = ["hash2curve", "sha2"]
Expand Down
Binary file modified p384/src/test_vectors/data/wycheproof.blb
Binary file not shown.
3 changes: 1 addition & 2 deletions p521/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ serdect = { version = "0.4", optional = true, default-features = false }
sha2 = { version = "0.11.0-rc.2", optional = true, default-features = false }

[dev-dependencies]
blobby = "0.3"
criterion = "0.7"
ecdsa-core = { version = "0.17.0-rc.7", package = "ecdsa", default-features = false, features = ["dev"] }
hex-literal = "1"
Expand All @@ -47,7 +46,7 @@ std = ["alloc", "ecdsa-core?/std", "elliptic-curve/std"]
arithmetic = ["dep:primefield", "dep:primeorder"]
digest = ["ecdsa-core/digest", "ecdsa-core/hazmat"]
ecdh = ["arithmetic", "elliptic-curve/ecdh"]
ecdsa = ["arithmetic", "ecdsa-core/signing", "ecdsa-core/verifying", "sha512"]
ecdsa = ["arithmetic", "ecdsa-core/algorithm", "sha512"]
expose-field = ["arithmetic"]
getrandom = ["rand_core/os_rng"]
hash2curve = ["arithmetic", "dep:hash2curve", "primeorder/hash2curve"]
Expand Down
Binary file modified p521/src/test_vectors/data/wycheproof.blb
Binary file not shown.