@@ -522,41 +522,6 @@ bool keystore_bip39_mnemonic_to_seed(const char* mnemonic, uint8_t* seed_out, si
522
522
return bip39_mnemonic_to_bytes (NULL , mnemonic , seed_out , 32 , seed_len_out ) == WALLY_OK ;
523
523
}
524
524
525
- static bool _get_xprv (const uint32_t * keypath , const size_t keypath_len , struct ext_key * xprv_out )
526
- {
527
- if (keystore_is_locked ()) {
528
- return false;
529
- }
530
-
531
- uint8_t bip39_seed [64 ] = {0 };
532
- UTIL_CLEANUP_64 (bip39_seed );
533
- if (!keystore_copy_bip39_seed (bip39_seed )) {
534
- return false;
535
- }
536
- struct ext_key xprv_master __attribute__((__cleanup__ (keystore_zero_xkey ))) = {0 };
537
-
538
- if (bip32_key_from_seed (
539
- bip39_seed , BIP32_ENTROPY_LEN_512 , BIP32_VER_MAIN_PRIVATE , 0 , & xprv_master ) !=
540
- WALLY_OK ) {
541
- return false;
542
- }
543
- util_zero (bip39_seed , sizeof (bip39_seed ));
544
- if (keypath_len == 0 ) {
545
- * xprv_out = xprv_master ;
546
- } else if (
547
- bip32_key_from_parent_path (
548
- & xprv_master , keypath , keypath_len , BIP32_FLAG_KEY_PRIVATE , xprv_out ) != WALLY_OK ) {
549
- keystore_zero_xkey (xprv_out );
550
- return false;
551
- }
552
- return true;
553
- }
554
-
555
- void keystore_zero_xkey (struct ext_key * xkey )
556
- {
557
- util_zero (xkey , sizeof (struct ext_key ));
558
- }
559
-
560
525
bool keystore_get_bip39_word (uint16_t idx , char * * word_out )
561
526
{
562
527
return bip39_get_word (NULL , idx , word_out ) == WALLY_OK ;
@@ -569,18 +534,17 @@ bool keystore_secp256k1_nonce_commit(
569
534
const uint8_t * host_commitment ,
570
535
uint8_t * signer_commitment_out )
571
536
{
572
- struct ext_key xprv __attribute__((__cleanup__ (keystore_zero_xkey ))) = {0 };
573
- if (!_get_xprv (keypath , keypath_len , & xprv )) {
537
+ uint8_t private_key [32 ] = {0 };
538
+ UTIL_CLEANUP_32 (private_key );
539
+ if (!rust_secp256k1_get_private_key (
540
+ keypath , keypath_len , rust_util_bytes_mut (private_key , sizeof (private_key )))) {
574
541
return false;
575
542
}
543
+
576
544
const secp256k1_context * ctx = wally_get_secp_context ();
577
545
secp256k1_ecdsa_s2c_opening signer_commitment ;
578
546
if (!secp256k1_ecdsa_anti_exfil_signer_commit (
579
- ctx ,
580
- & signer_commitment ,
581
- msg32 ,
582
- xprv .priv_key + 1 , // first byte is 0,
583
- host_commitment )) {
547
+ ctx , & signer_commitment , msg32 , private_key , host_commitment )) {
584
548
return false;
585
549
}
586
550
@@ -601,19 +565,17 @@ bool keystore_secp256k1_sign(
601
565
if (keystore_is_locked ()) {
602
566
return false;
603
567
}
604
- struct ext_key xprv __attribute__((__cleanup__ (keystore_zero_xkey ))) = {0 };
605
- if (!_get_xprv (keypath , keypath_len , & xprv )) {
568
+ uint8_t private_key [32 ] = {0 };
569
+ UTIL_CLEANUP_32 (private_key );
570
+ if (!rust_secp256k1_get_private_key (
571
+ keypath , keypath_len , rust_util_bytes_mut (private_key , sizeof (private_key )))) {
606
572
return false;
607
573
}
574
+
608
575
const secp256k1_context * ctx = wally_get_secp_context ();
609
576
secp256k1_ecdsa_signature secp256k1_sig = {0 };
610
577
if (!secp256k1_anti_exfil_sign (
611
- ctx ,
612
- & secp256k1_sig ,
613
- msg32 ,
614
- xprv .priv_key + 1 , // first byte is 0
615
- host_nonce32 ,
616
- recid_out )) {
578
+ ctx , & secp256k1_sig , msg32 , private_key , host_nonce32 , recid_out )) {
617
579
return false;
618
580
}
619
581
if (!secp256k1_ecdsa_signature_serialize_compact (ctx , sig_compact_out , & secp256k1_sig )) {
@@ -687,13 +649,15 @@ static bool _schnorr_keypair(
687
649
if (keystore_is_locked ()) {
688
650
return false;
689
651
}
690
- struct ext_key xprv __attribute__((__cleanup__ (keystore_zero_xkey ))) = {0 };
691
- if (!_get_xprv (keypath , keypath_len , & xprv )) {
652
+ uint8_t private_key [32 ] = {0 };
653
+ UTIL_CLEANUP_32 (private_key );
654
+ if (!rust_secp256k1_get_private_key (
655
+ keypath , keypath_len , rust_util_bytes_mut (private_key , sizeof (private_key )))) {
692
656
return false;
693
657
}
694
- const uint8_t * secret_key = xprv . priv_key + 1 ; // first byte is 0;
658
+
695
659
const secp256k1_context * ctx = wally_get_secp_context ();
696
- if (!secp256k1_keypair_create (ctx , keypair_out , secret_key )) {
660
+ if (!secp256k1_keypair_create (ctx , keypair_out , private_key )) {
697
661
return false;
698
662
}
699
663
if (tweak != NULL ) {
0 commit comments