1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 07:28:10 +00:00

Use different seed modifier for different curves

This commit is contained in:
Jochen Hoenicke 2016-04-20 10:30:33 +02:00
parent c983afd72f
commit 0bc1b70c4a
5 changed files with 16 additions and 5 deletions

View File

@ -86,7 +86,8 @@ int hdnode_from_seed(const uint8_t *seed, int seed_len, const char* curve, HDNod
out->fingerprint = 0x00000000; out->fingerprint = 0x00000000;
out->child_num = 0; out->child_num = 0;
out->curve = get_curve_by_name(curve); out->curve = get_curve_by_name(curve);
hmac_sha512((uint8_t *)"Bitcoin seed", 12, seed, seed_len, I); hmac_sha512((const uint8_t*) out->curve->bip32_name,
strlen(out->curve->bip32_name), seed, seed_len, I);
memcpy(out->private_key, I, 32); memcpy(out->private_key, I, 32);
bignum256 a; bignum256 a;
bn_read_be(out->private_key, &a); bn_read_be(out->private_key, &a);
@ -337,6 +338,7 @@ int hdnode_deserialize(const char *str, HDNode *node)
if (!base58_decode_check(str, node_data, sizeof(node_data))) { if (!base58_decode_check(str, node_data, sizeof(node_data))) {
return -1; return -1;
} }
node->curve = get_curve_by_name(SECP256K1_NAME);
uint32_t version = read_be(node_data); uint32_t version = read_be(node_data);
if (version == 0x0488B21E) { // public node if (version == 0x0488B21E) { // public node
memcpy(node->public_key, node_data + 45, 33); memcpy(node->public_key, node_data + 45, 33);

View File

@ -1050,10 +1050,10 @@ const ecdsa_curve *get_curve_by_name(const char *curve_name) {
if (curve_name == 0) { if (curve_name == 0) {
return 0; return 0;
} }
if (strcmp(curve_name, "secp256k1") == 0) { if (strcmp(curve_name, SECP256K1_NAME) == 0) {
return &secp256k1; return &secp256k1;
} }
if (strcmp(curve_name, "nist256p1") == 0) { if (strcmp(curve_name, NIST256P1_NAME) == 0) {
return &nist256p1; return &nist256p1;
} }
return 0; return 0;

View File

@ -41,6 +41,7 @@ typedef struct {
bignum256 order_half; // order of G divided by 2 bignum256 order_half; // order of G divided by 2
int a; // coefficient 'a' of the elliptic curve int a; // coefficient 'a' of the elliptic curve
bignum256 b; // coefficient 'b' of the elliptic curve bignum256 b; // coefficient 'b' of the elliptic curve
const char *bip32_name;// string used for generating BIP32 xprv from seed
#if USE_PRECOMPUTED_CP #if USE_PRECOMPUTED_CP
const curve_point cp[64][8]; const curve_point cp[64][8];

View File

@ -46,7 +46,11 @@ const ecdsa_curve nist256p1 = {
/* b */ { /* b */ {
/*.val =*/{0x27d2604b, 0x2f38f0f8, 0x53b0f63, 0x741ac33, 0x1886bc65, 0x2ef555da, 0x293e7b3e, 0xd762a8e, 0x5ac6} /*.val =*/{0x27d2604b, 0x2f38f0f8, 0x53b0f63, 0x741ac33, 0x1886bc65, 0x2ef555da, 0x293e7b3e, 0xd762a8e, 0x5ac6}
} },
/* bip32_name */
"Nist256p1 seed"
#if USE_PRECOMPUTED_CP #if USE_PRECOMPUTED_CP
, ,
/* cp */ { /* cp */ {

View File

@ -47,7 +47,11 @@ const ecdsa_curve secp256k1 = {
/* b */ { /* b */ {
/*.val =*/{7} /*.val =*/{7}
} },
/* bip32_name */
"Bitcoin seed"
#if USE_PRECOMPUTED_CP #if USE_PRECOMPUTED_CP
, ,
/* cp */ { /* cp */ {