MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / TestBIP324PacketVector

Method TestBIP324PacketVector

src/test/bip324_tests.cpp:25–159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23
24struct BIP324Test : BasicTestingSetup {
25void TestBIP324PacketVector(
26 uint32_t in_idx,
27 const std::string& in_priv_ours_hex,
28 const std::string& in_ellswift_ours_hex,
29 const std::string& in_ellswift_theirs_hex,
30 bool in_initiating,
31 const std::string& in_contents_hex,
32 uint32_t in_multiply,
33 const std::string& in_aad_hex,
34 bool in_ignore,
35 const std::string& mid_send_garbage_hex,
36 const std::string& mid_recv_garbage_hex,
37 const std::string& out_session_id_hex,
38 const std::string& out_ciphertext_hex,
39 const std::string& out_ciphertext_endswith_hex)
40{
41 // Convert input from hex to char/byte vectors/arrays.
42 const auto in_priv_ours = ParseHex(in_priv_ours_hex);
43 const auto in_ellswift_ours = ParseHex<std::byte>(in_ellswift_ours_hex);
44 const auto in_ellswift_theirs = ParseHex<std::byte>(in_ellswift_theirs_hex);
45 const auto in_contents = ParseHex<std::byte>(in_contents_hex);
46 const auto in_aad = ParseHex<std::byte>(in_aad_hex);
47 const auto mid_send_garbage = ParseHex<std::byte>(mid_send_garbage_hex);
48 const auto mid_recv_garbage = ParseHex<std::byte>(mid_recv_garbage_hex);
49 const auto out_session_id = ParseHex<std::byte>(out_session_id_hex);
50 const auto out_ciphertext = ParseHex<std::byte>(out_ciphertext_hex);
51 const auto out_ciphertext_endswith = ParseHex<std::byte>(out_ciphertext_endswith_hex);
52
53 // Load keys
54 CKey key;
55 key.Set(in_priv_ours.begin(), in_priv_ours.end(), true);
56 EllSwiftPubKey ellswift_ours(in_ellswift_ours);
57 EllSwiftPubKey ellswift_theirs(in_ellswift_theirs);
58
59 // Instantiate encryption BIP324 cipher.
60 BIP324Cipher cipher(key, ellswift_ours);
61 BOOST_CHECK(!cipher);
62 BOOST_CHECK(cipher.GetOurPubKey() == ellswift_ours);
63 cipher.Initialize(ellswift_theirs, in_initiating);
64 BOOST_CHECK(cipher);
65
66 // Compare session variables.
67 BOOST_CHECK(std::ranges::equal(out_session_id, cipher.GetSessionID()));
68 BOOST_CHECK(std::ranges::equal(mid_send_garbage, cipher.GetSendGarbageTerminator()));
69 BOOST_CHECK(std::ranges::equal(mid_recv_garbage, cipher.GetReceiveGarbageTerminator()));
70
71 // Vector of encrypted empty messages, encrypted in order to seek to the right position.
72 std::vector<std::vector<std::byte>> dummies(in_idx);
73
74 // Seek to the numbered packet.
75 for (uint32_t i = 0; i < in_idx; ++i) {
76 dummies[i].resize(cipher.EXPANSION);
77 cipher.Encrypt({}, {}, true, dummies[i]);
78 }
79
80 // Construct contents and encrypt it.
81 std::vector<std::byte> contents;
82 for (uint32_t i = 0; i < in_multiply; ++i) {

Callers

nothing calls this directly

Calls 15

ParseHexFunction · 0.85
MakeByteSpanFunction · 0.85
GetSessionIDMethod · 0.80
randrangeMethod · 0.80
DecryptLengthMethod · 0.80
SetMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
InitializeMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected