|
| 1 | +#include "lib_standard_app/crypto_helpers.h" |
1 | 2 | #include "os_io_seproxyhal.h"
|
2 | 3 | #include "shared_context.h"
|
3 | 4 | #include "utils.h"
|
4 | 5 | #include "common_ui.h"
|
5 | 6 | #include "handle_swap_sign_transaction.h"
|
6 | 7 |
|
7 | 8 | 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; |
12 | 10 | 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 | + |
32 | 24 | if (txContext.txType == EIP1559 || txContext.txType == EIP2930) {
|
33 | 25 | if (info & CX_ECCINFO_PARITY_ODD) {
|
34 | 26 | G_io_apdu_buffer[0] = 1;
|
@@ -57,13 +49,13 @@ unsigned int io_seproxyhal_touch_tx_ok(__attribute__((unused)) const bagl_elemen
|
57 | 49 | G_io_apdu_buffer[0] += 2;
|
58 | 50 | }
|
59 | 51 | }
|
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; |
64 | 56 |
|
65 | 57 | // 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); |
67 | 59 | if (G_called_from_swap) {
|
68 | 60 | PRINTF("G_called_from_swap\n");
|
69 | 61 |
|
|
0 commit comments