1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-03-04 17:26:23 +00:00

embed: hdnode field length fix

This commit is contained in:
Tomas Susanka 2018-01-26 13:51:44 +01:00 committed by Jan Pochyla
parent e4423567cb
commit 858f2583a5

View File

@ -74,21 +74,21 @@ STATIC mp_obj_t mod_trezorcrypto_HDNode_make_new(const mp_obj_type_t *type, size
mp_get_buffer_raise(vals[5].u_obj, &public_key, MP_BUFFER_READ); mp_get_buffer_raise(vals[5].u_obj, &public_key, MP_BUFFER_READ);
mp_get_buffer_raise(vals[6].u_obj, &curve_name, MP_BUFFER_READ); mp_get_buffer_raise(vals[6].u_obj, &curve_name, MP_BUFFER_READ);
if (NULL == chain_code.buf || 32 != chain_code.len) { if (32 != chain_code.len) {
mp_raise_ValueError("chain_code is invalid"); mp_raise_ValueError("chain_code is invalid");
} }
if (NULL == public_key.buf && NULL == private_key.buf) { if (0 == public_key.len && 0 == private_key.len) {
mp_raise_ValueError("either public_key or private_key is required"); mp_raise_ValueError("either public_key or private_key is required");
} }
if (NULL != private_key.buf && 32 != private_key.len) { if (0 != private_key.len && 32 != private_key.len) {
mp_raise_ValueError("private_key is invalid"); mp_raise_ValueError("private_key is invalid");
} }
if (NULL != public_key.buf && 33 != public_key.len) { if (0 != public_key.len && 33 != public_key.len) {
mp_raise_ValueError("public_key is invalid"); mp_raise_ValueError("public_key is invalid");
} }
const curve_info *curve = NULL; const curve_info *curve = NULL;
if (NULL == curve_name.buf) { if (0 == curve_name.len) {
curve = get_curve_by_name(SECP256K1_NAME); curve = get_curve_by_name(SECP256K1_NAME);
} else { } else {
curve = get_curve_by_name(curve_name.buf); curve = get_curve_by_name(curve_name.buf);
@ -103,17 +103,17 @@ STATIC mp_obj_t mod_trezorcrypto_HDNode_make_new(const mp_obj_type_t *type, size
o->fingerprint = fingerprint; o->fingerprint = fingerprint;
o->hdnode.depth = depth; o->hdnode.depth = depth;
o->hdnode.child_num = child_num; o->hdnode.child_num = child_num;
if (NULL != chain_code.buf && 32 == chain_code.len) { if (32 == chain_code.len) {
memcpy(o->hdnode.chain_code, chain_code.buf, 32); memcpy(o->hdnode.chain_code, chain_code.buf, 32);
} else { } else {
memzero(o->hdnode.chain_code, 32); memzero(o->hdnode.chain_code, 32);
} }
if (NULL != private_key.buf && 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);
} else { } else {
memzero(o->hdnode.private_key, 32); memzero(o->hdnode.private_key, 32);
} }
if (NULL != public_key.buf && 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);
} else { } else {
memzero(o->hdnode.public_key, 33); memzero(o->hdnode.public_key, 33);