-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnoise_init_pqc.c
More file actions
62 lines (52 loc) · 1.71 KB
/
Copy pathnoise_init_pqc.c
File metadata and controls
62 lines (52 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// SPDX-License-Identifier: GPL-2.0
/*
* WireGuard PQC Extension - Noise Initialization with PQC Support
*/
#include "noise.h"
#include "device.h"
#include "peer.h"
#include "crypto_mode.h"
#include <linux/slab.h>
#include <linux/string.h>
/*
* Extended handshake initializer that wraps wg_noise_handshake_init() and
* additionally allocates PQC key storage when PQC mode is active.
*/
int wg_noise_handshake_init_with_pqc(struct noise_handshake *handshake,
struct noise_static_identity *static_identity,
const u8 peer_public_key[NOISE_PUBLIC_KEY_LEN],
const u8 peer_preshared_key[NOISE_SYMMETRIC_KEY_LEN],
struct wg_peer *peer)
{
wg_noise_handshake_init(handshake, static_identity, peer_public_key,
peer_preshared_key, peer);
if (wg_mode_pqc_enabled()) {
int ret = wg_noise_pqc_init_handshake(handshake);
if (ret < 0) {
pr_err("WG_PQC: Failed to initialize PQC handshake: %d\n", ret);
wg_noise_handshake_clear(handshake);
return ret;
}
}
return 0;
}
/* Extended handshake clear that also frees PQC key material. */
void wg_noise_handshake_clear_with_pqc(struct noise_handshake *handshake)
{
if (wg_mode_pqc_enabled())
wg_noise_pqc_clear_handshake(handshake);
wg_noise_handshake_clear(handshake);
}
/* Initialises PQC key storage on the static identity if PQC mode is active. */
int wg_noise_static_identity_init_pqc(struct noise_static_identity *identity)
{
if (!wg_mode_pqc_enabled())
return 0;
return wg_noise_pqc_init_identity(identity);
}
/* Clears PQC key material from the static identity if PQC mode is active. */
void wg_noise_static_identity_clear_pqc(struct noise_static_identity *identity)
{
if (wg_mode_pqc_enabled())
wg_noise_pqc_clear_identity(identity);
}