onion_key: allowing both odd and even pubkeys
output compressed public keys; accept compressed pubkey in test_onion
This commit is contained in:
parent
2042e1cdb7
commit
9ffac49c6f
|
@ -20,6 +20,7 @@ static void random_bytes(void *dst, size_t n)
|
|||
d[i] = random() % 256;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* Compressed key would start with 0x3? Subtract from group. Thanks
|
||||
* Greg Maxwell. */
|
||||
static void flip_key(struct seckey *seckey)
|
||||
|
@ -47,6 +48,7 @@ static void flip_key(struct seckey *seckey)
|
|||
seckey->u.be64[i] = cpu_to_be64(v);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
int main(int argc, char *argv[])
|
||||
|
@ -97,7 +99,7 @@ static void random_key(secp256k1_context *ctx,
|
|||
|
||||
/* We don't want to spend a byte encoding sign, so make sure it's 0x2 */
|
||||
static void gen_keys(secp256k1_context *ctx,
|
||||
struct seckey *seckey, struct onion_pubkey *pubkey)
|
||||
struct seckey *seckey, struct compressed_pubkey *pubkey)
|
||||
{
|
||||
unsigned char tmp[33];
|
||||
secp256k1_pubkey pkey;
|
||||
|
@ -108,16 +110,18 @@ static void gen_keys(secp256k1_context *ctx,
|
|||
secp256k1_ec_pubkey_serialize(ctx, tmp, &len, &pkey,
|
||||
SECP256K1_EC_COMPRESSED);
|
||||
assert(len == sizeof(tmp));
|
||||
#if 0
|
||||
if (tmp[0] == 0x3)
|
||||
flip_key(seckey);
|
||||
memcpy(pubkey, tmp+1, sizeof(*pubkey));
|
||||
#endif
|
||||
memcpy(pubkey, tmp, sizeof(*pubkey));
|
||||
}
|
||||
|
||||
void print_keypair(int pub, int priv)
|
||||
{
|
||||
secp256k1_context *ctx;
|
||||
struct seckey seckey;
|
||||
struct onion_pubkey pubkey;
|
||||
struct compressed_pubkey pubkey;
|
||||
char sechex[hex_str_size(sizeof(seckey))];
|
||||
char pubhex[hex_str_size(sizeof(pubkey))];
|
||||
|
||||
|
|
|
@ -11,6 +11,11 @@ struct seckey {
|
|||
} u;
|
||||
};
|
||||
|
||||
/* First byte is 0x02 or 0x03 indicating even or odd y */
|
||||
struct compressed_pubkey {
|
||||
unsigned char u8[33];
|
||||
};
|
||||
|
||||
/* Prepend 0x02 to get pubkey for libsecp256k1 */
|
||||
struct onion_pubkey {
|
||||
unsigned char u8[32];
|
||||
|
|
|
@ -588,9 +588,9 @@ bool peel_onion(struct onion *onion,
|
|||
static bool parse_onion_pubkey(secp256k1_context *ctx,
|
||||
const char *arg, secp256k1_pubkey *pubkey)
|
||||
{
|
||||
unsigned char tmp[33] = { 0x2 };
|
||||
unsigned char tmp[33] = { };
|
||||
|
||||
if (!hex_decode(arg, strlen(arg), tmp + 1, sizeof(tmp) - 1))
|
||||
if (!hex_decode(arg, strlen(arg), tmp, sizeof(tmp)))
|
||||
return false;
|
||||
|
||||
return secp256k1_ec_pubkey_parse(ctx, pubkey, tmp, sizeof(tmp));
|
||||
|
|
Loading…
Reference in New Issue