44#include "feature_getPublicKey.h"
55#include "common_ui.h"
66#include "os_io_seproxyhal.h"
7+ #include "crypto_helpers.h"
8+
9+ void getEthPublicKey (uint32_t * bip32Path , uint8_t bip32PathLength ) {
10+ tmpCtx .publicKeyContext .publicKey .curve = CX_CURVE_256K1 ;
11+ tmpCtx .publicKeyContext .publicKey .W_len = 65 ;
12+ if (bip32_derive_get_pubkey_256 (
13+ CX_CURVE_256K1 ,
14+ bip32Path ,
15+ bip32PathLength ,
16+ tmpCtx .publicKeyContext .publicKey .W ,
17+ (tmpCtx .publicKeyContext .getChaincode ? tmpCtx .publicKeyContext .chainCode : NULL ),
18+ CX_SHA512 ) != CX_OK ) {
19+ THROW (CX_INVALID_PARAMETER );
20+ }
21+
22+ if (!getEthAddressStringFromKey (& tmpCtx .publicKeyContext .publicKey ,
23+ tmpCtx .publicKeyContext .address ,
24+ & global_sha3 ,
25+ chainConfig -> chainId )) {
26+ THROW (CX_INVALID_PARAMETER );
27+ }
28+ }
729
830void handleGetPublicKey (uint8_t p1 ,
931 uint8_t p2 ,
1032 const uint8_t * dataBuffer ,
1133 uint8_t dataLength ,
1234 unsigned int * flags ,
1335 unsigned int * tx ) {
14- uint8_t privateKeyData [INT256_LENGTH ];
1536 bip32_path_t bip32 ;
16- cx_ecfp_private_key_t privateKey ;
1737
1838 if (!G_called_from_swap ) {
1939 reset_app_context ();
@@ -35,25 +55,7 @@ void handleGetPublicKey(uint8_t p1,
3555 }
3656
3757 tmpCtx .publicKeyContext .getChaincode = (p2 == P2_CHAINCODE );
38- io_seproxyhal_io_heartbeat ();
39- os_perso_derive_node_bip32 (
40- CX_CURVE_256K1 ,
41- bip32 .path ,
42- bip32 .length ,
43- privateKeyData ,
44- (tmpCtx .publicKeyContext .getChaincode ? tmpCtx .publicKeyContext .chainCode : NULL ));
45- cx_ecfp_init_private_key (CX_CURVE_256K1 , privateKeyData , 32 , & privateKey );
46- io_seproxyhal_io_heartbeat ();
47- cx_ecfp_generate_pair (CX_CURVE_256K1 , & tmpCtx .publicKeyContext .publicKey , & privateKey , 1 );
48- explicit_bzero (& privateKey , sizeof (privateKey ));
49- explicit_bzero (privateKeyData , sizeof (privateKeyData ));
50- io_seproxyhal_io_heartbeat ();
51- if (!getEthAddressStringFromKey (& tmpCtx .publicKeyContext .publicKey ,
52- tmpCtx .publicKeyContext .address ,
53- & global_sha3 ,
54- chainConfig -> chainId )) {
55- THROW (CX_INVALID_PARAMETER );
56- }
58+ getEthPublicKey (bip32 .path , bip32 .length );
5759
5860 uint64_t chain_id = chainConfig -> chainId ;
5961 if (dataLength >= sizeof (chain_id )) {
0 commit comments