1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-12 18:49:07 +00:00

extract xprv_fill_public method

This commit is contained in:
Pavol Rusnak 2013-11-08 16:02:48 +01:00
parent b14ce58df7
commit 9da3b35962
4 changed files with 13 additions and 6 deletions

13
bip32.c
View File

@ -14,8 +14,7 @@ void xprv_from_seed(uint8_t *seed, int seed_len, XprvNode *out)
// this can be done because private_key[32] and chain_code[32]
// form a continuous 64 byte block in the memory
hmac_sha512((uint8_t *)"Bitcoin seed", 12, seed, seed_len, out->private_key);
ecdsa_get_public_key33(out->private_key, out->public_key);
ecdsa_get_address(out->public_key, 0, out->address);
xprv_fill_public(out);
}
void xprv_descent(XprvNode *inout, uint32_t i)
@ -44,6 +43,12 @@ void xprv_descent(XprvNode *inout, uint32_t i)
inout->child_num = i;
bn_write_be(&a, inout->private_key);
ecdsa_get_public_key33(inout->private_key, inout->public_key);
ecdsa_get_address(inout->public_key, 0, inout->address);
xprv_fill_public(inout);
}
void xprv_fill_public(XprvNode *xprv)
{
const uint8_t version = 0x00;
ecdsa_get_public_key33(xprv->private_key, xprv->public_key);
ecdsa_get_address(xprv->public_key, version, xprv->address);
}

View File

@ -20,4 +20,6 @@ void xprv_from_seed(uint8_t *seed, int seed_len, XprvNode *out);
void xprv_descent(XprvNode *inout, uint32_t i);
void xprv_fill_public(XprvNode *xprv);
#endif

View File

@ -293,7 +293,7 @@ void ecdsa_get_public_key65(const uint8_t *priv_key, uint8_t *pub_key)
bn_write_be(&R.y, pub_key + 33);
}
void ecdsa_get_address(const uint8_t *pub_key, char version, char *addr)
void ecdsa_get_address(const uint8_t *pub_key, uint8_t version, char *addr)
{
const char code[] = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
char *p = addr, s;

View File

@ -35,7 +35,7 @@
int ecdsa_sign(const uint8_t *priv_key, const uint8_t *msg, uint32_t msg_len, uint8_t *sig);
void ecdsa_get_public_key33(const uint8_t *priv_key, uint8_t *pub_key);
void ecdsa_get_public_key65(const uint8_t *priv_key, uint8_t *pub_key);
void ecdsa_get_address(const uint8_t *pub_key, char version, char *addr);
void ecdsa_get_address(const uint8_t *pub_key, uint8_t version, char *addr);
int ecdsa_verify(const uint8_t *pub_key, const uint8_t *sig, const uint8_t *msg, uint32_t msg_len);
#endif