mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-12 18:49:07 +00:00
get rid of bip32 versions, it's a mess :(
This commit is contained in:
parent
b08d44d39e
commit
18dea22213
19
bip32.c
19
bip32.c
@ -7,11 +7,8 @@
|
||||
#include "sha2.h"
|
||||
#include "ripemd160.h"
|
||||
|
||||
void hdnode_from_xpub(uint8_t version_byte, uint32_t version_private, uint32_t version_public, uint32_t depth, uint32_t fingerprint, uint32_t child_num, uint8_t *chain_code, uint8_t *public_key, HDNode *out)
|
||||
void hdnode_from_xpub(uint8_t version_byte, uint32_t depth, uint32_t fingerprint, uint32_t child_num, uint8_t *chain_code, uint8_t *public_key, HDNode *out)
|
||||
{
|
||||
out->version = version_public;
|
||||
out->version_private = version_private;
|
||||
out->version_public = version_public;
|
||||
out->depth = depth;
|
||||
out->fingerprint = fingerprint;
|
||||
out->child_num = child_num;
|
||||
@ -22,11 +19,8 @@ void hdnode_from_xpub(uint8_t version_byte, uint32_t version_private, uint32_t v
|
||||
hdnode_fill_address(out);
|
||||
}
|
||||
|
||||
void hdnode_from_xprv(uint8_t version_byte, uint32_t version_private, uint32_t version_public, uint32_t depth, uint32_t fingerprint, uint32_t child_num, uint8_t *chain_code, uint8_t *private_key, HDNode *out)
|
||||
void hdnode_from_xprv(uint8_t version_byte, uint32_t depth, uint32_t fingerprint, uint32_t child_num, uint8_t *chain_code, uint8_t *private_key, HDNode *out)
|
||||
{
|
||||
out->version = version_private;
|
||||
out->version_private = version_private;
|
||||
out->version_public = version_public;
|
||||
out->depth = depth;
|
||||
out->fingerprint = fingerprint;
|
||||
out->child_num = child_num;
|
||||
@ -37,12 +31,9 @@ void hdnode_from_xprv(uint8_t version_byte, uint32_t version_private, uint32_t v
|
||||
hdnode_fill_address(out);
|
||||
}
|
||||
|
||||
void hdnode_from_seed(uint8_t version_byte, uint32_t version_private, uint32_t version_public, uint8_t *seed, int seed_len, HDNode *out)
|
||||
void hdnode_from_seed(uint8_t version_byte, uint8_t *seed, int seed_len, HDNode *out)
|
||||
{
|
||||
uint8_t I[32 + 32];
|
||||
out->version = version_private;
|
||||
out->version_private = version_private;
|
||||
out->version_public = version_public;
|
||||
out->depth = 0;
|
||||
out->fingerprint = 0x00000000;
|
||||
out->child_num = 0;
|
||||
@ -61,8 +52,6 @@ int hdnode_private_ckd(HDNode *inout, uint32_t i)
|
||||
uint8_t fingerprint[32];
|
||||
bignum256 a, b;
|
||||
|
||||
inout->version = inout->version_private;
|
||||
|
||||
if (i & 0x80000000) { // private derivation
|
||||
data[0] = 0;
|
||||
memcpy(data + 1, inout->private_key, 32);
|
||||
@ -102,8 +91,6 @@ int hdnode_public_ckd(HDNode *inout, uint32_t i)
|
||||
curve_point a, b;
|
||||
bignum256 c;
|
||||
|
||||
inout->version = inout->version_public;
|
||||
|
||||
if (i & 0x80000000) { // private derivation
|
||||
return 0;
|
||||
} else { // public derivation
|
||||
|
10
bip32.h
10
bip32.h
@ -4,7 +4,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
uint32_t version;
|
||||
// uint32_t version;
|
||||
uint32_t depth;
|
||||
uint32_t fingerprint;
|
||||
uint32_t child_num;
|
||||
@ -13,15 +13,13 @@ typedef struct {
|
||||
uint8_t public_key[33];
|
||||
char address[35];
|
||||
uint8_t version_byte;
|
||||
uint32_t version_private;
|
||||
uint32_t version_public;
|
||||
} HDNode;
|
||||
|
||||
void hdnode_from_xpub(uint8_t version_byte, uint32_t version_private, uint32_t version_public, uint32_t depth, uint32_t fingerprint, uint32_t child_num, uint8_t *chain_code, uint8_t *public_key, HDNode *out);
|
||||
void hdnode_from_xpub(uint8_t version_byte, uint32_t depth, uint32_t fingerprint, uint32_t child_num, uint8_t *chain_code, uint8_t *public_key, HDNode *out);
|
||||
|
||||
void hdnode_from_xprv(uint8_t version_byte, uint32_t version_private, uint32_t version_public, uint32_t depth, uint32_t fingerprint, uint32_t child_num, uint8_t *chain_code, uint8_t *private_key, HDNode *out);
|
||||
void hdnode_from_xprv(uint8_t version_byte, uint32_t depth, uint32_t fingerprint, uint32_t child_num, uint8_t *chain_code, uint8_t *private_key, HDNode *out);
|
||||
|
||||
void hdnode_from_seed(uint8_t version_byte, uint32_t version_private, uint32_t version_public, uint8_t *seed, int seed_len, HDNode *out);
|
||||
void hdnode_from_seed(uint8_t version_byte, uint8_t *seed, int seed_len, HDNode *out);
|
||||
|
||||
#define hdnode_private_ckd_prime(X, I) hdnode_private_ckd((X), ((I) | 0x80000000))
|
||||
|
||||
|
6
tests.c
6
tests.c
@ -80,7 +80,7 @@ START_TEST(test_bip32_vector_1)
|
||||
HDNode node;
|
||||
|
||||
// init m
|
||||
hdnode_from_seed(0x00, 0x0488ADE4, 0x0488B21E, fromhex("000102030405060708090a0b0c0d0e0f"), 16, &node);
|
||||
hdnode_from_seed(0x00, fromhex("000102030405060708090a0b0c0d0e0f"), 16, &node);
|
||||
|
||||
// [Chain m]
|
||||
ck_assert_int_eq(node.fingerprint, 0x00000000);
|
||||
@ -138,7 +138,7 @@ START_TEST(test_bip32_vector_2)
|
||||
int r;
|
||||
|
||||
// init m
|
||||
hdnode_from_seed(0x00, 0x0488ADE4, 0x0488B21E, fromhex("fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542"), 64, &node);
|
||||
hdnode_from_seed(0x00, fromhex("fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542"), 64, &node);
|
||||
|
||||
// [Chain m]
|
||||
ck_assert_int_eq(node.fingerprint, 0x00000000);
|
||||
@ -193,7 +193,7 @@ START_TEST(test_bip32_vector_2)
|
||||
ck_assert_str_eq(node.address, "14UKfRV9ZPUp6ZC9PLhqbRtxdihW9em3xt");
|
||||
|
||||
// init m
|
||||
hdnode_from_seed(0x00, 0x0488ADE4, 0x0488B21E, fromhex("fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542"), 64, &node);
|
||||
hdnode_from_seed(0x00, fromhex("fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542"), 64, &node);
|
||||
|
||||
// test public derivation
|
||||
// [Chain m/0]
|
||||
|
Loading…
Reference in New Issue
Block a user