mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-10 15:30:55 +00:00
embed: private key set check simplified
This commit is contained in:
parent
b5e26f1d44
commit
2c2f2ff97b
@ -31,7 +31,6 @@ typedef struct _mp_obj_HDNode_t {
|
|||||||
mp_obj_base_t base;
|
mp_obj_base_t base;
|
||||||
uint32_t fingerprint;
|
uint32_t fingerprint;
|
||||||
HDNode hdnode;
|
HDNode hdnode;
|
||||||
bool private_key_set;
|
|
||||||
} mp_obj_HDNode_t;
|
} mp_obj_HDNode_t;
|
||||||
|
|
||||||
STATIC const mp_obj_type_t mod_trezorcrypto_HDNode_type;
|
STATIC const mp_obj_type_t mod_trezorcrypto_HDNode_type;
|
||||||
@ -111,10 +110,8 @@ STATIC mp_obj_t mod_trezorcrypto_HDNode_make_new(const mp_obj_type_t *type, size
|
|||||||
}
|
}
|
||||||
if (32 == private_key.len) {
|
if (32 == private_key.len) {
|
||||||
memcpy(o->hdnode.private_key, private_key.buf, 32);
|
memcpy(o->hdnode.private_key, private_key.buf, 32);
|
||||||
o->private_key_set = true;
|
|
||||||
} else {
|
} else {
|
||||||
memzero(o->hdnode.private_key, 32);
|
memzero(o->hdnode.private_key, 32);
|
||||||
o->private_key_set = false;
|
|
||||||
}
|
}
|
||||||
if (33 == public_key.len) {
|
if (33 == public_key.len) {
|
||||||
memcpy(o->hdnode.public_key, public_key.buf, 33);
|
memcpy(o->hdnode.public_key, public_key.buf, 33);
|
||||||
@ -140,7 +137,7 @@ STATIC mp_obj_t mod_trezorcrypto_HDNode_derive(size_t n_args, const mp_obj_t *ar
|
|||||||
if (public) {
|
if (public) {
|
||||||
res = hdnode_public_ckd(&o->hdnode, i);
|
res = hdnode_public_ckd(&o->hdnode, i);
|
||||||
} else {
|
} else {
|
||||||
if (!o->private_key_set) {
|
if (0 == memcmp(o->hdnode.private_key, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 32)) {
|
||||||
memzero(&o->hdnode, sizeof(o->hdnode));
|
memzero(&o->hdnode, sizeof(o->hdnode));
|
||||||
mp_raise_ValueError("Failed to derive, private key not set");
|
mp_raise_ValueError("Failed to derive, private key not set");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user