FD.io VPP  v21.01.1
Vector Packet Processing
wireguard_messages.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Doc.ai and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef __included_wg_messages_h__
17 #define __included_wg_messages_h__
18 
19 #include <stdint.h>
22 
23 #define WG_TICK 0.01 /**< WG tick period (s) */
24 #define WHZ (u32) (1/WG_TICK) /**< WG tick frequency */
25 
26 #define NOISE_KEY_LEN_BASE64 ((((NOISE_PUBLIC_KEY_LEN) + 2) / 3) * 4 + 1)
27 #define noise_encrypted_len(plain_len) ((plain_len) + NOISE_AUTHTAG_LEN)
28 
29 enum limits
30 {
35  MAX_PEERS = 1U << 20
36 };
37 
38 #define foreach_wg_message_type \
39  _(INVALID, "Invalid") \
40  _(HANDSHAKE_INITIATION, "Handshake initiation") \
41  _(HANDSHAKE_RESPONSE, "Handshake response") \
42  _(HANDSHAKE_COOKIE, "Handshake cookie") \
43  _(DATA, "Data") \
44 
45 typedef enum message_type
46 {
47 #define _(v,s) MESSAGE_##v,
49 #undef _
51 
52 typedef struct message_header
53 {
56 
58 {
61  u8 unencrypted_ephemeral[NOISE_PUBLIC_KEY_LEN];
63  u8 encrypted_timestamp[noise_encrypted_len (NOISE_TIMESTAMP_LEN)];
66 
68 {
72  u8 unencrypted_ephemeral[NOISE_PUBLIC_KEY_LEN];
73  u8 encrypted_nothing[noise_encrypted_len (0)];
76 
78 {
82  u8 encrypted_cookie[noise_encrypted_len (COOKIE_MAC_SIZE)];
84 
85 typedef struct message_data
86 {
90  u8 encrypted_data[];
92 
93 #define message_data_len(plain_len) \
94  (noise_encrypted_len(plain_len) + sizeof(message_data_t))
95 
96 #endif /* __included_wg_messages_h__ */
97 
98 /*
99  * fd.io coding-style-patch-verification: ON
100  *
101  * Local Variables:
102  * eval: (c-set-style "gnu")
103  * End:
104  */
message_header_t header
struct message_handshake_initiation message_handshake_initiation_t
#define NOISE_TIMESTAMP_LEN
unsigned long u64
Definition: types.h:89
unsigned char u8
Definition: types.h:56
unsigned int u32
Definition: types.h:88
#define NOISE_PUBLIC_KEY_LEN
struct message_handshake_response message_handshake_response_t
#define WHZ
WG tick frequency.
struct message_header message_header_t
struct message_data message_data_t
struct message_handshake_cookie message_handshake_cookie_t
#define noise_encrypted_len(plain_len)
message_type_t type
enum message_type message_type_t
message_type
#define foreach_wg_message_type