summaryrefslogtreecommitdiffstats
path: root/src/wireguard.h
diff options
context:
space:
mode:
authorMatt Dunwoodie <ncon@mail.noconroy.net>2019-07-27 18:34:58 +1000
committerMatt Dunwoodie <ncon@mail.noconroy.net>2019-08-08 21:37:38 +1000
commit530857921c80746e2a36874a651e404a0662a79a (patch)
tree753224f624806852f88a1ec69a5f4893dd46abae /src/wireguard.h
parentRename wg_id_* functions to be consistent with wg_peer_* (diff)
downloadwireguard-openbsd-530857921c80746e2a36874a651e404a0662a79a.tar.xz
wireguard-openbsd-530857921c80746e2a36874a651e404a0662a79a.zip
Decrease coupling between if_wg.c and wireguard.c more
Diffstat (limited to 'src/wireguard.h')
-rw-r--r--src/wireguard.h46
1 files changed, 21 insertions, 25 deletions
diff --git a/src/wireguard.h b/src/wireguard.h
index 0be4645345d..c0d8834bc5b 100644
--- a/src/wireguard.h
+++ b/src/wireguard.h
@@ -33,16 +33,14 @@
#define WG_COOKIE_VALID_TIME 120
#define WG_REKEY_AFTER_TIME_RECV (WG_REJECT_AFTER_TIME - WG_KEEPALIVE_TIMEOUT - WG_REKEY_TIMEOUT)
-enum wg_role {
- WG_ROLE_UNKNOWN = 0,
- WG_ROLE_INITIATOR,
- WG_ROLE_RESPONDER,
-};
-
-enum wg_keytype {
- WG_KEY_PSK,
- WG_KEY_LOCAL,
- WG_KEY_REMOTE,
+enum wg_state {
+ WG_STATE_CLEAN = 0,
+ WG_STATE_MADE_INITIATION,
+ WG_STATE_MADE_RESPONSE,
+ WG_STATE_RECV_INITIATION,
+ WG_STATE_RECV_RESPONSE,
+ WG_STATE_INITIATOR,
+ WG_STATE_RESPONDER,
};
enum wg_pkt_type {
@@ -66,7 +64,7 @@ struct wg_cookie {
struct wg_handshake {
struct rwlock hs_lock;
- enum wg_role hs_role;
+ enum wg_state hs_state;
uint32_t hs_local_id;
uint32_t hs_remote_id;
uint8_t hs_mac[WG_MAC_SIZE];
@@ -86,7 +84,7 @@ struct wg_handshake {
struct wg_session {
struct rwlock s_lock;
- enum wg_role s_role;
+ enum wg_state s_state;
uint64_t s_txcounter;
uint64_t s_rxcounter;
uint32_t s_local_id;
@@ -142,9 +140,11 @@ struct wg_msg_transport {
enum wg_error {
WG_OK = 0,
+ WG_TIMESTAMP,
WG_DECRYPT,
WG_REPLAY,
WG_REJECT,
+ WG_REKEY,
WG_STATE,
WG_MAC,
};
@@ -157,28 +157,24 @@ uint32_t wg_session_clean(struct wg_session *);
enum wg_error wg_handshake_make_initiation(struct wg_handshake *, uint32_t, struct wg_msg_initiation *);
enum wg_error wg_handshake_make_response(struct wg_handshake *, uint32_t, struct wg_msg_response *);
enum wg_error wg_handshake_make_cookie(struct wg_keypair *kp, struct wg_cookie *, uint32_t, uint8_t *, uint8_t, uint8_t mac[WG_MAC_SIZE], struct wg_msg_cookie *);
-enum wg_error wg_session_encrypt(struct wg_session *, struct wg_msg_transport *, size_t);
-enum wg_error wg_handshake_valid_mac2(struct wg_cookie *, uint8_t *, uint8_t);
-
-enum wg_error wg_handshake_recv_initiation(struct wg_handshake *, struct wg_msg_initiation *);
+enum wg_error wg_handshake_recv_initiation(struct wg_handshake *, struct wg_keypair *, struct wg_msg_initiation *);
enum wg_error wg_handshake_recv_response(struct wg_handshake *, struct wg_msg_response *);
enum wg_error wg_handshake_recv_cookie(struct wg_handshake *, struct wg_msg_cookie *);
-enum wg_error wg_session_decrypt(struct wg_session *, struct wg_msg_transport *, size_t);
-void wg_handshake_clone(struct wg_handshake *, struct wg_handshake *);
-void wg_session_from_handshake(struct wg_session *, struct wg_handshake *);
+enum wg_error wg_handshake_valid_mac2(struct wg_cookie *, uint8_t *, uint8_t);
+enum wg_error wg_handshake_merge(struct wg_handshake *, struct wg_handshake *);
-int wg_session_reject_tx(struct wg_session *);
-int wg_session_reject_rx(struct wg_session *);
-int wg_session_rekey_tx(struct wg_session *);
-int wg_session_rekey_rx(struct wg_session *);
+enum wg_error wg_session_encrypt(struct wg_session *, struct wg_msg_transport *, size_t);
+enum wg_error wg_session_decrypt(struct wg_session *, struct wg_msg_transport *, size_t);
+enum wg_error wg_session_from_handshake(struct wg_session *, struct wg_handshake *);
void wg_keypair_from_bytes(struct wg_keypair *, const uint8_t [WG_KEY_SIZE]);
-void wg_keypair_generate(struct wg_keypair *);
+enum wg_pkt_type wg_pkt_type(uint8_t *, size_t);
+
/* TODO make better */
+void wg_keypair_generate(struct wg_keypair *);
int wg_timespec_timedout(struct timespec *, time_t);
-enum wg_pkt_type wg_pkt_type(uint8_t *, size_t);
#endif /* _LIBWG_H_ */