4
4
#include "feature_getPublicKey.h"
5
5
#include "common_ui.h"
6
6
#include "os_io_seproxyhal.h"
7
+ #include "crypto_helpers.h"
8
+
9
+
10
+ void getEthPublicKey (uint32_t * bip32Path , uint8_t bip32PathLength ) {
11
+ tmpCtx .publicKeyContext .publicKey .curve = CX_CURVE_256K1 ;
12
+ tmpCtx .publicKeyContext .publicKey .W_len = 65 ;
13
+ if (bip32_derive_get_pubkey_256 (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
+ }
7
29
8
30
void handleGetPublicKey (uint8_t p1 ,
9
31
uint8_t p2 ,
10
32
const uint8_t * dataBuffer ,
11
33
uint8_t dataLength ,
12
34
unsigned int * flags ,
13
35
unsigned int * tx ) {
14
- uint8_t privateKeyData [INT256_LENGTH ];
15
36
bip32_path_t bip32 ;
16
- cx_ecfp_private_key_t privateKey ;
17
37
18
38
if (!G_called_from_swap ) {
19
39
reset_app_context ();
@@ -35,25 +55,7 @@ void handleGetPublicKey(uint8_t p1,
35
55
}
36
56
37
57
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 );
57
59
58
60
uint64_t chain_id = chainConfig -> chainId ;
59
61
if (dataLength >= sizeof (chain_id )) {
0 commit comments