Skip to content

Commit

Permalink
Re-indent all C files to 4 spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
elric1 committed Sep 19, 2023
1 parent 2f6e871 commit 92dbd78
Show file tree
Hide file tree
Showing 23 changed files with 2,697 additions and 2,697 deletions.
194 changes: 97 additions & 97 deletions app/src/apdu_pubkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,137 +38,137 @@ static void format_pkh(char *);
static void stream_cb(tz_ui_cb_type_t);

static void provide_pubkey(void) {
buffer_t bufs[2] = {0};
uint8_t byte;
cx_ecfp_public_key_t pubkey;
TZ_PREAMBLE(("void"));

// 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(EXC_SECURITY, os_global_pin_is_validated() == BOLOS_UX_OK);
TZ_CHECK(generate_public_key(&pubkey, global.path_with_curve.derivation_type,
&global.path_with_curve.bip32_path));

byte = pubkey.W_len;
bufs[0].ptr = &byte;
bufs[0].size = 1;
bufs[1].ptr = pubkey.W;
bufs[1].size = pubkey.W_len;
io_send_response_buffers(bufs, 2, SW_OK);
global.step = ST_IDLE;

TZ_POSTAMBLE;
buffer_t bufs[2] = {0};
uint8_t byte;
cx_ecfp_public_key_t pubkey;
TZ_PREAMBLE(("void"));

// 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(EXC_SECURITY, os_global_pin_is_validated() == BOLOS_UX_OK);
TZ_CHECK(generate_public_key(&pubkey, global.path_with_curve.derivation_type,
&global.path_with_curve.bip32_path));

byte = pubkey.W_len;
bufs[0].ptr = &byte;
bufs[0].size = 1;
bufs[1].ptr = pubkey.W;
bufs[1].size = pubkey.W_len;
io_send_response_buffers(bufs, 2, SW_OK);
global.step = ST_IDLE;

TZ_POSTAMBLE;
}

static void format_pkh(char *buffer) {
cx_ecfp_public_key_t pubkey = {0};
uint8_t hash[21];
TZ_PREAMBLE(("buffer=%p", buffer));

TZ_CHECK(generate_public_key(&pubkey, global.path_with_curve.derivation_type,
&global.path_with_curve.bip32_path));
TZ_CHECK(public_key_hash(hash+1, 20, NULL,
global.path_with_curve.derivation_type, &pubkey));
switch (global.path_with_curve.derivation_type) {
case DERIVATION_TYPE_SECP256K1: hash[0] = 1; break;
case DERIVATION_TYPE_SECP256R1: hash[0] = 2; break;
case DERIVATION_TYPE_ED25519:
case DERIVATION_TYPE_BIP32_ED25519: hash[0] = 0; break;
default: CX_CHECK(EXC_WRONG_PARAM); break;
}
TZ_CHECK(tz_format_pkh(hash, 21, buffer));

TZ_POSTAMBLE;
cx_ecfp_public_key_t pubkey = {0};
uint8_t hash[21];
TZ_PREAMBLE(("buffer=%p", buffer));

TZ_CHECK(generate_public_key(&pubkey, global.path_with_curve.derivation_type,
&global.path_with_curve.bip32_path));
TZ_CHECK(public_key_hash(hash+1, 20, NULL,
global.path_with_curve.derivation_type, &pubkey));
switch (global.path_with_curve.derivation_type) {
case DERIVATION_TYPE_SECP256K1: hash[0] = 1; break;
case DERIVATION_TYPE_SECP256R1: hash[0] = 2; break;
case DERIVATION_TYPE_ED25519:
case DERIVATION_TYPE_BIP32_ED25519: hash[0] = 0; break;
default: CX_CHECK(EXC_WRONG_PARAM); break;
}
TZ_CHECK(tz_format_pkh(hash, 21, buffer));

TZ_POSTAMBLE;
}

static void stream_cb(tz_ui_cb_type_t type) {
TZ_PREAMBLE(("type=%u", type));
TZ_PREAMBLE(("type=%u", type));

switch (type) {
case TZ_UI_STREAM_CB_ACCEPT: TZ_CHECK(provide_pubkey()); break;
case TZ_UI_STREAM_CB_REFILL: break;
case TZ_UI_STREAM_CB_REJECT: TZ_FAIL(EXC_REJECT); break;
}
switch (type) {
case TZ_UI_STREAM_CB_ACCEPT: TZ_CHECK(provide_pubkey()); break;
case TZ_UI_STREAM_CB_REFILL: break;
case TZ_UI_STREAM_CB_REJECT: TZ_FAIL(EXC_REJECT); break;
}

TZ_POSTAMBLE;
TZ_POSTAMBLE;
}

