@@ -43,6 +43,7 @@ FUZZ_TARGET(p2p_v2_transport_serialization)
43
43
44
44
// There is no sense in providing a mac assist if the length is incorrect.
45
45
bool mac_assist = length_assist && fdp.ConsumeBool ();
46
+ auto aad = fdp.ConsumeBytes <std::byte>(fdp.ConsumeIntegralInRange (0 , 1024 ));
46
47
auto encrypted_packet = fdp.ConsumeRemainingBytes <uint8_t >();
47
48
bool is_decoy_packet{false };
48
49
@@ -56,17 +57,18 @@ FUZZ_TARGET(p2p_v2_transport_serialization)
56
57
57
58
if (mac_assist) {
58
59
std::array<std::byte, RFC8439_EXPANSION> tag;
59
- ComputeRFC8439Tag (GetPoly1305Key (c20), {} ,
60
+ ComputeRFC8439Tag (GetPoly1305Key (c20), aad ,
60
61
{reinterpret_cast <std::byte*>(encrypted_packet.data ()) + BIP324_LENGTH_FIELD_LEN,
61
- encrypted_packet.size () - BIP324_LENGTH_FIELD_LEN - RFC8439_EXPANSION}, tag);
62
+ encrypted_packet.size () - BIP324_LENGTH_FIELD_LEN - RFC8439_EXPANSION},
63
+ tag);
62
64
memcpy (encrypted_packet.data () + encrypted_packet.size () - RFC8439_EXPANSION, tag.data (), RFC8439_EXPANSION);
63
65
64
66
std::vector<std::byte> dec_header_and_contents (
65
- encrypted_packet.size () - BIP324_LENGTH_FIELD_LEN - RFC8439_EXPANSION);
66
- RFC8439Decrypt ({} , key_P, nonce,
67
+ encrypted_packet.size () - BIP324_LENGTH_FIELD_LEN - RFC8439_EXPANSION);
68
+ RFC8439Decrypt (aad , key_P, nonce,
67
69
{reinterpret_cast <std::byte*>(encrypted_packet.data () + BIP324_LENGTH_FIELD_LEN),
68
70
encrypted_packet.size () - BIP324_LENGTH_FIELD_LEN},
69
- dec_header_and_contents);
71
+ dec_header_and_contents);
70
72
if (BIP324HeaderFlags ((uint8_t )dec_header_and_contents.at (0 ) & BIP324_IGNORE) != BIP324_NONE) {
71
73
is_decoy_packet = true ;
72
74
}
@@ -83,7 +85,7 @@ FUZZ_TARGET(p2p_v2_transport_serialization)
83
85
const std::chrono::microseconds m_time{std::numeric_limits<int64_t >::max ()};
84
86
bool reject_message{true };
85
87
bool disconnect{true };
86
- CNetMessage result{deserializer.GetMessage (m_time, reject_message, disconnect)};
88
+ CNetMessage result{deserializer.GetMessage (m_time, reject_message, disconnect, aad )};
87
89
88
90
if (mac_assist) {
89
91
assert (!disconnect);
@@ -104,6 +106,7 @@ FUZZ_TARGET(p2p_v2_transport_serialization)
104
106
105
107
std::vector<unsigned char > header;
106
108
auto msg = CNetMsgMaker{result.m_recv .GetVersion ()}.Make (result.m_type , MakeUCharSpan (result.m_recv ));
109
+ msg.aad = aad;
107
110
// if decryption succeeds, encryption must succeed
108
111
assert (serializer.prepareForTransport (msg, header));
109
112
}
0 commit comments