Skip to content

Commit b3d96d1

Browse files
Use standard app crypto helper to simplify io_seproxyhal_touch_tx_ok
1 parent 277b505 commit b3d96d1

File tree

2 files changed

+23
-28
lines changed

2 files changed

+23
-28
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@ else
266266
APP_SOURCE_PATH += src_bagl
267267
endif
268268

269+
# Allow usage of function from lib_standard_app/crypto_helpers.c
270+
APP_SOURCE_FILES += ${BOLOS_SDK}/lib_standard_app/crypto_helpers.c
271+
269272
### initialize plugin SDK submodule if needed, rebuild it, and warn if a difference is noticed
270273
ifeq ($(CHAIN),ethereum)
271274
ifneq ($(shell git submodule status | grep '^[-+]'),)

src_features/signTx/ui_common_signTx.c

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,26 @@
1+
#include "lib_standard_app/crypto_helpers.h"
12
#include "os_io_seproxyhal.h"
23
#include "shared_context.h"
34
#include "utils.h"
45
#include "common_ui.h"
56
#include "handle_swap_sign_transaction.h"
67

78
unsigned int io_seproxyhal_touch_tx_ok(__attribute__((unused)) const bagl_element_t *e) {
8-
uint8_t privateKeyData[INT256_LENGTH];
9-
uint8_t signature[100];
10-
cx_ecfp_private_key_t privateKey;
11-
uint32_t tx = 0;
9+
uint32_t info = 0;
1210
int err;
13-
io_seproxyhal_io_heartbeat();
14-
os_perso_derive_node_bip32(CX_CURVE_256K1,
15-
tmpCtx.transactionContext.bip32.path,
16-
tmpCtx.transactionContext.bip32.length,
17-
privateKeyData,
18-
NULL);
19-
cx_ecfp_init_private_key(CX_CURVE_256K1, privateKeyData, 32, &privateKey);
20-
explicit_bzero(privateKeyData, sizeof(privateKeyData));
21-
unsigned int info = 0;
22-
io_seproxyhal_io_heartbeat();
23-
cx_ecdsa_sign(&privateKey,
24-
CX_RND_RFC6979 | CX_LAST,
25-
CX_SHA256,
26-
tmpCtx.transactionContext.hash,
27-
sizeof(tmpCtx.transactionContext.hash),
28-
signature,
29-
sizeof(signature),
30-
&info);
31-
explicit_bzero(&privateKey, sizeof(privateKey));
11+
if (bip32_derive_ecdsa_sign_rs_hash_256(CX_CURVE_256K1,
12+
tmpCtx.transactionContext.bip32.path,
13+
tmpCtx.transactionContext.bip32.length,
14+
CX_RND_RFC6979 | CX_LAST,
15+
CX_SHA256,
16+
tmpCtx.transactionContext.hash,
17+
sizeof(tmpCtx.transactionContext.hash),
18+
G_io_apdu_buffer + 1,
19+
G_io_apdu_buffer + 1 + 32,
20+
&info) != CX_OK) {
21+
THROW(0x6F00);
22+
}
23+
3224
if (txContext.txType == EIP1559 || txContext.txType == EIP2930) {
3325
if (info & CX_ECCINFO_PARITY_ODD) {
3426
G_io_apdu_buffer[0] = 1;
@@ -57,13 +49,13 @@ unsigned int io_seproxyhal_touch_tx_ok(__attribute__((unused)) const bagl_elemen
5749
G_io_apdu_buffer[0] += 2;
5850
}
5951
}
60-
format_signature_out(signature);
61-
tx = 65;
62-
G_io_apdu_buffer[tx++] = 0x90;
63-
G_io_apdu_buffer[tx++] = 0x00;
52+
53+
// Write status code at parity_byte + r + s
54+
G_io_apdu_buffer[1 + 64] = 0x90;
55+
G_io_apdu_buffer[1 + 64 + 1] = 0x00;
6456

6557
// Send back the response, do not restart the event loop
66-
err = io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, tx);
58+
err = io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, 1 + 64 + 2);
6759
if (G_called_from_swap) {
6860
PRINTF("G_called_from_swap\n");
6961

0 commit comments

Comments
 (0)