|
28 | 28 |
|
29 | 29 | #include <rust/rust.h> |
30 | 30 | #include <secp256k1_ecdsa_s2c.h> |
31 | | -#include <secp256k1_extrakeys.h> |
32 | | -#include <secp256k1_schnorrsig.h> |
33 | 31 |
|
34 | 32 | // Change this ONLY via keystore_unlock() or keystore_lock() |
35 | 33 | static bool _is_unlocked_device = false; |
@@ -549,94 +547,6 @@ bool keystore_get_u2f_seed(uint8_t* seed_out) |
549 | 547 | return true; |
550 | 548 | } |
551 | 549 |
|
552 | | -bool keystore_get_ed25519_seed(uint8_t* seed_out) |
553 | | -{ |
554 | | - uint8_t bip39_seed[64] = {0}; |
555 | | - UTIL_CLEANUP_64(bip39_seed); |
556 | | - if (!keystore_copy_bip39_seed(bip39_seed)) { |
557 | | - return false; |
558 | | - } |
559 | | - |
560 | | - const uint8_t key[] = "ed25519 seed"; |
561 | | - |
562 | | - // Derive a 64 byte expanded ed25519 private key and put it into seed_out. |
563 | | - memcpy(seed_out, bip39_seed, 64); |
564 | | - do { |
565 | | - rust_hmac_sha512(key, sizeof(key), seed_out, 64, seed_out); |
566 | | - } while (seed_out[31] & 0x20); |
567 | | - |
568 | | - seed_out[0] &= 248; |
569 | | - seed_out[31] &= 127; |
570 | | - seed_out[31] |= 64; |
571 | | - |
572 | | - // Compute chain code and put it into seed_out at offset 64. |
573 | | - uint8_t message[65] = {0}; |
574 | | - message[0] = 0x01; |
575 | | - memcpy(&message[1], bip39_seed, 64); |
576 | | - util_zero(bip39_seed, sizeof(bip39_seed)); |
577 | | - rust_hmac_sha256(key, sizeof(key), message, sizeof(message), &seed_out[64]); |
578 | | - util_zero(message, sizeof(message)); |
579 | | - return true; |
580 | | -} |
581 | | - |
582 | | -static bool _schnorr_keypair( |
583 | | - const secp256k1_context* ctx, |
584 | | - const uint32_t* keypath, |
585 | | - size_t keypath_len, |
586 | | - const uint8_t* tweak, |
587 | | - secp256k1_keypair* keypair_out, |
588 | | - secp256k1_xonly_pubkey* pubkey_out) |
589 | | -{ |
590 | | - if (keystore_is_locked()) { |
591 | | - return false; |
592 | | - } |
593 | | - uint8_t private_key[32] = {0}; |
594 | | - UTIL_CLEANUP_32(private_key); |
595 | | - if (!rust_secp256k1_get_private_key( |
596 | | - keypath, keypath_len, rust_util_bytes_mut(private_key, sizeof(private_key)))) { |
597 | | - return false; |
598 | | - } |
599 | | - |
600 | | - if (!secp256k1_keypair_create(ctx, keypair_out, private_key)) { |
601 | | - return false; |
602 | | - } |
603 | | - if (tweak != NULL) { |
604 | | - if (secp256k1_keypair_xonly_tweak_add(ctx, keypair_out, tweak) != 1) { |
605 | | - return false; |
606 | | - } |
607 | | - } |
608 | | - if (!secp256k1_keypair_xonly_pub(ctx, pubkey_out, NULL, keypair_out)) { |
609 | | - return false; |
610 | | - } |
611 | | - return true; |
612 | | -} |
613 | | - |
614 | | -static void _cleanup_keypair(secp256k1_keypair* keypair) |
615 | | -{ |
616 | | - util_zero(keypair, sizeof(secp256k1_keypair)); |
617 | | -} |
618 | | - |
619 | | -bool keystore_secp256k1_schnorr_sign( |
620 | | - const secp256k1_context* ctx, |
621 | | - const uint32_t* keypath, |
622 | | - size_t keypath_len, |
623 | | - const uint8_t* msg32, |
624 | | - const uint8_t* tweak, |
625 | | - uint8_t* sig64_out) |
626 | | -{ |
627 | | - secp256k1_keypair __attribute__((__cleanup__(_cleanup_keypair))) keypair = {0}; |
628 | | - secp256k1_xonly_pubkey pubkey = {0}; |
629 | | - if (!_schnorr_keypair(ctx, keypath, keypath_len, tweak, &keypair, &pubkey)) { |
630 | | - return false; |
631 | | - } |
632 | | - uint8_t aux_rand[32] = {0}; |
633 | | - random_32_bytes(aux_rand); |
634 | | - if (secp256k1_schnorrsig_sign32(ctx, sig64_out, msg32, &keypair, aux_rand) != 1) { |
635 | | - return false; |
636 | | - } |
637 | | - return secp256k1_schnorrsig_verify(ctx, sig64_out, msg32, 32, &pubkey) == 1; |
638 | | -} |
639 | | - |
640 | 550 | #ifdef TESTING |
641 | 551 | void keystore_mock_unlocked(const uint8_t* seed, size_t seed_len, const uint8_t* bip39_seed) |
642 | 552 | { |
|
0 commit comments