2022-03-08 17:59:36 +01:00
|
|
|
#include "os_io_seproxyhal.h"
|
2024-03-18 08:58:05 +01:00
|
|
|
#include "apdu_constants.h"
|
2024-04-15 11:33:42 +02:00
|
|
|
#include "crypto_helpers.h"
|
2022-09-09 17:21:35 +02:00
|
|
|
#include "common_ui.h"
|
2020-06-27 13:24:04 +02:00
|
|
|
|
2022-08-30 10:16:39 +02:00
|
|
|
unsigned int io_seproxyhal_touch_signMessage_ok(void) {
|
2020-06-27 13:24:04 +02:00
|
|
|
uint32_t tx = 0;
|
|
|
|
|
unsigned int info = 0;
|
2024-03-18 08:58:05 +01:00
|
|
|
if (bip32_derive_ecdsa_sign_rs_hash_256(CX_CURVE_256K1,
|
|
|
|
|
tmpCtx.messageSigningContext.bip32.path,
|
|
|
|
|
tmpCtx.messageSigningContext.bip32.length,
|
|
|
|
|
CX_RND_RFC6979 | CX_LAST,
|
|
|
|
|
CX_SHA256,
|
|
|
|
|
tmpCtx.messageSigningContext.hash,
|
|
|
|
|
sizeof(tmpCtx.messageSigningContext.hash),
|
|
|
|
|
G_io_apdu_buffer + 1,
|
|
|
|
|
G_io_apdu_buffer + 1 + 32,
|
|
|
|
|
&info) != CX_OK) {
|
|
|
|
|
THROW(APDU_RESPONSE_UNKNOWN);
|
|
|
|
|
}
|
2020-06-27 13:24:04 +02:00
|
|
|
G_io_apdu_buffer[0] = 27;
|
|
|
|
|
if (info & CX_ECCINFO_PARITY_ODD) {
|
2020-12-01 16:20:13 +01:00
|
|
|
G_io_apdu_buffer[0]++;
|
2020-06-27 13:24:04 +02:00
|
|
|
}
|
|
|
|
|
if (info & CX_ECCINFO_xGTn) {
|
2020-12-01 16:20:13 +01:00
|
|
|
G_io_apdu_buffer[0] += 2;
|
2020-06-27 13:24:04 +02:00
|
|
|
}
|
|
|
|
|
tx = 65;
|
|
|
|
|
G_io_apdu_buffer[tx++] = 0x90;
|
|
|
|
|
G_io_apdu_buffer[tx++] = 0x00;
|
|
|
|
|
reset_app_context();
|
|
|
|
|
// Send back the response, do not restart the event loop
|
|
|
|
|
io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, tx);
|
|
|
|
|
// Display back the original UX
|
|
|
|
|
ui_idle();
|
2020-12-01 16:20:13 +01:00
|
|
|
return 0; // do not redraw the widget
|
2020-06-27 13:24:04 +02:00
|
|
|
}
|
|
|
|
|
|
2022-08-30 10:16:39 +02:00
|
|
|
unsigned int io_seproxyhal_touch_signMessage_cancel(void) {
|
2020-06-27 13:24:04 +02:00
|
|
|
reset_app_context();
|
|
|
|
|
G_io_apdu_buffer[0] = 0x69;
|
|
|
|
|
G_io_apdu_buffer[1] = 0x85;
|
|
|
|
|
// Send back the response, do not restart the event loop
|
|
|
|
|
io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, 2);
|
|
|
|
|
// Display back the original UX
|
|
|
|
|
ui_idle();
|
2020-12-01 16:20:13 +01:00
|
|
|
return 0; // do not redraw the widget
|
2020-06-27 13:24:04 +02:00
|
|
|
}
|