mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-09 06:50:58 +00:00
extract xprv_fill_public method
This commit is contained in:
parent
b14ce58df7
commit
9da3b35962
13
bip32.c
13
bip32.c
@ -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]
|
// this can be done because private_key[32] and chain_code[32]
|
||||||
// form a continuous 64 byte block in the memory
|
// form a continuous 64 byte block in the memory
|
||||||
hmac_sha512((uint8_t *)"Bitcoin seed", 12, seed, seed_len, out->private_key);
|
hmac_sha512((uint8_t *)"Bitcoin seed", 12, seed, seed_len, out->private_key);
|
||||||
ecdsa_get_public_key33(out->private_key, out->public_key);
|
xprv_fill_public(out);
|
||||||
ecdsa_get_address(out->public_key, 0, out->address);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void xprv_descent(XprvNode *inout, uint32_t i)
|
void xprv_descent(XprvNode *inout, uint32_t i)
|
||||||
@ -44,6 +43,12 @@ void xprv_descent(XprvNode *inout, uint32_t i)
|
|||||||
inout->child_num = i;
|
inout->child_num = i;
|
||||||
bn_write_be(&a, inout->private_key);
|
bn_write_be(&a, inout->private_key);
|
||||||
|
|
||||||
ecdsa_get_public_key33(inout->private_key, inout->public_key);
|
xprv_fill_public(inout);
|
||||||
ecdsa_get_address(inout->public_key, 0, inout->address);
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
2
bip32.h
2
bip32.h
@ -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_descent(XprvNode *inout, uint32_t i);
|
||||||
|
|
||||||
|
void xprv_fill_public(XprvNode *xprv);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
2
ecdsa.c
2
ecdsa.c
@ -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);
|
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";
|
const char code[] = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
||||||
char *p = addr, s;
|
char *p = addr, s;
|
||||||
|
2
ecdsa.h
2
ecdsa.h
@ -35,7 +35,7 @@
|
|||||||
int ecdsa_sign(const uint8_t *priv_key, const uint8_t *msg, uint32_t msg_len, uint8_t *sig);
|
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_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_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);
|
int ecdsa_verify(const uint8_t *pub_key, const uint8_t *sig, const uint8_t *msg, uint32_t msg_len);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user