1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
10 #include <linux/rwsem.h>
14 struct cookie_checker
{
15 u8 secret
[NOISE_HASH_LEN
];
16 u8 cookie_encryption_key
[NOISE_SYMMETRIC_KEY_LEN
];
17 u8 message_mac1_key
[NOISE_SYMMETRIC_KEY_LEN
];
19 struct rw_semaphore secret_lock
;
20 struct wg_device
*device
;
26 u8 cookie
[COOKIE_LEN
];
28 u8 last_mac1_sent
[COOKIE_LEN
];
29 u8 cookie_decryption_key
[NOISE_SYMMETRIC_KEY_LEN
];
30 u8 message_mac1_key
[NOISE_SYMMETRIC_KEY_LEN
];
31 struct rw_semaphore lock
;
34 enum cookie_mac_state
{
36 VALID_MAC_BUT_NO_COOKIE
,
37 VALID_MAC_WITH_COOKIE_BUT_RATELIMITED
,
41 void wg_cookie_checker_init(struct cookie_checker
*checker
,
42 struct wg_device
*wg
);
43 void wg_cookie_checker_precompute_device_keys(struct cookie_checker
*checker
);
44 void wg_cookie_checker_precompute_peer_keys(struct wg_peer
*peer
);
45 void wg_cookie_init(struct cookie
*cookie
);
47 enum cookie_mac_state
wg_cookie_validate_packet(struct cookie_checker
*checker
,
50 void wg_cookie_add_mac_to_packet(void *message
, size_t len
,
51 struct wg_peer
*peer
);
53 void wg_cookie_message_create(struct message_handshake_cookie
*src
,
54 struct sk_buff
*skb
, __le32 index
,
55 struct cookie_checker
*checker
);
56 void wg_cookie_message_consume(struct message_handshake_cookie
*src
,
57 struct wg_device
*wg
);
59 #endif /* _WG_COOKIE_H */