Skip to content

Commit c2a6b05

Browse files
committed
test_onion.c: generate message predictably
Generate sample encrypted payload based on actual pubkey, not libsecp256k1's internal representation of the pubkey.
1 parent a517b2c commit c2a6b05

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

test/test_onion.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -596,12 +596,17 @@ static bool parse_onion_pubkey(secp256k1_context *ctx,
596596
return secp256k1_ec_pubkey_parse(ctx, pubkey, tmp, sizeof(tmp));
597597
}
598598

599-
static char *make_message(const secp256k1_pubkey *pubkey)
599+
static char *make_message(secp256k1_context *ctx,
600+
const secp256k1_pubkey *pubkey)
600601
{
601602
char *m;
603+
unsigned char tmp[33];
604+
size_t len;
602605
char hexstr[hex_str_size(20)];
603606

604-
hex_encode(pubkey, 20, hexstr, sizeof(hexstr));
607+
secp256k1_ec_pubkey_serialize(ctx, tmp, &len, pubkey,
608+
SECP256K1_EC_COMPRESSED);
609+
hex_encode(tmp+1, 20, hexstr, sizeof(hexstr));
605610
asprintf(&m, "Message for %s...", hexstr);
606611
return m;
607612
}
@@ -643,7 +648,7 @@ int main(int argc, char *argv[])
643648
for (i = 1; i < argc; i++) {
644649
if (!parse_onion_pubkey(ctx, argv[i], &pubkeys[i-1]))
645650
errx(1, "Bad pubkey '%s'", argv[i]);
646-
msgs[i-1] = make_message(&pubkeys[i-1]);
651+
msgs[i-1] = make_message(ctx, &pubkeys[i-1]);
647652
}
648653

649654
if (!create_onion(pubkeys, msgs, argc - 1, &onion))
@@ -670,7 +675,7 @@ int main(int argc, char *argv[])
670675

671676
if (!decrypt_onion(&seckey, &onion, &enckey, &pad_iv))
672677
errx(1, "Failed decrypting onion for '%s'", argv[1]);
673-
if (strncmp((char *)myhop(&onion)->msg, make_message(&pubkey),
678+
if (strncmp((char *)myhop(&onion)->msg, make_message(ctx, &pubkey),
674679
sizeof(myhop(&onion)->msg)))
675680
errx(1, "Bad message '%s'", (char *)myhop(&onion)->msg);
676681
if (!peel_onion(&onion, &enckey, &pad_iv))

0 commit comments

Comments
 (0)