diff --git a/bitcoin/privkey.h b/bitcoin/privkey.h index 59272bf16..c9966f21b 100644 --- a/bitcoin/privkey.h +++ b/bitcoin/privkey.h @@ -4,6 +4,8 @@ #include #include +#define PRIVKEY_LEN 32 + /* General 256-bit secret, which must be private. Used in various places. */ struct secret { u8 data[32]; diff --git a/devtools/onion.c b/devtools/onion.c index 276861c82..33160330f 100644 --- a/devtools/onion.c +++ b/devtools/onion.c @@ -18,8 +18,6 @@ #include #define ASSOC_DATA_SIZE 32 -#define PUBKEY_LEN 33 -#define PRIVKEY_LEN 32 static void do_generate(int argc, char **argv, const u8 assocdata[ASSOC_DATA_SIZE]) @@ -27,7 +25,7 @@ static void do_generate(int argc, char **argv, const tal_t *ctx = talz(NULL, tal_t); int num_hops = argc - 2; struct pubkey *path = tal_arr(ctx, struct pubkey, num_hops); - u8 rawpubkey[PUBKEY_LEN], rawprivkey[PRIVKEY_LEN]; + u8 rawprivkey[PRIVKEY_LEN]; struct secret session_key; struct secret *shared_secrets; struct sphinx_path *sp; @@ -40,7 +38,7 @@ static void do_generate(int argc, char **argv, for (int i = 0; i < num_hops; i++) { size_t klen = strcspn(argv[1 + i], "/"); - if (klen == 2 * PRIVKEY_LEN) { + if (hex_data_size(klen) == PRIVKEY_LEN) { if (!hex_decode(argv[1 + i], klen, rawprivkey, PRIVKEY_LEN)) errx(1, "Invalid private key hex '%s'", argv[1 + i]); @@ -49,25 +47,16 @@ static void do_generate(int argc, char **argv, &path[i].pubkey, rawprivkey) != 1) errx(1, "Could not decode pubkey"); - } else if (klen == 2 * PUBKEY_LEN) { - if (!hex_decode(argv[1 + i], 2 * PUBKEY_LEN, rawpubkey, - PUBKEY_LEN)) { + } else if (hex_data_size(klen) == PUBKEY_CMPR_LEN) { + if (!pubkey_from_hexstr(argv[i + 1], klen, &path[i])) errx(1, "Invalid public key hex '%s'", argv[1 + i]); - } - - if (secp256k1_ec_pubkey_parse(secp256k1_ctx, - &path[i].pubkey, - rawpubkey, PUBKEY_LEN) != 1) - errx(1, "Could not decode pubkey"); } else { - fprintf(stderr, - "Provided key is neither a pubkey nor a " - "privkey: %s\n", - argv[1 + i]); + errx(1, + "Provided key is neither a pubkey nor a privkey: " + "%s\n", + argv[1 + i]); } - fprintf(stderr, "Node %d pubkey %s\n", i, - secp256k1_pubkey_to_hexstr(ctx, &path[i].pubkey)); memset(&hops_data[i], 0, sizeof(hops_data[i])); if (argv[1 + i][klen] != '\0') {