Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion ecdsa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ alloc = ["elliptic-curve/alloc", "signature/alloc", "spki/alloc"]
std = ["alloc", "elliptic-curve/std"]

algorithm = ["dep:rfc6979", "digest", "elliptic-curve/arithmetic", "hazmat"]
dev = ["algorithm", "elliptic-curve/dev"]
dev = ["algorithm", "digest/dev", "elliptic-curve/dev"]
der = ["dep:der"]
digest = ["dep:digest", "elliptic-curve/digest", "signature/digest"]
hazmat = []
Expand Down
70 changes: 57 additions & 13 deletions ecdsa/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use crate::EcdsaCurve;
use elliptic_curve::dev::MockCurve;

pub use digest::dev::blobby;

impl EcdsaCurve for MockCurve {
const NORMALIZE_S: bool = false;
}
Expand Down Expand Up @@ -148,14 +150,13 @@ macro_rules! new_wycheproof_test {
($name:ident, $test_name: expr, $curve:path) => {
use $crate::{
Signature,
elliptic_curve::{bigint::Integer, sec1::EncodedPoint},
elliptic_curve::{sec1::EncodedPoint},
signature::Verifier,
};

#[test]
fn $name() {
use blobby::Blob5Iterator;
use elliptic_curve::{array::typenum::Unsigned, bigint::Encoding as _};
use $crate::elliptic_curve::{self, array::typenum::Unsigned};

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

let data = include_bytes!(concat!("test_vectors/data/", $test_name, ".blb"));
#[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],
}

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) {
impl TestVector {
pub fn pass(&self) -> bool {
match self.pass_ {
&[0] => false,
&[1] => true,
other => panic!(
concat!(
"Unsupported value for pass in `",
$test_name,
"`.\n",
"found=`{other:?}`,\n",
"expected=[0] or [1]"
),
other=other
),
}
}
}

$crate::dev::blobby::parse_into_structs!(
include_bytes!(concat!("test_vectors/data/", $test_name, ".blb"));
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()) {
panic!(
"\n\
Failed test №{}: {}\n\
Expand All @@ -226,10 +259,21 @@ macro_rules! new_wycheproof_test {
msg:\t{:?}\n\
sig:\t{:?}\n\
pass:\t{}\n",
i, desc, wx, wy, msg, sig, pass,
i, desc, tv.wx, tv.wy, tv.msg, tv.sig, tv.pass(),
);
}
}
}
};
}

#[cfg(test)]
mod tests {
use super::*;

impl crate::hazmat::DigestAlgorithm for MockCurve {
type Digest = sha2::Sha256;
}

new_wycheproof_test!(wycheproof_mock, "wycheproof-mock", MockCurve);
}
Binary file added ecdsa/src/test_vectors/data/wycheproof-mock.blb
Binary file not shown.