Files
app-ethereum/src_features/getPublicKey/cmd_getPublicKey.c

74 lines
2.2 KiB
C
Raw Normal View History

2020-06-27 13:24:04 +02:00
#include "shared_context.h"
#include "apdu_constants.h"
2020-06-27 13:24:04 +02:00
#include "feature_getPublicKey.h"
#include "ethUtils.h"
2022-08-24 09:25:01 +02:00
#include "common_ui.h"
#include "os_io_seproxyhal.h"
2020-06-27 13:24:04 +02:00
2020-12-01 16:20:13 +01:00
void handleGetPublicKey(uint8_t p1,
uint8_t p2,
const uint8_t *dataBuffer,
uint8_t dataLength,
2020-12-01 16:20:13 +01:00
unsigned int *flags,
unsigned int *tx) {
uint8_t privateKeyData[INT256_LENGTH];
2022-07-08 11:12:50 +02:00
bip32_path_t bip32;
2020-12-01 16:20:13 +01:00
cx_ecfp_private_key_t privateKey;
2022-07-08 11:12:50 +02:00
if (!G_called_from_swap) {
2020-12-01 16:20:13 +01:00
reset_app_context();
}
2022-07-08 11:12:50 +02:00
2020-12-01 16:20:13 +01:00
if ((p1 != P1_CONFIRM) && (p1 != P1_NON_CONFIRM)) {
THROW(0x6B00);
}
if ((p2 != P2_CHAINCODE) && (p2 != P2_NO_CHAINCODE)) {
THROW(0x6B00);
}
2022-07-08 11:12:50 +02:00
dataBuffer = parseBip32(dataBuffer, &dataLength, &bip32);
if (dataBuffer == NULL) {
THROW(0x6a80);
2020-12-01 16:20:13 +01:00
}
2022-07-08 11:12:50 +02:00
2020-12-01 16:20:13 +01:00
tmpCtx.publicKeyContext.getChaincode = (p2 == P2_CHAINCODE);
io_seproxyhal_io_heartbeat();
os_perso_derive_node_bip32(
CX_CURVE_256K1,
2022-07-08 11:12:50 +02:00
bip32.path,
bip32.length,
2020-12-01 16:20:13 +01:00
privateKeyData,
(tmpCtx.publicKeyContext.getChaincode ? tmpCtx.publicKeyContext.chainCode : NULL));
cx_ecfp_init_private_key(CX_CURVE_256K1, privateKeyData, 32, &privateKey);
io_seproxyhal_io_heartbeat();
cx_ecfp_generate_pair(CX_CURVE_256K1, &tmpCtx.publicKeyContext.publicKey, &privateKey, 1);
explicit_bzero(&privateKey, sizeof(privateKey));
explicit_bzero(privateKeyData, sizeof(privateKeyData));
io_seproxyhal_io_heartbeat();
getEthAddressStringFromKey(&tmpCtx.publicKeyContext.publicKey,
tmpCtx.publicKeyContext.address,
&global_sha3,
chainConfig->chainId);
2020-06-27 13:24:04 +02:00
#ifndef NO_CONSENT
2020-12-01 16:20:13 +01:00
if (p1 == P1_NON_CONFIRM)
#endif // NO_CONSENT
{
*tx = set_result_get_publicKey();
THROW(0x9000);
}
2020-06-27 13:24:04 +02:00
#ifndef NO_CONSENT
2020-12-01 16:20:13 +01:00
else {
snprintf(strings.common.fullAddress,
sizeof(strings.common.fullAddress),
"0x%.*s",
40,
tmpCtx.publicKeyContext.address);
2022-08-24 09:25:01 +02:00
ui_display_public_key();
2020-06-27 13:24:04 +02:00
2020-12-01 16:20:13 +01:00
*flags |= IO_ASYNCH_REPLY;
}
#endif // NO_CONSENT
2020-06-27 13:24:04 +02:00
}