embed: hdnode field length fix

pull/25/head
Tomas Susanka 6 years ago committed by Jan Pochyla
parent e4423567cb
commit 858f2583a5

@ -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[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");
}
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");
}
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");
}
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");
}
const curve_info *curve = NULL;
if (NULL == curve_name.buf) {
if (0 == curve_name.len) {
curve = get_curve_by_name(SECP256K1_NAME);
} else {
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->hdnode.depth = depth;
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);
} else {
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);
} else {
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);
} else {
memzero(o->hdnode.public_key, 33);

Loading…
Cancel
Save