1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 22:38:08 +00:00

add fingerprint output parameter to hdnode_private_ckd_cached function

This commit is contained in:
Pavol Rusnak 2016-12-12 12:06:42 +01:00
parent 6aac03d2d8
commit b55473a01e
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 13 additions and 6 deletions

View File

@ -323,12 +323,16 @@ static struct {
HDNode node;
} private_ckd_cache[BIP32_CACHE_SIZE];
int hdnode_private_ckd_cached(HDNode *inout, const uint32_t *i, size_t i_count)
int hdnode_private_ckd_cached(HDNode *inout, const uint32_t *i, size_t i_count, uint32_t *fingerprint)
{
if (i_count == 0) {
// no way how to compute parent fingerprint
return 1;
}
if (i_count == 1) {
if (fingerprint) {
*fingerprint = hdnode_fingerprint(inout);
}
if (hdnode_private_ckd(inout, i[0]) == 0) return 0;
return 1;
}
@ -372,6 +376,9 @@ int hdnode_private_ckd_cached(HDNode *inout, const uint32_t *i, size_t i_count)
private_ckd_cache_index = (private_ckd_cache_index + 1) % BIP32_CACHE_SIZE;
}
if (fingerprint) {
*fingerprint = hdnode_fingerprint(inout);
}
if (hdnode_private_ckd(inout, i[i_count - 1]) == 0) return 0;
return 1;

View File

@ -59,7 +59,7 @@ int hdnode_public_ckd_address_optimized(const curve_point *pub, const uint8_t *p
#if USE_BIP32_CACHE
int hdnode_private_ckd_cached(HDNode *inout, const uint32_t *i, size_t i_count);
int hdnode_private_ckd_cached(HDNode *inout, const uint32_t *i, size_t i_count, uint32_t *fingerprint);
#endif

View File

@ -817,7 +817,7 @@ START_TEST(test_bip32_cache_1)
for (i = 0; i < 8; i++) {
r = hdnode_private_ckd(&node1, ii[i]); ck_assert_int_eq(r, 1);
}
r = hdnode_private_ckd_cached(&node2, ii, 8); ck_assert_int_eq(r, 1);
r = hdnode_private_ckd_cached(&node2, ii, 8, NULL); ck_assert_int_eq(r, 1);
ck_assert_mem_eq(&node1, &node2, sizeof(HDNode));
hdnode_from_seed(fromhex("301133282ad079cbeb59bc446ad39d333928f74c46997d3609cd3e2801ca69d62788f9f174429946ff4e9be89f67c22fae28cb296a9b37734f75e73d1477af19"), 64, SECP256K1_NAME, &node1);
@ -828,7 +828,7 @@ START_TEST(test_bip32_cache_1)
for (i = 0; i < 8; i++) {
r = hdnode_private_ckd(&node1, ii[i]); ck_assert_int_eq(r, 1);
}
r = hdnode_private_ckd_cached(&node2, ii, 8); ck_assert_int_eq(r, 1);
r = hdnode_private_ckd_cached(&node2, ii, 8, NULL); ck_assert_int_eq(r, 1);
ck_assert_mem_eq(&node1, &node2, sizeof(HDNode));
// test different root node
@ -838,7 +838,7 @@ START_TEST(test_bip32_cache_1)
for (i = 0; i < 8; i++) {
r = hdnode_private_ckd(&node1, ii[i]); ck_assert_int_eq(r, 1);
}
r = hdnode_private_ckd_cached(&node2, ii, 8); ck_assert_int_eq(r, 1);
r = hdnode_private_ckd_cached(&node2, ii, 8, NULL); ck_assert_int_eq(r, 1);
ck_assert_mem_eq(&node1, &node2, sizeof(HDNode));
}
END_TEST
@ -860,7 +860,7 @@ START_TEST(test_bip32_cache_2)
r = hdnode_private_ckd(&(nodea[j]), ii[i - 1]); ck_assert_int_eq(r, 1);
}
// cached
r = hdnode_private_ckd_cached(&(nodeb[j]), ii, j); ck_assert_int_eq(r, 1);
r = hdnode_private_ckd_cached(&(nodeb[j]), ii, j, NULL); ck_assert_int_eq(r, 1);
}
ck_assert_mem_eq(&(nodea[0]), &(nodeb[0]), sizeof(HDNode));