Skip to content

Commit

Permalink
Merge pull request #8 from obsidiansystems/eac@fix-hq-master
Browse files Browse the repository at this point in the history
Revert "Merge pull request #7 from KhalilBellakrid/chaincode"
  • Loading branch information
TamtamHero authored Sep 13, 2019
2 parents 60577f0 + 9697009 commit 13318d9
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 39 deletions.
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ obj
src/u2f_crypto_data.h
src/glyphs.h
src/glyphs.c
/ledger
*.hex
Dockerfile
prepare-devenv.sh

#ide
*.code-workspace
compile_commands.json
.idea/
7 changes: 1 addition & 6 deletions src/apdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@
#include <stdint.h>
#include <string.h>

size_t provide_pubkey(uint8_t *const io_buffer, cx_ecfp_public_key_t const *const pubkey, unsigned char *const chain_code) {
size_t provide_pubkey(uint8_t *const io_buffer, cx_ecfp_public_key_t const *const pubkey) {
size_t tx = 0;
io_buffer[tx++] = pubkey->W_len;
memmove(io_buffer + tx, pubkey->W, pubkey->W_len);
tx += pubkey->W_len;

io_buffer[tx++] = 32;
memmove(io_buffer + tx, chain_code, 32);
tx += 32;

return finalize_successful_send(tx);
}

Expand Down
2 changes: 1 addition & 1 deletion src/apdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static inline void require_hid(void) {
}
}

size_t provide_pubkey(uint8_t *const io_buffer, cx_ecfp_public_key_t const *const pubkey, unsigned char *const chain_code);
size_t provide_pubkey(uint8_t *const io_buffer, cx_ecfp_public_key_t const *const pubkey);

size_t handle_apdu_error(uint8_t instruction);
size_t handle_apdu_version(uint8_t instruction);
Expand Down
6 changes: 3 additions & 3 deletions src/apdu_pubkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#define G global.u.pubkey

static bool pubkey_ok(void) {
delayed_send(provide_pubkey(G_io_apdu_buffer, &G.public_key, G.chain_code));
delayed_send(provide_pubkey(G_io_apdu_buffer, &G.public_key));
return true;
}

Expand Down Expand Up @@ -91,10 +91,10 @@ size_t handle_apdu_get_public_key(uint8_t instruction) {
if (G.key.bip32_path.length == 0) THROW(EXC_WRONG_LENGTH_FOR_INS);
}
#endif
generate_public_key(&G.public_key, G.key.curve, &G.key.bip32_path, G.chain_code);
generate_public_key(&G.public_key, G.key.curve, &G.key.bip32_path);

if (instruction == INS_GET_PUBLIC_KEY) {
return provide_pubkey(G_io_apdu_buffer, &G.public_key, G.chain_code);
return provide_pubkey(G_io_apdu_buffer, &G.public_key);
} else {
// instruction == INS_PROMPT_PUBLIC_KEY || instruction == INS_AUTHORIZE_BAKING
ui_callback_t cb;
Expand Down
4 changes: 2 additions & 2 deletions src/apdu_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ static bool ok(void) {
});

