@@ -113,6 +113,7 @@ typedef struct {
113
113
114
114
// NOTE: Uses global hdPath / HDPATH_LEN_DEFAULT
115
115
static zxerr_t crypto_extractPublicKey (uint8_t * pubKey , uint16_t pubKeyLen ) {
116
+ io_seproxyhal_io_heartbeat ();
116
117
if (pubKey == NULL || pubKeyLen < PK_LEN_SECP256K1 ) {
117
118
return zxerr_invalid_crypto_settings ;
118
119
}
@@ -128,6 +129,7 @@ static zxerr_t crypto_extractPublicKey(uint8_t *pubKey, uint16_t pubKeyLen) {
128
129
zxerr_t error = zxerr_unknown ;
129
130
CATCH_CXERROR (os_derive_bip32_no_throw (CX_CURVE_256K1 , hdPath .secp256k1_path , HDPATH_LEN_BIP44 , privateKeyData , NULL ));
130
131
CATCH_CXERROR (cx_ecfp_init_private_key_no_throw (CX_CURVE_256K1 , privateKeyData , SK_SECP256K1_SIZE , & cx_privateKey ));
132
+ io_seproxyhal_io_heartbeat ();
131
133
CATCH_CXERROR (cx_ecfp_init_public_key_no_throw (CX_CURVE_256K1 , NULL , 0 , & cx_publicKey ));
132
134
CATCH_CXERROR (cx_ecfp_generate_pair_no_throw (CX_CURVE_256K1 , & cx_publicKey , & cx_privateKey , 1 ));
133
135
@@ -149,6 +151,7 @@ static zxerr_t crypto_extractPublicKey(uint8_t *pubKey, uint16_t pubKeyLen) {
149
151
// handleGetAddrSecp256K1
150
152
// NOTE: Uses global hdPath / HDPATH_LEN_DEFAULT (indirectly)
151
153
zxerr_t crypto_fillAddress_secp256k1 (uint8_t * buffer , uint16_t buffer_len , uint16_t * replyLen ) {
154
+ io_seproxyhal_io_heartbeat ();
152
155
if (buffer_len < sizeof (answer_t )) {
153
156
return zxerr_unknown ;
154
157
}
@@ -160,6 +163,7 @@ zxerr_t crypto_fillAddress_secp256k1(uint8_t *buffer, uint16_t buffer_len, uint1
160
163
answer_t * const answer = (answer_t * )buffer ;
161
164
162
165
CHECK_ZXERR (crypto_extractPublicKey (answer -> publicKey , sizeof_field (answer_t , publicKey )));
166
+ io_seproxyhal_io_heartbeat ();
163
167
164
168
address_temp_t address_temp ;
165
169
@@ -179,6 +183,7 @@ zxerr_t crypto_fillAddress_secp256k1(uint8_t *buffer, uint16_t buffer_len, uint1
179
183
// 7. 25 bytes BTC address = [extended ripemd-160][checksum]
180
184
// Encode as base58
181
185
size_t outLen = sizeof_field (answer_t , address );
186
+ io_seproxyhal_io_heartbeat ();
182
187
int err =
183
188
encode_base58 (address_temp .address , VERSION_SIZE + CX_RIPEMD160_SIZE + CHECKSUM_SIZE , answer -> address , & outLen );
184
189
if (err != 0 ) {
@@ -224,6 +229,7 @@ zxerr_t crypto_fillDeviceSeed(uint8_t *device_seed) {
224
229
// handleInitTX step 1/2
225
230
zxerr_t crypto_extracttx_sapling (uint8_t * buffer , uint16_t bufferLen , const uint8_t * txdata , const uint16_t txdatalen ) {
226
231
ZEMU_LOGF (100 , "crypto_extracttx_sapling\n" );
232
+ io_seproxyhal_io_heartbeat ();
227
233
228
234
MEMZERO (buffer , bufferLen );
229
235
uint8_t t_in_len = * txdata ;
@@ -275,6 +281,7 @@ zxerr_t crypto_extracttx_sapling(uint8_t *buffer, uint16_t bufferLen, const uint
275
281
}
276
282
start += T_IN_INPUT_LEN ;
277
283
}
284
+ io_seproxyhal_io_heartbeat ();
278
285
279
286
for (int i = 0 ; i < t_out_len ; i ++ ) {
280
287
uint8_t * addr = (uint8_t * )(start + INDEX_INPUT_TOUT_ADDR );
@@ -292,6 +299,7 @@ zxerr_t crypto_extracttx_sapling(uint8_t *buffer, uint16_t bufferLen, const uint
292
299
}
293
300
start += T_OUT_INPUT_LEN ;
294
301
}
302
+ io_seproxyhal_io_heartbeat ();
295
303
296
304
for (int i = 0 ; i < spend_len ; i ++ ) {
297
305
pars_ctx .offset = 0 ;
@@ -325,6 +333,7 @@ zxerr_t crypto_extracttx_sapling(uint8_t *buffer, uint16_t bufferLen, const uint
325
333
}
326
334
start += SPEND_INPUT_LEN ;
327
335
}
336
+ io_seproxyhal_io_heartbeat ();
328
337
329
338
for (int i = 0 ; i < output_len ; i ++ ) {
330
339
uint8_t * div = start + INDEX_INPUT_OUTPUTDIV ;
@@ -362,6 +371,7 @@ zxerr_t crypto_extracttx_sapling(uint8_t *buffer, uint16_t bufferLen, const uint
362
371
}
363
372
start += OUTPUT_INPUT_LEN ;
364
373
}
374
+ io_seproxyhal_io_heartbeat ();
365
375
366
376
uint64_t tx_value__flash = get_totalvalue ();
367
377
#ifdef HAVE_ZIP0317
@@ -430,6 +440,7 @@ zxerr_t crypto_extract_spend_proofkeyandrnd(uint8_t *buffer, uint16_t bufferLen)
430
440
431
441
// handleExtractOutputData
432
442
zxerr_t crypto_extract_output_rnd (uint8_t * buffer , uint16_t bufferLen , uint16_t * replyLen ) {
443
+ io_seproxyhal_io_heartbeat ();
433
444
if (!outputlist_more_extract ()) {
434
445
return zxerr_unknown ;
435
446
}
@@ -469,6 +480,7 @@ zxerr_t crypto_check_prevouts(uint8_t *buffer, uint16_t bufferLen, const uint8_t
469
480
if (get_state () != STATE_CHECKING_ALL_TXDATA ) {
470
481
return zxerr_unknown ;
471
482
}
483
+ io_seproxyhal_io_heartbeat ();
472
484
473
485
uint8_t hash [HASH_SIZE ] = {0 };
474
486
size_t prevouts_hash_offset = 0 ;
@@ -499,6 +511,7 @@ zxerr_t crypto_check_sequence(uint8_t *buffer, uint16_t bufferLen, const uint8_t
499
511
500
512
uint8_t hash [HASH_SIZE ] = {0 };
501
513
size_t sequence_hash_offset = 0 ;
514
+ io_seproxyhal_io_heartbeat ();
502
515
503
516
if (tx_version == TX_VERSION_SAPLING ) {
504
517
sapling_transparent_sequence_hash (txdata , hash );
@@ -708,6 +721,7 @@ zxerr_t crypto_checkspend_sapling(
708
721
}
709
722
710
723
// NOTE: This use is probably correct
724
+ io_seproxyhal_io_heartbeat ();
711
725
compute_nullifier (tmp_buf -> ncm_full , notepos , tmp .step4 .nsk , tmp_buf -> nf );
712
726
if (MEMCMP (tmp_buf -> nf , start_spenddata + INDEX_SPEND_NF + i * SPEND_TX_LEN , NULLIFIER_SIZE ) != 0 ) {
713
727
CHECK_ZXERROR_AND_CLEAN (zxerr_unknown )
@@ -903,6 +917,7 @@ typedef struct {
903
917
// handleCheckandSign step 8/11
904
918
zxerr_t crypto_checkencryptions_sapling (uint8_t * buffer , uint16_t bufferLen , const uint8_t * txdata ) {
905
919
zemu_log_stack ("crypto_checkencryptions_sapling" );
920
+ io_seproxyhal_io_heartbeat ();
906
921
MEMZERO (buffer , bufferLen );
907
922
tmp_enc * tmp = (tmp_enc * )buffer ;
908
923
@@ -927,6 +942,7 @@ zxerr_t crypto_checkencryptions_sapling(uint8_t *buffer, uint16_t bufferLen, con
927
942
// get shared key (used as encryption key) from esk, epk and pkd
928
943
ka_to_key (tmp -> step1 .esk , (uint8_t * )item -> pkd , tmp -> step1 .epk , tmp -> step2 .sharedkey );
929
944
CHECK_APP_CANARY ()
945
+ io_seproxyhal_io_heartbeat ();
930
946
// encode (div, value rseed and memotype) into step2.compactout ready to be
931
947
// encrypted
932
948
prepare_compact_note ((uint8_t * )item -> div , item -> value , (uint8_t * )item -> rseed , item -> memotype ,
@@ -938,6 +954,7 @@ zxerr_t crypto_checkencryptions_sapling(uint8_t *buffer, uint16_t bufferLen, con
938
954
// step2.compactoutput (reusing the same memory for input and output)
939
955
chacha (tmp -> step2 .compactout , tmp -> step2 .compactout , COMPACT_OUT_SIZE , tmp -> step2 .sharedkey , tmp -> step2 .chachanonce ,
940
956
1 );
957
+ io_seproxyhal_io_heartbeat ();
941
958
CHECK_APP_CANARY ()
942
959
// check that the computed encryption is the same as that provided in the
943
960
// transaction data
@@ -997,6 +1014,7 @@ zxerr_t crypto_checkencryptions_sapling(uint8_t *buffer, uint16_t bufferLen, con
997
1014
// that provided in the transaction data
998
1015
chacha (tmp -> step4b .encciph , tmp -> step4b .encciph , ENC_CIPHER_SIZE , tmp -> step4b .outkey , tmp -> step4b .chachanonce ,
999
1016
1 );
1017
+ io_seproxyhal_io_heartbeat ();
1000
1018
if (MEMCMP (tmp -> step4b .encciph , start_outputdata + INDEX_OUTPUT_OUT + i * OUTPUT_TX_LEN , ENC_CIPHER_SIZE ) != 0 ) {
1001
1019
return zxerr_unknown ;
1002
1020
}
@@ -1135,6 +1153,7 @@ zxerr_t crypto_sign_and_check_transparent(
1135
1153
size_t signatureLen = DER_MAX_SIZE ;
1136
1154
CATCH_CXERROR (cx_ecdsa_sign_no_throw (& cx_privateKey , CX_RND_RFC6979 | CX_LAST , CX_SHA256 , message_digest ,
1137
1155
CX_SHA256_SIZE , signature -> step1 .der_signature , & signatureLen , & info ));
1156
+ io_seproxyhal_io_heartbeat ();
1138
1157
1139
1158
if (convertDERtoRSV (signature -> step1 .der_signature , info , signature -> step1 .r , signature -> step1 .s ,
1140
1159
& signature -> step1 .v ) != no_error ||
@@ -1262,6 +1281,7 @@ zxerr_t crypto_ivk_sapling(uint8_t *buffer, uint16_t bufferLen, uint32_t zip32_a
1262
1281
1263
1282
tmp_sapling_ivk_and_default_div * out = (tmp_sapling_ivk_and_default_div * )buffer ;
1264
1283
MEMZERO (buffer , bufferLen );
1284
+ io_seproxyhal_io_heartbeat ();
1265
1285
1266
1286
CHECK_APP_CANARY ()
1267
1287
// get incomming viewing key
@@ -1270,6 +1290,7 @@ zxerr_t crypto_ivk_sapling(uint8_t *buffer, uint16_t bufferLen, uint32_t zip32_a
1270
1290
CHECK_APP_CANARY ()
1271
1291
// get default diversifier for start index 0
1272
1292
diversifier_find_valid (zip32_account , out -> default_div );
1293
+ io_seproxyhal_io_heartbeat ();
1273
1294
1274
1295
CHECK_APP_CANARY ()
1275
1296
* replyLen = IVK_SIZE + DIV_SIZE ;
@@ -1421,6 +1442,7 @@ zxerr_t crypto_fillAddress_sapling(uint8_t *buffer, uint16_t bufferLen, uint32_t
1421
1442
if (bufferLen < sizeof (tmp_buf_addr_s )) {
1422
1443
return zxerr_unknown ;
1423
1444
}
1445
+ io_seproxyhal_io_heartbeat ();
1424
1446
1425
1447
zemu_log_stack ("crypto_fillAddress_sapling" );
1426
1448
tmp_buf_addr_s * const out = (tmp_buf_addr_s * )buffer ;
@@ -1429,6 +1451,7 @@ zxerr_t crypto_fillAddress_sapling(uint8_t *buffer, uint16_t bufferLen, uint32_t
1429
1451
get_pkd_from_seed (p , out -> startindex , out -> diversifier , out -> pkd );
1430
1452
MEMZERO (out + DIV_SIZE , MAX_SIZE_BUF_ADDR - DIV_SIZE );
1431
1453
CHECK_APP_CANARY ()
1454
+ io_seproxyhal_io_heartbeat ();
1432
1455
1433
1456
if (bech32EncodeFromBytes (out -> address_bech32 , sizeof_field (tmp_buf_addr_s , address_bech32 ), BECH32_HRP ,
1434
1457
out -> address_raw , sizeof_field (tmp_buf_addr_s , address_raw ), 1 ,
0 commit comments