@@ -69,6 +69,12 @@ namespace pcpp
69
69
return be32toh (reservedValue);
70
70
}
71
71
72
+ void WireGuardLayer::setReserved (const std::array<uint8_t , 3 >& reserved)
73
+ {
74
+ wg_common_header* msg = reinterpret_cast <wg_common_header*>(m_Data);
75
+ memcpy (msg->reserved , reserved.data (), 3 );
76
+ }
77
+
72
78
bool WireGuardLayer::isDataValid (const uint8_t * data, size_t dataLen)
73
79
{
74
80
if (dataLen < sizeof (WireGuardLayer::wg_common_header))
@@ -149,6 +155,43 @@ namespace pcpp
149
155
return mac2Array;
150
156
}
151
157
158
+ void WireGuardHandshakeInitiationLayer::setSenderIndex (uint32_t senderIndex)
159
+ {
160
+ wg_handshake_initiation* msg = reinterpret_cast <wg_handshake_initiation*>(m_Data);
161
+ msg->senderIndex = htobe32 (senderIndex);
162
+ }
163
+
164
+ void WireGuardHandshakeInitiationLayer::setInitiatorEphemeral (const std::array<uint8_t , 32 >& initiatorEphemeral)
165
+ {
166
+ wg_handshake_initiation* msg = reinterpret_cast <wg_handshake_initiation*>(m_Data);
167
+ memcpy (msg->initiatorEphemeral , initiatorEphemeral.data (), 32 );
168
+ }
169
+
170
+ void WireGuardHandshakeInitiationLayer::setEncryptedInitiatorStatic (
171
+ const std::array<uint8_t , 48 >& encryptedInitiatorStatic)
172
+ {
173
+ wg_handshake_initiation* msg = reinterpret_cast <wg_handshake_initiation*>(m_Data);
174
+ memcpy (msg->encryptedInitiatorStatic , encryptedInitiatorStatic.data (), 48 );
175
+ }
176
+
177
+ void WireGuardHandshakeInitiationLayer::setEncryptedTimestamp (const std::array<uint8_t , 28 >& encryptedTimestamp)
178
+ {
179
+ wg_handshake_initiation* msg = reinterpret_cast <wg_handshake_initiation*>(m_Data);
180
+ memcpy (msg->encryptedTimestamp , encryptedTimestamp.data (), 28 );
181
+ }
182
+
183
+ void WireGuardHandshakeInitiationLayer::setMac1 (const std::array<uint8_t , 16 >& mac1)
184
+ {
185
+ wg_handshake_initiation* msg = reinterpret_cast <wg_handshake_initiation*>(m_Data);
186
+ memcpy (msg->mac1 , mac1.data (), 16 );
187
+ }
188
+
189
+ void WireGuardHandshakeInitiationLayer::setMac2 (const std::array<uint8_t , 16 >& mac2)
190
+ {
191
+ wg_handshake_initiation* msg = reinterpret_cast <wg_handshake_initiation*>(m_Data);
192
+ memcpy (msg->mac2 , mac2.data (), 16 );
193
+ }
194
+
152
195
// ~~~~~~~~~~~~~~~~~~~~
153
196
// WireGuardHandshakeResponseLayer
154
197
// ~~~~~~~~~~~~~~~~~~~~
@@ -213,6 +256,43 @@ namespace pcpp
213
256
return mac2Array;
214
257
}
215
258
259
+ void WireGuardHandshakeResponseLayer::setSenderIndex (uint32_t senderIndex)
260
+ {
261
+
262
+ wg_handshake_response* msg = reinterpret_cast <wg_handshake_response*>(m_Data);
263
+ msg->senderIndex = htobe32 (senderIndex);
264
+ }
265
+
266
+ void WireGuardHandshakeResponseLayer::setReceiverIndex (uint32_t receiverIndex)
267
+ {
268
+ wg_handshake_response* msg = reinterpret_cast <wg_handshake_response*>(m_Data);
269
+ msg->receiverIndex = htobe32 (receiverIndex);
270
+ }
271
+
272
+ void WireGuardHandshakeResponseLayer::setResponderEphemeral (const std::array<uint8_t , 32 >& responderEphemeral)
273
+ {
274
+ wg_handshake_response* msg = reinterpret_cast <wg_handshake_response*>(m_Data);
275
+ memcpy (msg->responderEphemeral , responderEphemeral.data (), 32 );
276
+ }
277
+
278
+ void WireGuardHandshakeResponseLayer::setEncryptedEmpty (const std::array<uint8_t , 16 >& encryptedEmpty)
279
+ {
280
+ wg_handshake_response* msg = reinterpret_cast <wg_handshake_response*>(m_Data);
281
+ memcpy (msg->encryptedEmpty , encryptedEmpty.data (), 16 );
282
+ }
283
+
284
+ void WireGuardHandshakeResponseLayer::setMac1 (const std::array<uint8_t , 16 >& mac1)
285
+ {
286
+ wg_handshake_response* msg = reinterpret_cast <wg_handshake_response*>(m_Data);
287
+ memcpy (msg->mac1 , mac1.data (), 16 );
288
+ }
289
+
290
+ void WireGuardHandshakeResponseLayer::setMac2 (const std::array<uint8_t , 16 >& mac2)
291
+ {
292
+ wg_handshake_response* msg = reinterpret_cast <wg_handshake_response*>(m_Data);
293
+ memcpy (msg->mac2 , mac2.data (), 16 );
294
+ }
295
+
216
296
// ~~~~~~~~~~~~~~~~~~~~
217
297
// WireGuardCookieReplyLayer
218
298
// ~~~~~~~~~~~~~~~~~~~~
@@ -255,6 +335,24 @@ namespace pcpp
255
335
return encryptedCookieArray;
256
336
}
257
337
338
+ void WireGuardCookieReplyLayer::setReceiverIndex (uint32_t receiverIndex)
339
+ {
340
+ wg_cookie_reply* msg = reinterpret_cast <wg_cookie_reply*>(m_Data);
341
+ msg->receiverIndex = htobe32 (receiverIndex);
342
+ }
343
+
344
+ void WireGuardCookieReplyLayer::setNonce (const std::array<uint8_t , 24 >& nonce)
345
+ {
346
+ wg_cookie_reply* msg = reinterpret_cast <wg_cookie_reply*>(m_Data);
347
+ memcpy (msg->nonce , nonce.data (), 24 );
348
+ }
349
+
350
+ void WireGuardCookieReplyLayer::setEncryptedCookie (const std::array<uint8_t , 32 >& encryptedCookie)
351
+ {
352
+ wg_cookie_reply* msg = reinterpret_cast <wg_cookie_reply*>(m_Data);
353
+ memcpy (msg->encryptedCookie , encryptedCookie.data (), 32 );
354
+ }
355
+
258
356
// ~~~~~~~~~~~~~~~~~~~~
259
357
// WireGuardTransportDataLayer
260
358
// ~~~~~~~~~~~~~~~~~~~~
@@ -293,4 +391,22 @@ namespace pcpp
293
391
return getTransportHeader ()->encryptedData ;
294
392
}
295
393
394
+ void WireGuardTransportDataLayer::setReceiverIndex (uint32_t receiverIndex)
395
+ {
396
+ wg_transport_data* msg = reinterpret_cast <wg_transport_data*>(m_Data);
397
+ msg->receiverIndex = htobe32 (receiverIndex);
398
+ }
399
+
400
+ void WireGuardTransportDataLayer::setCounter (uint64_t counter)
401
+ {
402
+ wg_transport_data* msg = reinterpret_cast <wg_transport_data*>(m_Data);
403
+ msg->counter = htobe64 (counter);
404
+ }
405
+
406
+ void WireGuardTransportDataLayer::setEncryptedData (const uint8_t * encryptedData, size_t encryptedDataLen)
407
+ {
408
+ wg_transport_data* msg = reinterpret_cast <wg_transport_data*>(m_Data);
409
+ memcpy (msg->encryptedData , encryptedData, encryptedDataLen);
410
+ }
411
+
296
412
} // namespace pcpp
0 commit comments