cx_ecfp_public_key_t const *const pubkey = generate_public_key_return_global(
G.key.curve, &G.key.bip32_path, G.chain_code);
delayed_send(provide_pubkey(G_io_apdu_buffer, pubkey, G.chain_code));
G.key.curve, &G.key.bip32_path);
delayed_send(provide_pubkey(G_io_apdu_buffer, pubkey));
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void update_baking_idle_screens(void) {
STRCPY(global.ui.baking_idle_screens.pkh, "No Key Authorized");
} else {
cx_ecfp_public_key_t const *const pubkey = generate_public_key_return_global(
N_data.baking_key.curve, &N_data.baking_key.bip32_path, NULL);
N_data.baking_key.curve, &N_data.baking_key.bip32_path);
pubkey_to_pkh_string(
global.ui.baking_idle_screens.pkh, sizeof(global.ui.baking_idle_screens.pkh),
N_data.baking_key.curve, pubkey);
Expand Down
5 changes: 2 additions & 3 deletions src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ typedef struct {

union {
struct {
bip32_path_with_curve_t key;
cx_ecfp_public_key_t public_key;
unsigned char chain_code[32];
bip32_path_with_curve_t key;
cx_ecfp_public_key_t public_key;
} pubkey;

apdu_sign_state_t sign;
Expand Down
14 changes: 6 additions & 8 deletions src/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ size_t read_bip32_path(bip32_path_t *const out, uint8_t const *const in, size_t

struct key_pair *generate_key_pair_return_global(
cx_curve_t const curve,
bip32_path_t const *const bip32_path,
unsigned char *const chain_code
bip32_path_t const *const bip32_path
) {
check_null(bip32_path);
struct priv_generate_key_pair *const priv = &global.priv.generate_key_pair;
Expand All @@ -57,10 +56,10 @@ struct key_pair *generate_key_pair_return_global(
if (curve == CX_CURVE_Ed25519) {
os_perso_derive_node_bip32_seed_key(
HDW_ED25519_SLIP10, curve, bip32_path->components, bip32_path->length,
priv->privateKeyData, chain_code, NULL, 0);
priv->privateKeyData, NULL, NULL, 0);
} else {
#endif
os_perso_derive_node_bip32(curve, bip32_path->components, bip32_path->length, priv->privateKeyData, chain_code);
os_perso_derive_node_bip32(curve, bip32_path->components, bip32_path->length, priv->privateKeyData, NULL);
#if CX_APILEVEL > 8
}
#endif
Expand All @@ -80,11 +79,10 @@ struct key_pair *generate_key_pair_return_global(

cx_ecfp_public_key_t const *generate_public_key_return_global(
cx_curve_t const curve,
bip32_path_t const *const bip32_path,
unsigned char *const chain_code
bip32_path_t const *const bip32_path
) {
check_null(bip32_path);
struct key_pair *const pair = generate_key_pair_return_global(curve, bip32_path, chain_code);
struct key_pair *const pair = generate_key_pair_return_global(curve, bip32_path);
memset(&pair->private_key, 0, sizeof(pair->private_key));
return &pair->public_key;
}
Expand Down Expand Up @@ -134,7 +132,7 @@ size_t sign(
check_null(key);
check_null(in);

struct key_pair *const pair = generate_key_pair_return_global(key->curve, &key->bip32_path, NULL);
struct key_pair *const pair = generate_key_pair_return_global(key->curve, &key->bip32_path);

size_t tx = 0;
switch (key->curve) {
Expand Down
13 changes: 5 additions & 8 deletions src/keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ size_t read_bip32_path(bip32_path_t *const out, uint8_t const *const in, size_t
// Non-reentrant
struct key_pair *generate_key_pair_return_global(
cx_curve_t const curve,
bip32_path_t const *const bip32_path,
unsigned char *const chain_code);
bip32_path_t const *const bip32_path);

// Non-reentrant
static inline void generate_key_pair(
Expand All @@ -29,25 +28,23 @@ static inline void generate_key_pair(
bip32_path_t const *const bip32_path
) {
check_null(out);
struct key_pair *const result = generate_key_pair_return_global(curve, bip32_path, NULL);
struct key_pair *const result = generate_key_pair_return_global(curve, bip32_path);
memcpy(out, result, sizeof(*out));
}

// Non-reentrant
cx_ecfp_public_key_t const *generate_public_key_return_global(
cx_curve_t const curve,
bip32_path_t const *const bip32_path,
unsigned char *const chain_code);
bip32_path_t const *const bip32_path);

// Non-reentrant
static inline void generate_public_key(
cx_ecfp_public_key_t *const out,
cx_curve_t const curve,
bip32_path_t const *const bip32_path,
unsigned char *const chain_code
bip32_path_t const *const bip32_path
) {
check_null(out);
cx_ecfp_public_key_t const *const result = generate_public_key_return_global(curve, bip32_path, chain_code);
cx_ecfp_public_key_t const *const result = generate_public_key_return_global(curve, bip32_path);
memcpy(out, result, sizeof(*out));
}

Expand Down
2 changes: 1 addition & 1 deletion src/operations.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static inline void compute_pkh(
check_null(bip32_path);
check_null(compressed_pubkey_out);
check_null(contract_out);
cx_ecfp_public_key_t const *const pubkey = generate_public_key_return_global(curve, bip32_path, NULL);
cx_ecfp_public_key_t const *const pubkey = generate_public_key_return_global(curve, bip32_path);
public_key_hash(
contract_out->hash, sizeof(contract_out->hash),
compressed_pubkey_out,
Expand Down
3 changes: 2 additions & 1 deletion src/to_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ void bip32_path_with_curve_to_pkh_string(
) {
check_null(out);
check_null(key);

cx_ecfp_public_key_t const *const pubkey = generate_public_key_return_global(
key->curve, &key->bip32_path, NULL);
key->curve, &key->bip32_path);
pubkey_to_pkh_string(out, out_size, key->curve, pubkey);
}

Expand Down

0 comments on commit 13318d9

Please sign in to comment.