Skip to content

Commit

Permalink
Deduplicate test case processing
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Feb 5, 2024
1 parent 6f5ecb4 commit 0e9624a
Showing 1 changed file with 12 additions and 28 deletions.
40 changes: 12 additions & 28 deletions packages/crypto/tests/wycheproof_secp256k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ fn ecdsa_secp256k1_sha256() {
tested += 1;
assert_eq!(tc.tc_id as usize, tested);
// eprintln!("Test case ID: {}", tc.tc_id);
let message = hex::decode(tc.msg).unwrap();
let message_hash = hashers::sha256(&message);
let der_signature = hex::decode(tc.sig).unwrap();

match tc.result.as_str() {
"valid" | "acceptable" => {
let message = hex::decode(tc.msg).unwrap();
let message_hash = hashers::sha256(&message);
let der_signature = hex::decode(tc.sig).unwrap();
let signature = from_der(&der_signature).unwrap();
let valid = secp256k1_verify(&message_hash, &signature, &public_key).unwrap();
assert!(valid);
Expand All @@ -107,10 +107,6 @@ fn ecdsa_secp256k1_sha256() {
}
}
"invalid" => {
let message = hex::decode(tc.msg).unwrap();
let message_hash = hashers::sha256(&message);
let der_signature = hex::decode(tc.sig).unwrap();

if let Ok(signature) = from_der(&der_signature) {
match secp256k1_verify(&message_hash, &signature, &public_key) {
Ok(valid) => assert!(!valid),
Expand Down Expand Up @@ -145,12 +141,12 @@ fn ecdsa_secp256k1_sha512() {
tested += 1;
assert_eq!(tc.tc_id as usize, tested);
// eprintln!("Test case ID: {}", tc.tc_id);
let message = hex::decode(tc.msg).unwrap();
let message_hash = hashers::sha512(&message);
let der_signature = hex::decode(tc.sig).unwrap();

match tc.result.as_str() {
"valid" | "acceptable" => {
let message = hex::decode(tc.msg).unwrap();
let message_hash = hashers::sha512(&message);
let der_signature = hex::decode(tc.sig).unwrap();
let signature = from_der(&der_signature).unwrap();
let valid = secp256k1_verify(&message_hash, &signature, &public_key).unwrap();
assert!(valid);
Expand All @@ -159,10 +155,6 @@ fn ecdsa_secp256k1_sha512() {
}
}
"invalid" => {
let message = hex::decode(tc.msg).unwrap();
let message_hash = hashers::sha512(&message);
let der_signature = hex::decode(tc.sig).unwrap();

if let Ok(signature) = from_der(&der_signature) {
match secp256k1_verify(&message_hash, &signature, &public_key) {
Ok(valid) => assert!(!valid),
Expand Down Expand Up @@ -197,12 +189,12 @@ fn ecdsa_secp256k1_sha3_256() {
tested += 1;
assert_eq!(tc.tc_id as usize, tested);
// eprintln!("Test case ID: {}", tc.tc_id);
let message = hex::decode(tc.msg).unwrap();
let message_hash = hashers::sha3_256(&message);
let der_signature = hex::decode(tc.sig).unwrap();

match tc.result.as_str() {
"valid" | "acceptable" => {
let message = hex::decode(tc.msg).unwrap();
let message_hash = hashers::sha3_256(&message);
let der_signature = hex::decode(tc.sig).unwrap();
let signature = from_der(&der_signature).unwrap();
let valid = secp256k1_verify(&message_hash, &signature, &public_key).unwrap();
assert!(valid);
Expand All @@ -211,10 +203,6 @@ fn ecdsa_secp256k1_sha3_256() {
}
}
"invalid" => {
let message = hex::decode(tc.msg).unwrap();
let message_hash = hashers::sha3_256(&message);
let der_signature = hex::decode(tc.sig).unwrap();

if let Ok(signature) = from_der(&der_signature) {
match secp256k1_verify(&message_hash, &signature, &public_key) {
Ok(valid) => assert!(!valid),
Expand Down Expand Up @@ -249,12 +237,12 @@ fn ecdsa_secp256k1_sha3_512() {
tested += 1;
assert_eq!(tc.tc_id as usize, tested);
// eprintln!("Test case ID: {}", tc.tc_id);
let message = hex::decode(tc.msg).unwrap();
let message_hash = hashers::sha3_512(&message);
let der_signature = hex::decode(tc.sig).unwrap();

match tc.result.as_str() {
"valid" | "acceptable" => {
let message = hex::decode(tc.msg).unwrap();
let message_hash = hashers::sha3_512(&message);
let der_signature = hex::decode(tc.sig).unwrap();
let signature = from_der(&der_signature).unwrap();
let valid = secp256k1_verify(&message_hash, &signature, &public_key).unwrap();
assert!(valid);
Expand All @@ -263,10 +251,6 @@ fn ecdsa_secp256k1_sha3_512() {
}
}
"invalid" => {
let message = hex::decode(tc.msg).unwrap();
let message_hash = hashers::sha3_512(&message);
let der_signature = hex::decode(tc.sig).unwrap();

if let Ok(signature) = from_der(&der_signature) {
match secp256k1_verify(&message_hash, &signature, &public_key) {
Ok(valid) => assert!(!valid),
Expand Down

0 comments on commit 0e9624a

Please sign in to comment.