From 173c62f0f3159046eb141ceb1504a77e82d1d0b2 Mon Sep 17 00:00:00 2001 From: Peter Banik Date: Sun, 10 Dec 2017 00:22:41 +0100 Subject: [PATCH] Fixed test suite to use generic hasher functions --- test_openssl.c | 7 ++++--- test_speed.c | 25 +++++++++++++------------ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/test_openssl.c b/test_openssl.c index f1446ad3c..44a4fae39 100644 --- a/test_openssl.c +++ b/test_openssl.c @@ -29,6 +29,7 @@ #include "ecdsa.h" #include "rand.h" +#include "hasher.h" #include "nist256p1.h" #include "secp256k1.h" @@ -75,7 +76,7 @@ void openssl_check(unsigned int iterations, int nid, const ecdsa_curve *curve) } // use our ECDSA signer to sign the message with the key - if (ecdsa_sign(curve, priv_key, msg, msg_len, sig, NULL, NULL) != 0) { + if (ecdsa_sign(curve, HASHER_SHA2, priv_key, msg, msg_len, sig, NULL, NULL) != 0) { printf("trezor-crypto signing failed\n"); return; } @@ -85,11 +86,11 @@ void openssl_check(unsigned int iterations, int nid, const ecdsa_curve *curve) ecdsa_get_public_key65(curve, priv_key, pub_key65); // use our ECDSA verifier to verify the message signature - if (ecdsa_verify(curve, pub_key65, sig, msg, msg_len) != 0) { + if (ecdsa_verify(curve, HASHER_SHA2, pub_key65, sig, msg, msg_len) != 0) { printf("trezor-crypto verification failed (pub_key_len = 65)\n"); return; } - if (ecdsa_verify(curve, pub_key33, sig, msg, msg_len) != 0) { + if (ecdsa_verify(curve, HASHER_SHA2, pub_key33, sig, msg, msg_len) != 0) { printf("trezor-crypto verification failed (pub_key_len = 33)\n"); return; } diff --git a/test_speed.c b/test_speed.c index 24b97f2f5..1140b84c8 100644 --- a/test_speed.c +++ b/test_speed.c @@ -9,6 +9,7 @@ #include "secp256k1.h" #include "nist256p1.h" #include "ed25519.h" +#include "hasher.h" static uint8_t msg[256]; @@ -28,7 +29,7 @@ void bench_sign_secp256k1(int iterations) memcpy(priv, "\xc5\x5e\xce\x85\x8b\x0d\xdd\x52\x63\xf9\x68\x10\xfe\x14\x43\x7c\xd3\xb5\xe1\xfb\xd7\xc6\xa2\xec\x1e\x03\x1f\x05\xe8\x6d\x8b\xd5", 32); for (int i = 0 ; i < iterations; i++) { - ecdsa_sign(curve, priv, msg, sizeof(msg), sig, &pby, NULL); + ecdsa_sign(curve, HASHER_SHA2, priv, msg, sizeof(msg), sig, &pby, NULL); } } @@ -41,7 +42,7 @@ void bench_sign_nist256p1(int iterations) memcpy(priv, "\xc5\x5e\xce\x85\x8b\x0d\xdd\x52\x63\xf9\x68\x10\xfe\x14\x43\x7c\xd3\xb5\xe1\xfb\xd7\xc6\xa2\xec\x1e\x03\x1f\x05\xe8\x6d\x8b\xd5", 32); for (int i = 0 ; i < iterations; i++) { - ecdsa_sign(curve, priv, msg, sizeof(msg), sig, &pby, NULL); + ecdsa_sign(curve, HASHER_SHA2, priv, msg, sizeof(msg), sig, &pby, NULL); } } @@ -67,10 +68,10 @@ void bench_verify_secp256k1_33(int iterations) memcpy(priv, "\xc5\x5e\xce\x85\x8b\x0d\xdd\x52\x63\xf9\x68\x10\xfe\x14\x43\x7c\xd3\xb5\xe1\xfb\xd7\xc6\xa2\xec\x1e\x03\x1f\x05\xe8\x6d\x8b\xd5", 32); ecdsa_get_public_key33(curve, priv, pub); - ecdsa_sign(curve, priv, msg, sizeof(msg), sig, &pby, NULL); + ecdsa_sign(curve, HASHER_SHA2, priv, msg, sizeof(msg), sig, &pby, NULL); for (int i = 0 ; i < iterations; i++) { - ecdsa_verify(curve, pub, sig, msg, sizeof(msg)); + ecdsa_verify(curve, HASHER_SHA2, pub, sig, msg, sizeof(msg)); } } @@ -82,10 +83,10 @@ void bench_verify_secp256k1_65(int iterations) memcpy(priv, "\xc5\x5e\xce\x85\x8b\x0d\xdd\x52\x63\xf9\x68\x10\xfe\x14\x43\x7c\xd3\xb5\xe1\xfb\xd7\xc6\xa2\xec\x1e\x03\x1f\x05\xe8\x6d\x8b\xd5", 32); ecdsa_get_public_key65(curve, priv, pub); - ecdsa_sign(curve, priv, msg, sizeof(msg), sig, &pby, NULL); + ecdsa_sign(curve, HASHER_SHA2, priv, msg, sizeof(msg), sig, &pby, NULL); for (int i = 0 ; i < iterations; i++) { - ecdsa_verify(curve, pub, sig, msg, sizeof(msg)); + ecdsa_verify(curve, HASHER_SHA2, pub, sig, msg, sizeof(msg)); } } @@ -97,10 +98,10 @@ void bench_verify_nist256p1_33(int iterations) memcpy(priv, "\xc5\x5e\xce\x85\x8b\x0d\xdd\x52\x63\xf9\x68\x10\xfe\x14\x43\x7c\xd3\xb5\xe1\xfb\xd7\xc6\xa2\xec\x1e\x03\x1f\x05\xe8\x6d\x8b\xd5", 32); ecdsa_get_public_key33(curve, priv, pub); - ecdsa_sign(curve, priv, msg, sizeof(msg), sig, &pby, NULL); + ecdsa_sign(curve, HASHER_SHA2, priv, msg, sizeof(msg), sig, &pby, NULL); for (int i = 0 ; i < iterations; i++) { - ecdsa_verify(curve, pub, sig, msg, sizeof(msg)); + ecdsa_verify(curve, HASHER_SHA2, pub, sig, msg, sizeof(msg)); } } @@ -112,10 +113,10 @@ void bench_verify_nist256p1_65(int iterations) memcpy(priv, "\xc5\x5e\xce\x85\x8b\x0d\xdd\x52\x63\xf9\x68\x10\xfe\x14\x43\x7c\xd3\xb5\xe1\xfb\xd7\xc6\xa2\xec\x1e\x03\x1f\x05\xe8\x6d\x8b\xd5", 32); ecdsa_get_public_key65(curve, priv, pub); - ecdsa_sign(curve, priv, msg, sizeof(msg), sig, &pby, NULL); + ecdsa_sign(curve, HASHER_SHA2, priv, msg, sizeof(msg), sig, &pby, NULL); for (int i = 0 ; i < iterations; i++) { - ecdsa_verify(curve, pub, sig, msg, sizeof(msg)); + ecdsa_verify(curve, HASHER_SHA2, pub, sig, msg, sizeof(msg)); } } @@ -164,7 +165,7 @@ void bench_ckd_normal(int iterations) memcpy(&node, &root, sizeof(HDNode)); hdnode_public_ckd(&node, i); hdnode_fill_public_key(&node); - ecdsa_get_address(node.public_key, 0, addr, sizeof(addr)); + ecdsa_get_address(node.public_key, HASHER_SHA2, 0, addr, sizeof(addr)); } } @@ -174,7 +175,7 @@ void bench_ckd_optimized(int iterations) curve_point pub; ecdsa_read_pubkey(&secp256k1, root.public_key, &pub); for (int i = 0; i < iterations; i++) { - hdnode_public_ckd_address_optimized(&pub, root.chain_code, i, 0, addr, sizeof(addr), false); + hdnode_public_ckd_address_optimized(&pub, root.chain_code, i, 0, HASHER_SHA2, addr, sizeof(addr), false); } }