mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-26 09:28:13 +00:00
add testcases for address generation
fix bug for version != 0 process uncompressed pubkeys as well
This commit is contained in:
parent
c0ee25c851
commit
7dc057c903
13
ecdsa.c
13
ecdsa.c
@ -302,7 +302,11 @@ void ecdsa_get_address(const uint8_t *pub_key, uint8_t version, char *addr)
|
|||||||
bignum256 c;
|
bignum256 c;
|
||||||
int i, l;
|
int i, l;
|
||||||
|
|
||||||
SHA256_Raw(pub_key, 33, a);
|
if (pub_key[0] == 0x04) {
|
||||||
|
SHA256_Raw(pub_key, 65, a);
|
||||||
|
} else {
|
||||||
|
SHA256_Raw(pub_key, 33, a);
|
||||||
|
}
|
||||||
b[0] = version;
|
b[0] = version;
|
||||||
ripemd160(a, 32, b + 1);
|
ripemd160(a, 32, b + 1);
|
||||||
|
|
||||||
@ -321,9 +325,10 @@ void ecdsa_get_address(const uint8_t *pub_key, uint8_t version, char *addr)
|
|||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a[0] == 0) {
|
i = 7;
|
||||||
*p = '1';
|
while (a[i] == 0) {
|
||||||
p++;
|
*p = code[0];
|
||||||
|
p++; i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
*p = 0;
|
*p = 0;
|
||||||
|
53
tests.c
53
tests.c
@ -442,6 +442,55 @@ START_TEST(test_mnemonic)
|
|||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
START_TEST(test_address)
|
||||||
|
{
|
||||||
|
char address[35];
|
||||||
|
uint8_t pub_key[65];
|
||||||
|
|
||||||
|
memcpy(pub_key, fromhex("0226659c1cf7321c178c07437150639ff0c5b7679c7ea195253ed9abda2e081a37"), 33);
|
||||||
|
ecdsa_get_address(pub_key, 0, address); ck_assert_str_eq(address, "139MaMHp3Vjo8o4x8N1ZLWEtovLGvBsg6s");
|
||||||
|
ecdsa_get_address(pub_key, 111, address); ck_assert_str_eq(address, "mhfJsQNnrXB3uuYZqvywARTDfuvyjg4RBh");
|
||||||
|
ecdsa_get_address(pub_key, 52, address); ck_assert_str_eq(address, "MxiimznnxsqMfLKTQBL8Z2PoY9jKpjgkCu");
|
||||||
|
ecdsa_get_address(pub_key, 48, address); ck_assert_str_eq(address, "LMNJqZbe89yrPbm7JVzrcXJf28hZ1rKPaH");
|
||||||
|
|
||||||
|
memcpy(pub_key, fromhex("025b1654a0e78d28810094f6c5a96b8efb8a65668b578f170ac2b1f83bc63ba856"), 33);
|
||||||
|
ecdsa_get_address(pub_key, 0, address); ck_assert_str_eq(address, "19Ywfm3witp6C1yBMy4NRYHY2347WCRBfQ");
|
||||||
|
ecdsa_get_address(pub_key, 111, address); ck_assert_str_eq(address, "mp4txp8vXvFLy8So5Y2kFTVrt2epN6YzdP");
|
||||||
|
ecdsa_get_address(pub_key, 52, address); ck_assert_str_eq(address, "N58JsQYveGueiZDgdnNwe4SSkGTAToutAY");
|
||||||
|
ecdsa_get_address(pub_key, 48, address); ck_assert_str_eq(address, "LTmtvyMmoZ49SpfLY73fhZMJEFRPdyohKh");
|
||||||
|
|
||||||
|
memcpy(pub_key, fromhex("03433f246a12e6486a51ff08802228c61cf895175a9b49ed4766ea9a9294a3c7fe"), 33);
|
||||||
|
ecdsa_get_address(pub_key, 0, address); ck_assert_str_eq(address, "1FWE2bn3MWhc4QidcF6AvEWpK77sSi2cAP");
|
||||||
|
ecdsa_get_address(pub_key, 111, address); ck_assert_str_eq(address, "mv2BKes2AY8rqXCFKp4Yk9j9B6iaMfWRLN");
|
||||||
|
ecdsa_get_address(pub_key, 52, address); ck_assert_str_eq(address, "NB5bEFH2GtoAawy8t4Qk8kfj3LWvQs3MhB");
|
||||||
|
ecdsa_get_address(pub_key, 48, address); ck_assert_str_eq(address, "LZjBHp5sSAwfKDQnnP5UCFaaXKV9YheGxQ");
|
||||||
|
|
||||||
|
memcpy(pub_key, fromhex("03aeb03abeee0f0f8b4f7a5d65ce31f9570cef9f72c2dd8a19b4085a30ab033d48"), 33);
|
||||||
|
ecdsa_get_address(pub_key, 0, address); ck_assert_str_eq(address, "1yrZb8dhdevoqpUEGi2tUccUEeiMKeLcs");
|
||||||
|
ecdsa_get_address(pub_key, 111, address); ck_assert_str_eq(address, "mgVoreDcWf6BaxJ5wqgQiPpwLEFRLSr8U8");
|
||||||
|
ecdsa_get_address(pub_key, 52, address); ck_assert_str_eq(address, "MwZDmEdcd1kVLP4yW62c6zmXCU3mNbveDo");
|
||||||
|
ecdsa_get_address(pub_key, 48, address); ck_assert_str_eq(address, "LLCopoSTnHtz4eWdQQhLAVgNgT1zTi4QBK");
|
||||||
|
|
||||||
|
memcpy(pub_key, fromhex("0496e8f2093f018aff6c2e2da5201ee528e2c8accbf9cac51563d33a7bb74a016054201c025e2a5d96b1629b95194e806c63eb96facaedc733b1a4b70ab3b33e3a"), 65);
|
||||||
|
ecdsa_get_address(pub_key, 0, address); ck_assert_str_eq(address, "194SZbL75xCCGBbKtMsyWLE5r9s2V6mhVM");
|
||||||
|
ecdsa_get_address(pub_key, 111, address); ck_assert_str_eq(address, "moaPreR5tydT3J4wbvrMLFSQi9TjPCiZc6");
|
||||||
|
ecdsa_get_address(pub_key, 52, address); ck_assert_str_eq(address, "N4domEq61LHkniqqABCYirNzaPG5NRU8GH");
|
||||||
|
ecdsa_get_address(pub_key, 48, address); ck_assert_str_eq(address, "LTHPpodwAcSFWzHV4VsGnMHr4NEJajMnKX");
|
||||||
|
|
||||||
|
memcpy(pub_key, fromhex("0498010f8a687439ff497d3074beb4519754e72c4b6220fb669224749591dde416f3961f8ece18f8689bb32235e436874d2174048b86118a00afbd5a4f33a24f0f"), 65);
|
||||||
|
ecdsa_get_address(pub_key, 0, address); ck_assert_str_eq(address, "1A2WfBD4BJFwYHFPc5KgktqtbdJLBuVKc4");
|
||||||
|
ecdsa_get_address(pub_key, 111, address); ck_assert_str_eq(address, "mpYTxEJ2zKhCKPj1KeJ4ap4DTcu39T3uzD");
|
||||||
|
ecdsa_get_address(pub_key, 52, address); ck_assert_str_eq(address, "N5bsrpi36gMW4pVtsteFyQzoKrhPE7nkxK");
|
||||||
|
ecdsa_get_address(pub_key, 48, address); ck_assert_str_eq(address, "LUFTvPWtFxVzo5wYnDJz2uueoqfcMYiuxH");
|
||||||
|
|
||||||
|
memcpy(pub_key, fromhex("04f80490839af36d13701ec3f9eebdac901b51c362119d74553a3c537faff31b17e2a59ebddbdac9e87b816307a7ed5b826b8f40b92719086238e1bebf19b77a4d"), 65);
|
||||||
|
ecdsa_get_address(pub_key, 0, address); ck_assert_str_eq(address, "19J81hrPnQxg9UGx45ibTieCkb2ttm8CLL");
|
||||||
|
ecdsa_get_address(pub_key, 111, address); ck_assert_str_eq(address, "mop5JkwNbSPvvakZmegyHdrXcadbjLazww");
|
||||||
|
ecdsa_get_address(pub_key, 52, address); ck_assert_str_eq(address, "N4sVDMMNho4Eg1XTKu3AgEo7UpRwq3aNbn");
|
||||||
|
ecdsa_get_address(pub_key, 48, address); ck_assert_str_eq(address, "LTX5GvADs5CjQGy7EDhtjjhxxoQB2Uhicd");
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
// define test suite and cases
|
// define test suite and cases
|
||||||
Suite *test_suite(void)
|
Suite *test_suite(void)
|
||||||
{
|
{
|
||||||
@ -462,6 +511,10 @@ Suite *test_suite(void)
|
|||||||
tcase_add_test(tc, test_verify_speed);
|
tcase_add_test(tc, test_verify_speed);
|
||||||
suite_add_tcase(s, tc);
|
suite_add_tcase(s, tc);
|
||||||
|
|
||||||
|
tc = tcase_create("addresses");
|
||||||
|
tcase_add_test(tc, test_address);
|
||||||
|
suite_add_tcase(s, tc);
|
||||||
|
|
||||||
tc = tcase_create("rijndael");
|
tc = tcase_create("rijndael");
|
||||||
tcase_add_test(tc, test_rijndael);
|
tcase_add_test(tc, test_rijndael);
|
||||||
suite_add_tcase(s, tc);
|
suite_add_tcase(s, tc);
|
||||||
|
Loading…
Reference in New Issue
Block a user