66use crate :: EcdsaCurve ;
77use elliptic_curve:: dev:: MockCurve ;
88
9+ pub use digest:: dev:: blobby;
10+
911impl 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+ }
0 commit comments