Skip to content

Commit

Permalink
Add testcase for Ethereum signatures.
Browse files Browse the repository at this point in the history
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
  • Loading branch information
sjaeckel committed Feb 24, 2025
1 parent a611b27 commit a69c55e
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/ecc_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,35 @@ static int s_ecc_import_export(void) {
return CRYPT_OK;
}

static int s_ecc_test_ethereum(void)
{
#ifdef LTC_ECC_SECP256K1
int stat;
const ltc_ecc_curve* dp;
ecc_key key;
unsigned char buf[1000];
unsigned long len;
unsigned char data16[16] = { 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1 };

DO(ecc_find_curve("SECP256K1", &dp));

DO(ecc_make_key_ex(&yarrow_prng, find_prng ("yarrow"), &key, dp));

/* test Ethereum signature */
len = sizeof(buf);
DO(ecc_sign_hash_eth27(data16, 16, buf, &len, &yarrow_prng, find_prng ("yarrow"), &key));
stat = 0;
DO(ecc_verify_hash_eth27(buf, len, data16, 16, &stat, &key));
if (stat != 1) return CRYPT_FAIL_TESTVECTOR;

/* cleanup */
ecc_free(&key);
return CRYPT_OK;
#else
return CRYPT_NOP;
#endif
}

#ifdef LTC_ECC_SHAMIR
static int s_ecc_test_recovery(void)
{
Expand Down Expand Up @@ -1633,6 +1662,7 @@ int ecc_test(void)
DO(s_ecc_test_shamir());
DO(s_ecc_test_recovery());
#endif
DO(s_ecc_test_ethereum());
return CRYPT_OK;
}

Expand Down

0 comments on commit a69c55e

Please sign in to comment.