Completely remove old Starkware internal "plugin"
This commit is contained in:
@@ -14,10 +14,6 @@ void handleGetAppConfiguration(uint8_t p1,
|
||||
UNUSED(flags);
|
||||
G_io_apdu_buffer[0] = (N_storage.dataAllowed ? APP_FLAG_DATA_ALLOWED : 0x00);
|
||||
G_io_apdu_buffer[0] |= APP_FLAG_EXTERNAL_TOKEN_NEEDED;
|
||||
#ifdef HAVE_STARKWARE
|
||||
G_io_apdu_buffer[0] |= APP_FLAG_STARKWARE;
|
||||
G_io_apdu_buffer[0] |= APP_FLAG_STARKWARE_V2;
|
||||
#endif
|
||||
G_io_apdu_buffer[1] = LEDGER_MAJOR_VERSION;
|
||||
G_io_apdu_buffer[2] = LEDGER_MINOR_VERSION;
|
||||
G_io_apdu_buffer[3] = LEDGER_PATCH_VERSION;
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
#include "shared_context.h"
|
||||
#include "common_utils.h"
|
||||
#include "feature_signTx.h"
|
||||
#ifdef HAVE_STARKWARE
|
||||
#include "stark_utils.h"
|
||||
#endif
|
||||
#include "uint256.h"
|
||||
#include "eth_plugin_handler.h"
|
||||
#include "network.h"
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
#ifdef HAVE_STARKWARE
|
||||
|
||||
#include "shared_context.h"
|
||||
#include "apdu_constants.h"
|
||||
#include "stark_utils.h"
|
||||
#include "feature_stark_getPublicKey.h"
|
||||
#include "common_ui.h"
|
||||
#include "os_io_seproxyhal.h"
|
||||
|
||||
void handleStarkwareGetPublicKey(uint8_t p1,
|
||||
uint8_t p2,
|
||||
const uint8_t *dataBuffer,
|
||||
uint8_t dataLength,
|
||||
unsigned int *flags,
|
||||
unsigned int *tx) {
|
||||
bip32_path_t bip32;
|
||||
cx_ecfp_private_key_t privateKey;
|
||||
uint8_t privateKeyData[32];
|
||||
|
||||
reset_app_context();
|
||||
|
||||
if ((p1 != P1_CONFIRM) && (p1 != P1_NON_CONFIRM)) {
|
||||
THROW(0x6B00);
|
||||
}
|
||||
|
||||
if (p2 != 0) {
|
||||
THROW(0x6B00);
|
||||
}
|
||||
|
||||
dataBuffer = parseBip32(dataBuffer, &dataLength, &bip32);
|
||||
|
||||
if (dataBuffer == NULL) {
|
||||
THROW(0x6a80);
|
||||
}
|
||||
|
||||
io_seproxyhal_io_heartbeat();
|
||||
starkDerivePrivateKey(bip32.path, bip32.length, privateKeyData);
|
||||
cx_ecfp_init_private_key(CX_CURVE_Stark256, privateKeyData, 32, &privateKey);
|
||||
io_seproxyhal_io_heartbeat();
|
||||
cx_ecfp_generate_pair(CX_CURVE_Stark256, &tmpCtx.publicKeyContext.publicKey, &privateKey, 1);
|
||||
explicit_bzero(&privateKey, sizeof(privateKey));
|
||||
explicit_bzero(privateKeyData, sizeof(privateKeyData));
|
||||
io_seproxyhal_io_heartbeat();
|
||||
#ifndef NO_CONSENT
|
||||
if (p1 == P1_NON_CONFIRM)
|
||||
#endif // NO_CONSENT
|
||||
{
|
||||
*tx = set_result_get_stark_publicKey();
|
||||
THROW(0x9000);
|
||||
}
|
||||
#ifndef NO_CONSENT
|
||||
else {
|
||||
// prepare for a UI based reply
|
||||
snprintf(strings.tmp.tmp,
|
||||
sizeof(strings.tmp.tmp),
|
||||
"0x%.*H",
|
||||
32,
|
||||
tmpCtx.publicKeyContext.publicKey.W + 1);
|
||||
ui_display_stark_public();
|
||||
|
||||
*flags |= IO_ASYNCH_REPLY;
|
||||
}
|
||||
#endif // NO_CONSENT
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,8 +0,0 @@
|
||||
#ifndef _STARK_GET_PUB_KEY_H_
|
||||
#define _STARK_GET_PUB_KEY_H_
|
||||
|
||||
#include "shared_context.h"
|
||||
|
||||
uint32_t set_result_get_stark_publicKey(void);
|
||||
|
||||
#endif // _STARK_GET_PUB_KEY_H_
|
||||
@@ -1,14 +0,0 @@
|
||||
#ifdef HAVE_STARKWARE
|
||||
|
||||
#include <string.h>
|
||||
#include "shared_context.h"
|
||||
#include "feature_stark_getPublicKey.h"
|
||||
|
||||
uint32_t set_result_get_stark_publicKey() {
|
||||
uint32_t tx = 0;
|
||||
memmove(G_io_apdu_buffer + tx, tmpCtx.publicKeyContext.publicKey.W, 65);
|
||||
tx += 65;
|
||||
return tx;
|
||||
}
|
||||
|
||||
#endif // HAVE_STARKWARE
|
||||
@@ -1,19 +0,0 @@
|
||||
#ifdef HAVE_STARKWARE
|
||||
|
||||
#include "shared_context.h"
|
||||
#include "common_ui.h"
|
||||
#include "feature_stark_getPublicKey.h"
|
||||
|
||||
unsigned int io_seproxyhal_touch_stark_pubkey_ok(__attribute__((unused)) const bagl_element_t *e) {
|
||||
uint32_t tx = set_result_get_stark_publicKey();
|
||||
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();
|
||||
return 0; // do not redraw the widget
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,64 +0,0 @@
|
||||
#ifdef HAVE_STARKWARE
|
||||
|
||||
#include "shared_context.h"
|
||||
#include "apdu_constants.h"
|
||||
#include "common_ui.h"
|
||||
|
||||
void handleStarkwareProvideQuantum(uint8_t p1,
|
||||
__attribute__((unused)) uint8_t p2,
|
||||
const uint8_t *dataBuffer,
|
||||
uint8_t dataLength,
|
||||
__attribute__((unused)) unsigned int *flags,
|
||||
__attribute__((unused)) unsigned int *tx) {
|
||||
size_t i = 0;
|
||||
uint8_t expectedDataSize = 20 + 32;
|
||||
uint8_t addressZero = 0;
|
||||
tokenDefinition_t *currentToken = NULL;
|
||||
if (appState != APP_STATE_IDLE) {
|
||||
reset_app_context();
|
||||
}
|
||||
switch (p1) {
|
||||
case STARK_QUANTUM_LEGACY:
|
||||
break;
|
||||
case STARK_QUANTUM_ETH:
|
||||
case STARK_QUANTUM_ERC20:
|
||||
case STARK_QUANTUM_ERC721:
|
||||
case STARK_QUANTUM_MINTABLE_ERC20:
|
||||
case STARK_QUANTUM_MINTABLE_ERC721:
|
||||
expectedDataSize += 32;
|
||||
break;
|
||||
default:
|
||||
THROW(0x6B00);
|
||||
}
|
||||
if (dataLength != expectedDataSize) {
|
||||
THROW(0x6700);
|
||||
}
|
||||
if (p1 == STARK_QUANTUM_LEGACY) {
|
||||
addressZero = allzeroes((void *) dataBuffer, 20);
|
||||
}
|
||||
if ((p1 != STARK_QUANTUM_ETH) && !addressZero) {
|
||||
for (i = 0; i < MAX_ITEMS; i++) {
|
||||
currentToken = &tmpCtx.transactionContext.extraInfo[i].token;
|
||||
if (tmpCtx.transactionContext.tokenSet[i] &&
|
||||
(memcmp(currentToken->address, dataBuffer, 20) == 0)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == MAX_ITEMS) {
|
||||
PRINTF("Associated token not found\n");
|
||||
THROW(0x6A80);
|
||||
}
|
||||
} else {
|
||||
i = MAX_ITEMS;
|
||||
}
|
||||
memmove(dataContext.tokenContext.quantum, dataBuffer + 20, 32);
|
||||
if (p1 != STARK_QUANTUM_LEGACY) {
|
||||
memmove(dataContext.tokenContext.mintingBlob, dataBuffer + 20 + 32, 32);
|
||||
}
|
||||
dataContext.tokenContext.quantumIndex = i;
|
||||
dataContext.tokenContext.quantumType = p1;
|
||||
quantumSet = true;
|
||||
THROW(0x9000);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,259 +0,0 @@
|
||||
#ifdef HAVE_STARKWARE
|
||||
|
||||
#include "shared_context.h"
|
||||
#include "apdu_constants.h"
|
||||
#include "stark_utils.h"
|
||||
#include "poorstream.h"
|
||||
#include "common_ui.h"
|
||||
#include "os_io_seproxyhal.h"
|
||||
|
||||
#define U8BE(buf, off) \
|
||||
(uint64_t)((((uint64_t) U4BE(buf, off)) << 32) | (((uint64_t) U4BE(buf, off + 4)) & 0xFFFFFFFF))
|
||||
#define TMP_OFFSET 140
|
||||
|
||||
void handleStarkwareSignMessage(uint8_t p1,
|
||||
uint8_t p2,
|
||||
uint8_t *dataBuffer,
|
||||
uint8_t dataLength,
|
||||
unsigned int *flags,
|
||||
__attribute__((unused)) unsigned int *tx) {
|
||||
uint8_t privateKeyData[INT256_LENGTH];
|
||||
uint32_t i;
|
||||
uint8_t bip32PathLength;
|
||||
uint8_t offset = 1;
|
||||
cx_ecfp_private_key_t privateKey;
|
||||
poorstream_t bitstream;
|
||||
bool selfTransfer = false;
|
||||
uint8_t order = 1;
|
||||
uint8_t protocol = 2;
|
||||
uint8_t preOffset, postOffset;
|
||||
uint8_t zeroTest;
|
||||
|
||||
// Initial checks
|
||||
if (appState != APP_STATE_IDLE) {
|
||||
reset_app_context();
|
||||
}
|
||||
|
||||
if (dataLength < 1) {
|
||||
PRINTF("Invalid data\n");
|
||||
THROW(0x6a80);
|
||||
}
|
||||
|
||||
bip32PathLength = *(dataBuffer);
|
||||
|
||||
if ((bip32PathLength < 0x01) || (bip32PathLength > MAX_BIP32_PATH)) {
|
||||
PRINTF("Invalid path\n");
|
||||
THROW(0x6a80);
|
||||
}
|
||||
switch (p1) {
|
||||
case P1_STARK_ORDER:
|
||||
protocol = 1;
|
||||
break;
|
||||
case P1_STARK_TRANSFER:
|
||||
protocol = 1;
|
||||
order = 0;
|
||||
break;
|
||||
case P1_STARK_ORDER_V2:
|
||||
break;
|
||||
case P1_STARK_TRANSFER_V2:
|
||||
case P1_STARK_CONDITIONAL_TRANSFER:
|
||||
order = 0;
|
||||
break;
|
||||
default:
|
||||
THROW(0x6B00);
|
||||
}
|
||||
postOffset = (protocol == 2 ? 1 + 32 : 0);
|
||||
preOffset = (protocol == 2 ? 1 : 0);
|
||||
if (order) {
|
||||
if (dataLength != (20 + 32 + 20 + 32 + 4 + 4 + 8 + 8 + 4 + 4 + 1 + 4 * bip32PathLength +
|
||||
2 * postOffset)) {
|
||||
THROW(0x6700);
|
||||
}
|
||||
} else {
|
||||
if (dataLength != (20 + 32 + 32 + 4 + 4 + 8 + 4 + 4 + 1 + 4 * bip32PathLength + postOffset +
|
||||
(p1 == P1_STARK_CONDITIONAL_TRANSFER ? 32 + 20 : 0))) {
|
||||
THROW(0x6700);
|
||||
}
|
||||
}
|
||||
if (p2 != 0) {
|
||||
THROW(0x6B00);
|
||||
}
|
||||
tmpCtx.transactionContext.bip32.length = bip32PathLength;
|
||||
for (i = 0; i < bip32PathLength; i++) {
|
||||
tmpCtx.transactionContext.bip32.path[i] = U4BE(dataBuffer, offset);
|
||||
PRINTF("Storing path %d %d\n", i, tmpCtx.transactionContext.bip32.path[i]);
|
||||
offset += 4;
|
||||
}
|
||||
// Discard the path to use part of dataBuffer as a temporary buffer
|
||||
memmove(dataBuffer, dataBuffer + offset, dataLength - offset);
|
||||
dataContext.starkContext.conditional = (p1 == P1_STARK_CONDITIONAL_TRANSFER);
|
||||
if (dataContext.starkContext.conditional) {
|
||||
memmove(dataContext.starkContext.fact,
|
||||
dataBuffer + 20 + 32 + postOffset + 32 + 4 + 4 + 8 + 4 + 4,
|
||||
32);
|
||||
memmove(dataContext.starkContext.conditionAddress,
|
||||
dataBuffer + 20 + 32 + postOffset + 32 + 4 + 4 + 8 + 4 + 4 + 32,
|
||||
20);
|
||||
PRINTF("Fact %.*H\n", 32, dataContext.starkContext.fact);
|
||||
PRINTF("Address %.*H\n", 20, dataContext.starkContext.conditionAddress);
|
||||
}
|
||||
|
||||
zeroTest = allzeroes(dataBuffer + preOffset, 20);
|
||||
if (zeroTest && (protocol == 2) && (dataBuffer[0] != STARK_QUANTUM_ETH)) {
|
||||
PRINTF("stark - unexpected quantum descriptor type for null first address %d\n",
|
||||
dataBuffer[0]);
|
||||
THROW(0x6A80);
|
||||
}
|
||||
if (!zeroTest && getKnownToken(dataBuffer + preOffset) == NULL) {
|
||||
PRINTF("stark - cannot process unknown token %.*H", 20, dataBuffer + preOffset);
|
||||
THROW(0x6A80);
|
||||
}
|
||||
if (order) {
|
||||
zeroTest = allzeroes(dataBuffer + 20 + 32 + postOffset + preOffset, 20);
|
||||
if (zeroTest && (protocol == 2) && (dataBuffer[1 + 20 + 32 + 32] != STARK_QUANTUM_ETH)) {
|
||||
PRINTF("stark - unexpected quantum descriptor type for null second address %d\n",
|
||||
dataBuffer[1 + 20 + 32 + 32]);
|
||||
THROW(0x6A80);
|
||||
}
|
||||
if (!zeroTest && getKnownToken(dataBuffer + 20 + 32 + postOffset + preOffset) == NULL) {
|
||||
PRINTF("stark - cannot process unknown token %.*H",
|
||||
20,
|
||||
dataBuffer + 20 + 32 + postOffset + preOffset);
|
||||
THROW(0x6A80);
|
||||
}
|
||||
}
|
||||
// Prepare the Stark parameters
|
||||
io_seproxyhal_io_heartbeat();
|
||||
compute_token_id(&global_sha3,
|
||||
dataBuffer + preOffset,
|
||||
(protocol == 2 ? dataBuffer[0] : STARK_QUANTUM_LEGACY),
|
||||
dataBuffer + preOffset + 20,
|
||||
(protocol == 2 ? dataBuffer + 1 + 20 + 32 : NULL),
|
||||
false,
|
||||
dataContext.starkContext.w1);
|
||||
if (order) {
|
||||
io_seproxyhal_io_heartbeat();
|
||||
compute_token_id(&global_sha3,
|
||||
dataBuffer + 20 + 32 + postOffset + preOffset,
|
||||
(protocol == 2 ? dataBuffer[1 + 20 + 32 + 32] : STARK_QUANTUM_LEGACY),
|
||||
dataBuffer + 20 + 32 + postOffset + preOffset + 20,
|
||||
(protocol == 2 ? dataBuffer + 1 + 20 + 32 + 32 + 1 + 20 + 32 : NULL),
|
||||
false,
|
||||
dataContext.starkContext.w2);
|
||||
offset = 20 + 32 + postOffset + 20 + 32 + postOffset;
|
||||
} else {
|
||||
memmove(dataContext.starkContext.w2, dataBuffer + 20 + 32 + postOffset, 32);
|
||||
offset = 20 + 32 + postOffset + 32;
|
||||
}
|
||||
|
||||
poorstream_init(&bitstream, dataContext.starkContext.w3);
|
||||
poorstream_write_bits(&bitstream, 0, 11); // padding
|
||||
poorstream_write_bits(&bitstream,
|
||||
(p1 == P1_STARK_CONDITIONAL_TRANSFER ? STARK_CONDITIONAL_TRANSFER_TYPE
|
||||
: order ? STARK_ORDER_TYPE
|
||||
: STARK_TRANSFER_TYPE),
|
||||
4);
|
||||
poorstream_write_bits(&bitstream, U4BE(dataBuffer, offset), 31);
|
||||
poorstream_write_bits(&bitstream, U4BE(dataBuffer, offset + 4), 31);
|
||||
poorstream_write_bits(&bitstream, U8BE(dataBuffer, offset + 4 + 4), 63);
|
||||
if (order) {
|
||||
poorstream_write_bits(&bitstream, U8BE(dataBuffer, offset + 4 + 4 + 8), 63);
|
||||
offset += 4 + 4 + 8 + 8;
|
||||
} else {
|
||||
poorstream_write_bits(&bitstream, 0, 63);
|
||||
offset += 4 + 4 + 8;
|
||||
}
|
||||
poorstream_write_bits(&bitstream, U4BE(dataBuffer, offset), 31);
|
||||
poorstream_write_bits(&bitstream, U4BE(dataBuffer, offset + 4), 22);
|
||||
|
||||
PRINTF("stark w1 %.*H\n", 32, dataContext.starkContext.w1);
|
||||
PRINTF("stark w2 %.*H\n", 32, dataContext.starkContext.w2);
|
||||
PRINTF("stark w3 %.*H\n", 32, dataContext.starkContext.w3);
|
||||
|
||||
if (dataContext.starkContext.conditional) {
|
||||
cx_keccak_init(&global_sha3, 256);
|
||||
cx_hash((cx_hash_t *) &global_sha3,
|
||||
0,
|
||||
dataContext.starkContext.conditionAddress,
|
||||
20,
|
||||
NULL,
|
||||
0);
|
||||
cx_hash((cx_hash_t *) &global_sha3,
|
||||
CX_LAST,
|
||||
dataContext.starkContext.fact,
|
||||
32,
|
||||
dataContext.starkContext.w4,
|
||||
32);
|
||||
dataContext.starkContext.w4[0] &= 0x03;
|
||||
PRINTF("stark w4 %.*H\n", 32, dataContext.starkContext.w4);
|
||||
}
|
||||
// Prepare the UI
|
||||
if (order) {
|
||||
io_seproxyhal_io_heartbeat();
|
||||
// amount to sell
|
||||
stark_get_amount_string(dataBuffer + preOffset,
|
||||
dataBuffer + preOffset + 20,
|
||||
dataBuffer + 20 + 32 + postOffset + 20 + 32 + postOffset + 4 + 4,
|
||||
(char *) (dataBuffer + TMP_OFFSET),
|
||||
strings.common.fullAmount);
|
||||
io_seproxyhal_io_heartbeat();
|
||||
// amount to buy
|
||||
stark_get_amount_string(
|
||||
dataBuffer + 20 + 32 + postOffset + preOffset,
|
||||
dataBuffer + 20 + 32 + postOffset + preOffset + 20,
|
||||
dataBuffer + 20 + 32 + postOffset + 20 + 32 + postOffset + 4 + 4 + 8,
|
||||
(char *) (dataBuffer + TMP_OFFSET),
|
||||
strings.common.maxFee);
|
||||
// src vault ID
|
||||
snprintf(strings.common.fullAddress,
|
||||
sizeof(strings.common.fullAddress),
|
||||
"%d",
|
||||
U4BE(dataBuffer, 20 + 32 + postOffset + 20 + 32 + postOffset));
|
||||
} else {
|
||||
cx_ecfp_public_key_t publicKey;
|
||||
// Check if the transfer is a self transfer
|
||||
io_seproxyhal_io_heartbeat();
|
||||
starkDerivePrivateKey(tmpCtx.transactionContext.bip32.path,
|
||||
bip32PathLength,
|
||||
privateKeyData);
|
||||
cx_ecfp_init_private_key(CX_CURVE_Stark256, privateKeyData, 32, &privateKey);
|
||||
io_seproxyhal_io_heartbeat();
|
||||
cx_ecfp_generate_pair(CX_CURVE_Stark256, &publicKey, &privateKey, 1);
|
||||
explicit_bzero(&privateKey, sizeof(privateKey));
|
||||
explicit_bzero(privateKeyData, sizeof(privateKeyData));
|
||||
io_seproxyhal_io_heartbeat();
|
||||
selfTransfer = (memcmp(publicKey.W + 1, dataBuffer + 20 + 32 + postOffset, 32) == 0);
|
||||
PRINTF("self transfer %d\n", selfTransfer);
|
||||
io_seproxyhal_io_heartbeat();
|
||||
// amount to transfer
|
||||
stark_get_amount_string(dataBuffer + preOffset,
|
||||
dataBuffer + preOffset + 20,
|
||||
dataBuffer + 20 + 32 + postOffset + 32 + 4 + 4,
|
||||
(char *) (dataBuffer + TMP_OFFSET),
|
||||
tmpContent.tmp);
|
||||
// dest vault ID
|
||||
snprintf(strings.tmp.tmp2,
|
||||
sizeof(strings.tmp.tmp2),
|
||||
"%d",
|
||||
U4BE(dataBuffer, 20 + 32 + postOffset + 32 + 4));
|
||||
if (!selfTransfer) {
|
||||
memmove(dataContext.starkContext.transferDestination,
|
||||
dataBuffer + 20 + 32 + postOffset,
|
||||
32);
|
||||
snprintf(strings.tmp.tmp,
|
||||
sizeof(strings.tmp.tmp),
|
||||
"0x%.*H",
|
||||
32,
|
||||
dataBuffer + 20 + 32 + postOffset);
|
||||
}
|
||||
}
|
||||
if (order) {
|
||||
ui_stark_limit_order();
|
||||
} else {
|
||||
ui_stark_transfer(selfTransfer, dataContext.starkContext.conditional);
|
||||
}
|
||||
|
||||
*flags |= IO_ASYNCH_REPLY;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,36 +0,0 @@
|
||||
#ifdef HAVE_STARKWARE
|
||||
|
||||
#include "os_io_seproxyhal.h"
|
||||
#include "shared_context.h"
|
||||
#include "stark_utils.h"
|
||||
#include "common_ui.h"
|
||||
|
||||
unsigned int io_seproxyhal_touch_stark_ok(__attribute__((unused)) const bagl_element_t *e) {
|
||||
uint8_t privateKeyData[32];
|
||||
uint8_t signature[72];
|
||||
uint32_t tx = 0;
|
||||
io_seproxyhal_io_heartbeat();
|
||||
starkDerivePrivateKey(tmpCtx.transactionContext.bip32.path,
|
||||
tmpCtx.transactionContext.bip32.length,
|
||||
privateKeyData);
|
||||
io_seproxyhal_io_heartbeat();
|
||||
stark_sign(signature,
|
||||
privateKeyData,
|
||||
dataContext.starkContext.w1,
|
||||
dataContext.starkContext.w2,
|
||||
dataContext.starkContext.w3,
|
||||
(dataContext.starkContext.conditional ? dataContext.starkContext.w4 : NULL));
|
||||
G_io_apdu_buffer[0] = 0;
|
||||
format_signature_out(signature);
|
||||
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();
|
||||
return 0; // do not redraw the widget
|
||||
}
|
||||
|
||||
#endif // HAVE_STARKWARE
|
||||
@@ -1,55 +0,0 @@
|
||||
#ifdef HAVE_STARKWARE
|
||||
|
||||
#include "shared_context.h"
|
||||
#include "apdu_constants.h"
|
||||
#include "stark_utils.h"
|
||||
#include "common_ui.h"
|
||||
#include "os_io_seproxyhal.h"
|
||||
|
||||
void handleStarkwareUnsafeSign(uint8_t p1,
|
||||
uint8_t p2,
|
||||
const uint8_t *dataBuffer,
|
||||
uint8_t dataLength,
|
||||
unsigned int *flags,
|
||||
__attribute__((unused)) unsigned int *tx) {
|
||||
uint8_t privateKeyData[INT256_LENGTH];
|
||||
cx_ecfp_public_key_t publicKey;
|
||||
cx_ecfp_private_key_t privateKey;
|
||||
|
||||
// Initial checks
|
||||
if (appState != APP_STATE_IDLE) {
|
||||
reset_app_context();
|
||||
}
|
||||
|
||||
if ((p1 != 0) || (p2 != 0)) {
|
||||
THROW(0x6B00);
|
||||
}
|
||||
|
||||
dataBuffer = parseBip32(dataBuffer, &dataLength, &tmpCtx.transactionContext.bip32);
|
||||
|
||||
if (dataBuffer == NULL) {
|
||||
THROW(0x6a80);
|
||||
}
|
||||
|
||||
if (dataLength != 32) {
|
||||
THROW(0x6700);
|
||||
}
|
||||
|
||||
memmove(dataContext.starkContext.w2, dataBuffer, 32);
|
||||
io_seproxyhal_io_heartbeat();
|
||||
starkDerivePrivateKey(tmpCtx.transactionContext.bip32.path,
|
||||
tmpCtx.transactionContext.bip32.length,
|
||||
privateKeyData);
|
||||
cx_ecfp_init_private_key(CX_CURVE_Stark256, privateKeyData, 32, &privateKey);
|
||||
io_seproxyhal_io_heartbeat();
|
||||
cx_ecfp_generate_pair(CX_CURVE_Stark256, &publicKey, &privateKey, 1);
|
||||
explicit_bzero(&privateKey, sizeof(privateKey));
|
||||
explicit_bzero(privateKeyData, sizeof(privateKeyData));
|
||||
io_seproxyhal_io_heartbeat();
|
||||
memmove(dataContext.starkContext.w1, publicKey.W + 1, 32);
|
||||
ui_stark_unsafe_sign();
|
||||
|
||||
*flags |= IO_ASYNCH_REPLY;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,42 +0,0 @@
|
||||
#ifdef HAVE_STARKWARE
|
||||
|
||||
#include "os_io_seproxyhal.h"
|
||||
#include "shared_context.h"
|
||||
#include "stark_utils.h"
|
||||
#include "common_ui.h"
|
||||
|
||||
unsigned int io_seproxyhal_touch_stark_unsafe_sign_ok(__attribute__((unused))
|
||||
const bagl_element_t *e) {
|
||||
cx_ecfp_private_key_t privateKey;
|
||||
uint8_t privateKeyData[INT256_LENGTH];
|
||||
uint8_t signature[72];
|
||||
unsigned int info = 0;
|
||||
uint32_t tx = 0;
|
||||
io_seproxyhal_io_heartbeat();
|
||||
starkDerivePrivateKey(tmpCtx.transactionContext.bip32.path,
|
||||
tmpCtx.transactionContext.bip32.length,
|
||||
privateKeyData);
|
||||
io_seproxyhal_io_heartbeat();
|
||||
cx_ecfp_init_private_key(CX_CURVE_Stark256, privateKeyData, 32, &privateKey);
|
||||
cx_ecdsa_sign(&privateKey,
|
||||
CX_RND_RFC6979 | CX_LAST,
|
||||
CX_SHA256,
|
||||
dataContext.starkContext.w2,
|
||||
sizeof(dataContext.starkContext.w2),
|
||||
signature,
|
||||
sizeof(signature),
|
||||
&info);
|
||||
G_io_apdu_buffer[0] = 0;
|
||||
format_signature_out(signature);
|
||||
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();
|
||||
return 0; // do not redraw the widget
|
||||
}
|
||||
|
||||
#endif // HAVE_STARKWARE
|
||||
Reference in New Issue
Block a user