Skip to content

Commit

Permalink
[get-pk] send the stored pk instead of derived it again
Browse files Browse the repository at this point in the history
  • Loading branch information
spalmer25 committed Oct 31, 2024
1 parent db702b9 commit 31d4c45
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
11 changes: 2 additions & 9 deletions src/apdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,15 @@
#include <stdint.h>
#include <string.h>

int provide_pubkey(bip32_path_with_curve_t const* const path_with_curve) {
int provide_pubkey(cx_ecfp_public_key_t const* const pubkey) {
tz_exc exc = SW_OK;
cx_err_t error = CX_OK;

TZ_ASSERT_NOT_NULL(path_with_curve);
TZ_ASSERT_NOT_NULL(pubkey);

uint8_t resp[1u + MAX_SIGNATURE_SIZE] = {0};
size_t offset = 0;

// Application could be PIN-locked, and pubkey->W_len would then be 0,
// so throwing an error rather than returning an empty key
TZ_ASSERT(os_global_pin_is_validated() == BOLOS_UX_OK, EXC_SECURITY);

cx_ecfp_public_key_t* pubkey = (cx_ecfp_public_key_t*) &(tz_ecfp_public_key_t){0};
CX_CHECK(generate_public_key(pubkey, path_with_curve));

resp[offset] = pubkey->W_len;
offset++;
memmove(resp + offset, pubkey->W, pubkey->W_len);
Expand Down
2 changes: 1 addition & 1 deletion src/apdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ static inline int io_send_apdu_err(uint16_t sw) {
* @param path_with_curve: bip32 path and curve of the key
* @return int: zero or positive integer if success, negative integer otherwise.
*/
int provide_pubkey(bip32_path_with_curve_t const* const path_with_curve);
int provide_pubkey(cx_ecfp_public_key_t const* const pubkey);
4 changes: 2 additions & 2 deletions src/apdu_pubkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* @return true
*/
static bool pubkey_ok(void) {
provide_pubkey(&global.path_with_curve);
provide_pubkey((cx_ecfp_public_key_t *) &global.public_key);
return true;
}

Expand Down Expand Up @@ -87,7 +87,7 @@ int handle_get_public_key(buffer_t *cdata,
generate_public_key((cx_ecfp_public_key_t *) &global.public_key, &global.path_with_curve));

if (!prompt) {
return provide_pubkey(&global.path_with_curve);
return provide_pubkey((cx_ecfp_public_key_t *) &global.public_key);
} else {
// INS_PROMPT_PUBLIC_KEY || INS_AUTHORIZE_BAKING
ui_callback_t cb;
Expand Down
2 changes: 1 addition & 1 deletion src/apdu_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static bool ok(void) {

UPDATE_NVRAM;

provide_pubkey(&global.path_with_curve);
provide_pubkey((cx_ecfp_public_key_t *) &global.public_key);

return true;
}
Expand Down

0 comments on commit 31d4c45

Please sign in to comment.