4
4
#include "ethUtils.h"
5
5
#include "string.h"
6
6
7
- #define ZERO (x ) memset (&x, 0 , sizeof(x))
7
+ #define ZERO (x ) explicit_bzero (&x, sizeof(x))
8
8
9
- int handle_check_address (check_address_parameters_t * params , chain_config_t * chain_config ) {
9
+ void handle_check_address (check_address_parameters_t * params , chain_config_t * chain_config ) {
10
+ params -> result = 0 ;
10
11
PRINTF ("Params on the address %d\n" , (unsigned int ) params );
11
12
PRINTF ("Address to check %s\n" , params -> address_to_check );
12
13
PRINTF ("Inside handle_check_address\n" );
13
14
if (params -> address_to_check == 0 ) {
14
15
PRINTF ("Address to check == 0\n" );
15
- return 0 ;
16
+ return ;
16
17
}
17
18
18
- uint8_t i ;
19
19
const uint8_t * bip32_path_ptr = params -> address_parameters ;
20
20
uint8_t bip32PathLength = * (bip32_path_ptr ++ );
21
21
cx_sha3_t local_sha3 ;
@@ -27,37 +27,55 @@ int handle_check_address(check_address_parameters_t* params, chain_config_t* cha
27
27
char address [51 ];
28
28
} locals_union1 ;
29
29
union group2 {
30
- uint8_t privateKeyData [32 ];
30
+ uint8_t privateKeyData [64 ];
31
31
cx_ecfp_public_key_t publicKey ;
32
32
} locals_union2 ;
33
33
34
34
if ((bip32PathLength < 0x01 ) || (bip32PathLength > MAX_BIP32_PATH ) ||
35
35
(bip32PathLength * 4 != params -> address_parameters_length - 1 )) {
36
36
PRINTF ("Invalid path\n" );
37
- return 0 ;
37
+ return ;
38
38
}
39
- for (i = 0 ; i < bip32PathLength ; i ++ ) {
39
+ for (uint8_t i = 0 ; i < bip32PathLength ; i ++ ) {
40
40
locals_union1 .bip32Path [i ] = U4BE (bip32_path_ptr , 0 );
41
41
bip32_path_ptr += 4 ;
42
42
}
43
- os_perso_derive_node_bip32 (CX_CURVE_256K1 ,
44
- locals_union1 .bip32Path ,
45
- bip32PathLength ,
46
- locals_union2 .privateKeyData ,
47
- NULL );
43
+ if (os_derive_bip32_no_throw (CX_CURVE_256K1 ,
44
+ locals_union1 .bip32Path ,
45
+ bip32PathLength ,
46
+ locals_union2 .privateKeyData ,
47
+ NULL ) != CX_OK ) {
48
+ ZERO (locals_union1 );
49
+ ZERO (locals_union2 );
50
+ return ;
51
+ }
52
+
48
53
ZERO (locals_union1 );
49
- cx_ecfp_init_private_key (CX_CURVE_256K1 ,
50
- locals_union2 .privateKeyData ,
51
- 32 ,
52
- & locals_union1 .privateKey );
54
+ if (cx_ecfp_init_private_key_no_throw (CX_CURVE_256K1 ,
55
+ locals_union2 .privateKeyData ,
56
+ 32 ,
57
+ & locals_union1 .privateKey ) != CX_OK ) {
58
+ ZERO (locals_union1 );
59
+ ZERO (locals_union2 );
60
+ return ;
61
+ }
53
62
ZERO (locals_union2 );
54
- cx_ecfp_generate_pair (CX_CURVE_256K1 , & locals_union2 .publicKey , & locals_union1 .privateKey , 1 );
63
+ if (cx_ecfp_generate_pair_no_throw (CX_CURVE_256K1 ,
64
+ & locals_union2 .publicKey ,
65
+ & locals_union1 .privateKey ,
66
+ 1 ) != CX_OK ) {
67
+ ZERO (locals_union1 );
68
+ ZERO (locals_union2 );
69
+ return ;
70
+ }
55
71
ZERO (locals_union1 );
56
72
if (!getEthAddressStringFromKey (& locals_union2 .publicKey ,
57
73
locals_union1 .address ,
58
74
& local_sha3 ,
59
75
chain_config -> chainId )) {
60
- THROW (CX_INVALID_PARAMETER );
76
+ ZERO (locals_union1 );
77
+ ZERO (locals_union2 );
78
+ return ;
61
79
}
62
80
ZERO (locals_union2 );
63
81
@@ -68,8 +86,9 @@ int handle_check_address(check_address_parameters_t* params, chain_config_t* cha
68
86
69
87
if (strcmp (locals_union1 .address , params -> address_to_check + offset_0x ) != 0 ) {
70
88
PRINTF ("Addresses don't match\n" );
71
- return 0 ;
89
+ } else {
90
+ PRINTF ("Addresses match\n" );
91
+ params -> result = 1 ;
72
92
}
73
- PRINTF ("Addresses match\n" );
74
- return 1 ;
93
+ ZERO (locals_union1 );
75
94
}
0 commit comments