common/test/run-blindedpath_enctlv: use modern functions to create test vector.

And include the final destination enctlv.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2021-11-30 13:36:05 +10:30
parent 1c230eee86
commit e02e0a197d

View File

@ -84,7 +84,7 @@ static void test_decrypt(const struct pubkey *blinding,
mykey = me;
assert(unblind_onion(blinding, test_ecdh, &dummy, &ss));
assert(decrypt_obs2_enctlv(blinding, &ss, enctlv, &next_node, &next_blinding));
assert(decrypt_enctlv(blinding, &ss, enctlv, &next_node, &next_blinding));
pubkey_from_privkey(expected_next_blinding_priv, &expected_next_blinding);
assert(pubkey_eq(&next_blinding, &expected_next_blinding));
@ -106,7 +106,7 @@ static void test_final_decrypt(const struct pubkey *blinding,
mykey = me;
pubkey_from_privkey(me, &my_pubkey);
assert(unblind_onion(blinding, test_ecdh, &dummy, &ss));
assert(decrypt_obs2_final_enctlv(tmpctx, blinding, &ss, enctlv, &my_pubkey,
assert(decrypt_final_enctlv(tmpctx, blinding, &ss, enctlv, &my_pubkey,
&alias, &self_id));
assert(pubkey_eq(&alias, expected_alias));
@ -150,8 +150,8 @@ int main(int argc, char *argv[])
"\t},\n",
type_to_string(tmpctx, struct pubkey, &bob_id));
enctlv = create_obs2_enctlv(tmpctx, &blinding, &alice_id, &bob_id,
0, NULL, &blinding, &alias);
enctlv = create_enctlv(tmpctx, &blinding, &alice_id, &bob_id,
0, NULL, &blinding, &alias);
printf("\t\"encrypted_recipient_data_hex\": \"%s\"\n"
"},\n",
tal_hex(tmpctx, enctlv));
@ -180,8 +180,8 @@ int main(int argc, char *argv[])
type_to_string(tmpctx, struct pubkey, &carol_id),
type_to_string(tmpctx, struct privkey, &override_blinding));
enctlv = create_obs2_enctlv(tmpctx, &blinding, &bob_id, &carol_id,
0, &override_blinding_pub, &blinding, &alias);
enctlv = create_enctlv(tmpctx, &blinding, &bob_id, &carol_id,
0, &override_blinding_pub, &blinding, &alias);
printf("\t\"encrypted_recipient_data_hex\": \"%s\"\n"
"},\n",
tal_hex(tmpctx, enctlv));
@ -209,21 +209,40 @@ int main(int argc, char *argv[])
type_to_string(tmpctx, struct pubkey, &dave_id),
tal_hex(tmpctx, tal_arrz(tmpctx, u8, 35)));
enctlv = create_obs2_enctlv(tmpctx, &blinding, &carol_id, &dave_id,
35, NULL, &blinding, &alias);
enctlv = create_enctlv(tmpctx, &blinding, &carol_id, &dave_id,
35, NULL, &blinding, &alias);
printf("\t\"encrypted_recipient_data_hex\": \"%s\"\n"
"}]\n",
"},\n",
tal_hex(tmpctx, enctlv));
test_decrypt(&blinding_pub, enctlv, &carol, &dave_id, &blinding);
/* FIXME: Add this to the test vectors! */
fclose(stdout);
memset(&self_id, 0x77, sizeof(self_id));
enctlv = create_obs2_final_enctlv(tmpctx, &blinding, &dave_id,
0, &self_id, &alias);
for (size_t i = 0; i < sizeof(self_id); i++)
self_id.data[i] = i+1;
printf("{");
json_strfield("test name", "Final enctlv for Dave");
json_strfield("node_privkey",
type_to_string(tmpctx, struct privkey, &dave));
json_strfield("node_id",
type_to_string(tmpctx, struct pubkey, &dave_id));
json_strfield("blinding_secret",
type_to_string(tmpctx, struct privkey, &blinding));
json_strfield("blinding",
type_to_string(tmpctx, struct pubkey, &blinding_pub));
printf("\t\"encrypted_data_tlv\": {\n"
"\t\t\"self_id\": \"%s\"\n"
"\t},\n",
type_to_string(tmpctx, struct secret, &self_id));
enctlv = create_final_enctlv(tmpctx, &blinding, &dave_id,
0, &self_id, &alias);
printf("\t\"encrypted_recipient_data_hex\": \"%s\"\n",
tal_hex(tmpctx, enctlv));
printf("}]\n");
pubkey_from_privkey(&blinding, &blinding_pub);
test_final_decrypt(&blinding_pub, enctlv, &dave, &alias, &self_id);
common_shutdown();
}