From 3cd2e89fbc8cc68f3aadb5c79afe2c73da394f44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Vejpustek?= Date: Wed, 16 Jun 2021 14:19:57 +0200 Subject: [PATCH] refactor(crypto): split test_ecdsa_signature into two tests --- crypto/tests/test_check.c | 56 ++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/crypto/tests/test_check.c b/crypto/tests/test_check.c index 47c8d069d2..ea8e5651fc 100644 --- a/crypto/tests/test_check.c +++ b/crypto/tests/test_check.c @@ -3426,34 +3426,12 @@ START_TEST(test_bip32_decred_vector_2) { } END_TEST -START_TEST(test_ecdsa_signature) { +START_TEST(test_ecdsa_sign_digest) { int res; uint8_t digest[32]; uint8_t pubkey[65]; - uint8_t sig[64]; const ecdsa_curve *curve = &secp256k1; - // Signature verification for a digest which is equal to the group order. - // https://github.com/trezor/trezor-firmware/pull/1374 - memcpy( - pubkey, - fromhex( - "0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f8179848" - "3ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"), - sizeof(pubkey)); - memcpy( - digest, - fromhex( - "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"), - sizeof(digest)); - memcpy(sig, - fromhex( - "a0b37f8fba683cc68f6574cd43b39f0343a50008bf6ccea9d13231d9e7e2e1e41" - "1edc8d307254296264aebfc3dc76cd8b668373a072fd64665b50000e9fcce52"), - sizeof(sig)); - res = ecdsa_verify_digest(curve, pubkey, sig, digest); - ck_assert_int_eq(res, 0); - // sha2(sha2("\x18Bitcoin Signed Message:\n\x0cHello World!")) memcpy( digest, @@ -3637,6 +3615,35 @@ START_TEST(test_ecdsa_signature) { } END_TEST +START_TEST(test_ecdsa_recover_pub_from_sig) { + int res; + uint8_t digest[32]; + uint8_t pubkey[65]; + uint8_t sig[64]; + const ecdsa_curve *curve = &secp256k1; + + // Signature verification for a digest which is equal to the group order. + // https://github.com/trezor/trezor-firmware/pull/1374 + memcpy( + pubkey, + fromhex( + "0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f8179848" + "3ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"), + sizeof(pubkey)); + memcpy( + digest, + fromhex( + "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"), + sizeof(digest)); + memcpy(sig, + fromhex( + "a0b37f8fba683cc68f6574cd43b39f0343a50008bf6ccea9d13231d9e7e2e1e41" + "1edc8d307254296264aebfc3dc76cd8b668373a072fd64665b50000e9fcce52"), + sizeof(sig)); + res = ecdsa_verify_digest(curve, pubkey, sig, digest); + ck_assert_int_eq(res, 0); +} + #define test_deterministic(KEY, MSG, K) \ do { \ sha256_Raw((uint8_t *)MSG, strlen(MSG), buf); \ @@ -9157,7 +9164,8 @@ Suite *test_suite(void) { suite_add_tcase(s, tc); tc = tcase_create("ecdsa"); - tcase_add_test(tc, test_ecdsa_signature); + tcase_add_test(tc, test_ecdsa_recover_pub_from_sig); + tcase_add_test(tc, test_ecdsa_sign_digest); suite_add_tcase(s, tc); tc = tcase_create("rfc6979");