#ifdef HAVE_BAGL
static void prompt_address(void) {
char buf[TZ_UI_STREAM_CONTENTS_SIZE + 1];
TZ_PREAMBLE(("void"));

global.step = ST_PROMPT;
tz_ui_stream_init(stream_cb);
TZ_CHECK(format_pkh(buf));
tz_ui_stream_push_all(TZ_UI_STREAM_CB_NOCB, "Provide Key", buf,
TZ_UI_ICON_NONE);
tz_ui_stream_push_accept_reject();
tz_ui_stream_close();
tz_ui_stream();

TZ_POSTAMBLE;
char buf[TZ_UI_STREAM_CONTENTS_SIZE + 1];
TZ_PREAMBLE(("void"));

global.step = ST_PROMPT;
tz_ui_stream_init(stream_cb);
TZ_CHECK(format_pkh(buf));
tz_ui_stream_push_all(TZ_UI_STREAM_CB_NOCB, "Provide Key", buf,
TZ_UI_ICON_NONE);
tz_ui_stream_push_accept_reject();
tz_ui_stream_close();
tz_ui_stream();

TZ_POSTAMBLE;
}
#elif HAVE_NBGL

#include "nbgl_use_case.h"

static void cancel_callback(void) {
stream_cb(TZ_UI_STREAM_CB_REJECT);
nbgl_useCaseStatus("Address rejected", false, ui_home_init);
stream_cb(TZ_UI_STREAM_CB_REJECT);
nbgl_useCaseStatus("Address rejected", false, ui_home_init);
}

static void approve_callback(void) {
stream_cb(TZ_UI_STREAM_CB_ACCEPT);
nbgl_useCaseStatus("ADDRESS\nVERIFIED", true, ui_home_init);
stream_cb(TZ_UI_STREAM_CB_ACCEPT);
nbgl_useCaseStatus("ADDRESS\nVERIFIED", true, ui_home_init);
}

static void confirmation_callback(bool confirm) {
if (confirm) {
approve_callback();
} else {
cancel_callback();
}
if (confirm) {
approve_callback();
} else {
cancel_callback();
}
}

static void verify_address(void) {
char buf[TZ_UI_STREAM_CONTENTS_SIZE + 1];
TZ_PREAMBLE(("void"));
char buf[TZ_UI_STREAM_CONTENTS_SIZE + 1];
TZ_PREAMBLE(("void"));

TZ_CHECK(format_pkh(buf));
nbgl_useCaseAddressConfirmation(buf, confirmation_callback);
TZ_POSTAMBLE;
TZ_CHECK(format_pkh(buf));
nbgl_useCaseAddressConfirmation(buf, confirmation_callback);
TZ_POSTAMBLE;
}

static void prompt_address(void) {
TZ_PREAMBLE(("void"));
TZ_PREAMBLE(("void"));

global.step = ST_PROMPT;
nbgl_useCaseReviewStart(&C_tezos, "Verify Tezos\naddress", NULL, "Cancel", verify_address, cancel_callback);
TZ_POSTAMBLE;
global.step = ST_PROMPT;
nbgl_useCaseReviewStart(&C_tezos, "Verify Tezos\naddress", NULL, "Cancel", verify_address, cancel_callback);
TZ_POSTAMBLE;
}
#endif

void handle_apdu_get_public_key(command_t *cmd) {
bool prompt = cmd->ins == INS_PROMPT_PUBLIC_KEY;
TZ_PREAMBLE(("cmd=%p", cmd));

TZ_ASSERT(EXC_UNEXPECTED_STATE, global.step == ST_IDLE);
TZ_ASSERT(EXC_WRONG_PARAM, cmd->p1 == 0);

// do not expose pks without prompt through U2F (permissionless legacy
// comm in browser)
TZ_ASSERT(EXC_HID_REQUIRED, prompt || G_io_apdu_media != IO_APDU_MEDIA_U2F);

global.path_with_curve.derivation_type = cmd->p2;
TZ_ASSERT(EXC_WRONG_PARAM,
check_derivation_type(global.path_with_curve.derivation_type));
TZ_CHECK(read_bip32_path(&global.path_with_curve.bip32_path,
cmd->data, cmd->lc));
if (prompt)
prompt_address();
else
provide_pubkey();

TZ_POSTAMBLE;
bool prompt = cmd->ins == INS_PROMPT_PUBLIC_KEY;
TZ_PREAMBLE(("cmd=%p", cmd));

TZ_ASSERT(EXC_UNEXPECTED_STATE, global.step == ST_IDLE);
TZ_ASSERT(EXC_WRONG_PARAM, cmd->p1 == 0);

// do not expose pks without prompt through U2F (permissionless legacy
// comm in browser)
TZ_ASSERT(EXC_HID_REQUIRED, prompt || G_io_apdu_media != IO_APDU_MEDIA_U2F);

global.path_with_curve.derivation_type = cmd->p2;
TZ_ASSERT(EXC_WRONG_PARAM,
check_derivation_type(global.path_with_curve.derivation_type));
TZ_CHECK(read_bip32_path(&global.path_with_curve.bip32_path,
cmd->data, cmd->lc));
if (prompt)
prompt_address();
else
provide_pubkey();

TZ_POSTAMBLE;
}
Loading

0 comments on commit 92dbd78

Please sign in to comment.