55#include "feature_performPrivacyOperation.h"
66
77#define P2_PUBLIC_ENCRYPTION_KEY 0x00
8- #define P2_SHARED_SECRET 0x01
8+ #define P2_SHARED_SECRET 0x01
99
1010void decodeScalar (const uint8_t * scalarIn , uint8_t * scalarOut ) {
11- for (uint8_t i = 0 ; i < 32 ; i ++ ) {
12- switch (i ) {
11+ for (uint8_t i = 0 ; i < 32 ; i ++ ) {
12+ switch (i ) {
1313 case 0 :
1414 scalarOut [0 ] = (scalarIn [31 ] & 0x7f ) | 0x40 ;
1515 break ;
@@ -18,16 +18,16 @@ void decodeScalar(const uint8_t *scalarIn, uint8_t *scalarOut) {
1818 break ;
1919 default :
2020 scalarOut [i ] = scalarIn [31 - i ];
21- }
21+ }
2222 }
2323}
2424
2525void handlePerformPrivacyOperation (uint8_t p1 ,
26- uint8_t p2 ,
27- uint8_t * dataBuffer ,
28- uint16_t dataLength ,
29- unsigned int * flags ,
30- unsigned int * tx ) {
26+ uint8_t p2 ,
27+ uint8_t * dataBuffer ,
28+ uint16_t dataLength ,
29+ unsigned int * flags ,
30+ unsigned int * tx ) {
3131 UNUSED (dataLength );
3232 uint8_t privateKeyData [INT256_LENGTH ];
3333 uint8_t privateKeyDataSwapped [INT256_LENGTH ];
@@ -38,14 +38,11 @@ void handlePerformPrivacyOperation(uint8_t p1,
3838 if (dataLength < 1 + 4 * bip32PathLength ) {
3939 THROW (0x6700 );
4040 }
41- }
42- else
43- if (p2 == P2_SHARED_SECRET ) {
41+ } else if (p2 == P2_SHARED_SECRET ) {
4442 if (dataLength < 1 + 4 * bip32PathLength + 32 ) {
4543 THROW (0x6700 );
46- }
47- }
48- else {
44+ }
45+ } else {
4946 THROW (0x6B00 );
5047 }
5148 cx_ecfp_private_key_t privateKey ;
@@ -59,7 +56,7 @@ void handlePerformPrivacyOperation(uint8_t p1,
5956 for (uint8_t i = 0 ; i < bip32PathLength ; i ++ ) {
6057 bip32Path [i ] = U4BE (dataBuffer , 0 );
6158 dataBuffer += 4 ;
62- }
59+ }
6360 os_perso_derive_node_bip32 (
6461 CX_CURVE_256K1 ,
6562 bip32Path ,
@@ -71,19 +68,21 @@ void handlePerformPrivacyOperation(uint8_t p1,
7168 getEthAddressStringFromKey (& tmpCtx .publicKeyContext .publicKey ,
7269 tmpCtx .publicKeyContext .address ,
7370 & global_sha3 ,
74- chainConfig -> chainId );
71+ chainConfig -> chainId );
7572 if (p2 == P2_PUBLIC_ENCRYPTION_KEY ) {
7673 decodeScalar (privateKeyData , privateKeyDataSwapped );
7774 cx_ecfp_init_private_key (CX_CURVE_Curve25519 , privateKeyDataSwapped , 32 , & privateKey );
78- cx_ecfp_generate_pair (CX_CURVE_Curve25519 , & tmpCtx .publicKeyContext .publicKey , & privateKey , 1 );
75+ cx_ecfp_generate_pair (CX_CURVE_Curve25519 ,
76+ & tmpCtx .publicKeyContext .publicKey ,
77+ & privateKey ,
78+ 1 );
7979 explicit_bzero (privateKeyDataSwapped , sizeof (privateKeyDataSwapped ));
80- }
81- else {
80+ } else {
8281 memmove (tmpCtx .publicKeyContext .publicKey .W + 1 , dataBuffer , 32 );
8382 status = cx_x25519 (tmpCtx .publicKeyContext .publicKey .W + 1 , privateKeyData , 32 );
8483 }
8584 explicit_bzero (& privateKey , sizeof (privateKey ));
86- explicit_bzero (privateKeyData , sizeof (privateKeyData ));
85+ explicit_bzero (privateKeyData , sizeof (privateKeyData ));
8786
8887 if (status != CX_OK ) {
8988 THROW (0x6A80 );
@@ -97,24 +96,27 @@ void handlePerformPrivacyOperation(uint8_t p1,
9796 THROW (0x9000 );
9897 }
9998#ifndef NO_CONSENT
100- else {
99+ else {
101100 snprintf (strings .common .fullAddress ,
102101 sizeof (strings .common .fullAddress ),
103102 "0x%.*s" ,
104103 40 ,
105104 tmpCtx .publicKeyContext .address );
106- for (uint8_t i = 0 ; i < 32 ; i ++ ) {
105+ for (uint8_t i = 0 ; i < 32 ; i ++ ) {
107106 privateKeyData [i ] = tmpCtx .publicKeyContext .publicKey .W [32 - i ];
108107 }
109- snprintf (strings .common .fullAmount , sizeof (strings .common .fullAmount ) - 1 , "%.*H" , 32 , privateKeyData );
108+ snprintf (strings .common .fullAmount ,
109+ sizeof (strings .common .fullAmount ) - 1 ,
110+ "%.*H" ,
111+ 32 ,
112+ privateKeyData );
110113 if (p2 == P2_PUBLIC_ENCRYPTION_KEY ) {
111114 ux_flow_init (0 , ux_display_privacy_public_key_flow , NULL );
112- }
113- else {
115+ } else {
114116 ux_flow_init (0 , ux_display_privacy_shared_secret_flow , NULL );
115117 }
116118
117- * flags |= IO_ASYNCH_REPLY ;
119+ * flags |= IO_ASYNCH_REPLY ;
118120 }
119121#endif // NO_CONSENT
120122}
0 commit comments