| 638 | } |
| 639 | |
| 640 | static void print_node_id(const char *hsm_secret_path) |
| 641 | { |
| 642 | u32 salt = 0; |
| 643 | struct secret hsm_secret; |
| 644 | struct privkey node_privkey; |
| 645 | struct pubkey node_id; |
| 646 | struct hsm_secret *hsms = load_hsm_secret(tmpctx, hsm_secret_path); |
| 647 | /* Extract first 32 bytes for legacy compatibility */ |
| 648 | memcpy(hsm_secret.data, hsms->secret_data, 32); |
| 649 | |
| 650 | /*~ So, there is apparently a 1 in 2^127 chance that a random value is |
| 651 | * not a valid private key, so this never actually loops. */ |
| 652 | do { |
| 653 | /*~ ccan/crypto/hkdf_sha256 implements RFC5869 "Hardened Key |
| 654 | * Derivation Functions". That means that if a derived key |
| 655 | * leaks somehow, the other keys are not compromised. */ |
| 656 | hkdf_sha256(&node_privkey, sizeof(node_privkey), |
| 657 | &salt, sizeof(salt), |
| 658 | &hsm_secret, |
| 659 | sizeof(hsm_secret), |
| 660 | "nodeid", 6); |
| 661 | salt++; |
| 662 | } while (!secp256k1_ec_pubkey_create(secp256k1_ctx, &node_id.pubkey, |
| 663 | node_privkey.secret.data)); |
| 664 | |
| 665 | printf("%s\n", fmt_pubkey(tmpctx, &node_id)); |
| 666 | } |
| 667 | |
| 668 | int main(int argc, char *argv[]) |
| 669 | { |
no test coverage detected