summaryrefslogtreecommitdiffstats
path: root/src/protocols/ec25519_fhmqvc
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-04-20 05:29:11 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-04-20 05:29:11 +0200
commit7adeb6e88196a594ec3d36ffc1c658340ffcd7bc (patch)
tree6a6bfb84387141bf39d573ef9fa47f2c993d1923 /src/protocols/ec25519_fhmqvc
parentb9c8603931203f5d94091f7a05a5967304b62fbd (diff)
downloadfastd-7adeb6e88196a594ec3d36ffc1c658340ffcd7bc.tar
fastd-7adeb6e88196a594ec3d36ffc1c658340ffcd7bc.zip
Make ctx global
Diffstat (limited to 'src/protocols/ec25519_fhmqvc')
-rw-r--r--src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c94
-rw-r--r--src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.h26
-rw-r--r--src/protocols/ec25519_fhmqvc/handshake.c236
-rw-r--r--src/protocols/ec25519_fhmqvc/handshake.h8
-rw-r--r--src/protocols/ec25519_fhmqvc/state.c56
-rw-r--r--src/protocols/ec25519_fhmqvc/util.c8
6 files changed, 214 insertions, 214 deletions
diff --git a/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c b/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c
index 698746b..9d32f3b 100644
--- a/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c
+++ b/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c
@@ -38,25 +38,25 @@ static inline bool read_key(uint8_t key[32], const char *hexkey) {
return true;
}
-static inline void check_session_refresh(fastd_context_t *ctx, fastd_peer_t *peer) {
+static inline void check_session_refresh(fastd_peer_t *peer) {
protocol_session_t *session = &peer->protocol_state->session;
- if (!session->refreshing && session->method->provider->session_want_refresh(ctx, session->method_state)) {
- pr_verbose(ctx, "refreshing session with %P", peer);
+ if (!session->refreshing && session->method->provider->session_want_refresh(session->method_state)) {
+ pr_verbose("refreshing session with %P", peer);
session->handshakes_cleaned = true;
session->refreshing = true;
- fastd_peer_schedule_handshake(ctx, peer, 0);
+ fastd_peer_schedule_handshake(peer, 0);
}
}
-static fastd_protocol_config_t* protocol_init(fastd_context_t *ctx) {
+static fastd_protocol_config_t* protocol_init(void) {
fastd_protocol_config_t *protocol_config = malloc(sizeof(fastd_protocol_config_t));
if (!conf.secret)
- exit_error(ctx, "no secret key configured");
+ exit_error("no secret key configured");
if (!read_key(protocol_config->key.secret.p, conf.secret))
- exit_error(ctx, "invalid secret key");
+ exit_error("invalid secret key");
ecc_25519_work_t work;
ecc_25519_scalarmult_base(&work, &protocol_config->key.secret);
@@ -65,27 +65,27 @@ static fastd_protocol_config_t* protocol_init(fastd_context_t *ctx) {
return protocol_config;
}
-static void protocol_peer_verify(fastd_context_t *ctx, fastd_peer_config_t *peer_conf) {
+static void protocol_peer_verify(fastd_peer_config_t *peer_conf) {
if (!peer_conf->key)
- exit_error(ctx, "no key configured for peer `%s'", peer_conf->name);
+ exit_error("no key configured for peer `%s'", peer_conf->name);
aligned_int256_t key;
if (!read_key(key.u8, peer_conf->key))
- exit_error(ctx, "invalid key configured for peer `%s'", peer_conf->name);
+ exit_error("invalid key configured for peer `%s'", peer_conf->name);
}
-static void protocol_peer_configure(fastd_context_t *ctx, fastd_peer_config_t *peer_conf) {
+static void protocol_peer_configure(fastd_peer_config_t *peer_conf) {
if (peer_conf->protocol_config)
return;
if (!peer_conf->key) {
- pr_warn(ctx, "no key configured for `%s', disabling peer", peer_conf->name);
+ pr_warn("no key configured for `%s', disabling peer", peer_conf->name);
return;
}
aligned_int256_t key;
if (!read_key(key.u8, peer_conf->key)) {
- pr_warn(ctx, "invalid key configured for `%s', disabling peer", peer_conf->name);
+ pr_warn("invalid key configured for `%s', disabling peer", peer_conf->name);
return;
}
@@ -93,62 +93,62 @@ static void protocol_peer_configure(fastd_context_t *ctx, fastd_peer_config_t *p
peer_conf->protocol_config->public_key = key;
if (memcmp(&peer_conf->protocol_config->public_key, &conf.protocol_config->key.public, 32) == 0)
- pr_debug(ctx, "found own key as `%s', ignoring peer", peer_conf->name);
+ pr_debug("found own key as `%s', ignoring peer", peer_conf->name);
}
-static inline bool check_session(fastd_context_t *ctx, fastd_peer_t *peer) {
- if (is_session_valid(ctx, &peer->protocol_state->session))
+static inline bool check_session(fastd_peer_t *peer) {
+ if (is_session_valid(&peer->protocol_state->session))
return true;
- pr_verbose(ctx, "active session with %P timed out", peer);
- fastd_peer_reset(ctx, peer);
+ pr_verbose("active session with %P timed out", peer);
+ fastd_peer_reset(peer);
return false;
}
-static void protocol_handle_recv(fastd_context_t *ctx, fastd_peer_t *peer, fastd_buffer_t buffer) {
- if (!peer->protocol_state || !check_session(ctx, peer))
+static void protocol_handle_recv(fastd_peer_t *peer, fastd_buffer_t buffer) {
+ if (!peer->protocol_state || !check_session(peer))
goto fail;
fastd_buffer_t recv_buffer;
bool ok = false;
- if (is_session_valid(ctx, &peer->protocol_state->old_session)) {
- if (peer->protocol_state->old_session.method->provider->decrypt(ctx, peer, peer->protocol_state->old_session.method_state, &recv_buffer, buffer))
+ if (is_session_valid(&peer->protocol_state->old_session)) {
+ if (peer->protocol_state->old_session.method->provider->decrypt(peer, peer->protocol_state->old_session.method_state, &recv_buffer, buffer))
ok = true;
}
if (!ok) {
- if (peer->protocol_state->session.method->provider->decrypt(ctx, peer, peer->protocol_state->session.method_state, &recv_buffer, buffer)) {
+ if (peer->protocol_state->session.method->provider->decrypt(peer, peer->protocol_state->session.method_state, &recv_buffer, buffer)) {
ok = true;
if (peer->protocol_state->old_session.method) {
- pr_debug(ctx, "invalidating old session with %P", peer);
- peer->protocol_state->old_session.method->provider->session_free(ctx, peer->protocol_state->old_session.method_state);
+ pr_debug("invalidating old session with %P", peer);
+ peer->protocol_state->old_session.method->provider->session_free(peer->protocol_state->old_session.method_state);
peer->protocol_state->old_session = (protocol_session_t){};
}
if (!peer->protocol_state->session.handshakes_cleaned) {
- pr_debug(ctx, "cleaning left handshakes with %P", peer);
- fastd_peer_unschedule_handshake(ctx, peer);
+ pr_debug("cleaning left handshakes with %P", peer);
+ fastd_peer_unschedule_handshake(peer);
peer->protocol_state->session.handshakes_cleaned = true;
- if (peer->protocol_state->session.method->provider->session_is_initiator(ctx, peer->protocol_state->session.method_state))
- fastd_protocol_ec25519_fhmqvc_send_empty(ctx, peer, &peer->protocol_state->session);
+ if (peer->protocol_state->session.method->provider->session_is_initiator(peer->protocol_state->session.method_state))
+ fastd_protocol_ec25519_fhmqvc_send_empty(peer, &peer->protocol_state->session);
}
- check_session_refresh(ctx, peer);
+ check_session_refresh(peer);
}
}
if (!ok) {
- pr_verbose(ctx, "verification failed for packet received from %P", peer);
+ pr_verbose("verification failed for packet received from %P", peer);
goto fail;
}
- fastd_peer_seen(ctx, peer);
+ fastd_peer_seen(peer);
if (recv_buffer.len)
- fastd_handle_receive(ctx, peer, recv_buffer);
+ fastd_handle_receive(peer, recv_buffer);
else
fastd_buffer_free(recv_buffer);
@@ -158,39 +158,39 @@ static void protocol_handle_recv(fastd_context_t *ctx, fastd_peer_t *peer, fastd
fastd_buffer_free(buffer);
}
-static void session_send(fastd_context_t *ctx, fastd_peer_t *peer, fastd_buffer_t buffer, protocol_session_t *session) {
+static void session_send(fastd_peer_t *peer, fastd_buffer_t buffer, protocol_session_t *session) {
size_t stat_size = buffer.len;
fastd_buffer_t send_buffer;
- if (!session->method->provider->encrypt(ctx, peer, session->method_state, &send_buffer, buffer)) {
+ if (!session->method->provider->encrypt(peer, session->method_state, &send_buffer, buffer)) {
fastd_buffer_free(buffer);
- pr_error(ctx, "failed to encrypt packet for %P", peer);
+ pr_error("failed to encrypt packet for %P", peer);
return;
}
- fastd_send(ctx, peer->sock, &peer->local_address, &peer->address, peer, send_buffer, stat_size);
- peer->keepalive_timeout = fastd_in_seconds(ctx, conf.keepalive_timeout);
+ fastd_send(peer->sock, &peer->local_address, &peer->address, peer, send_buffer, stat_size);
+ peer->keepalive_timeout = fastd_in_seconds(conf.keepalive_timeout);
}
-static void protocol_send(fastd_context_t *ctx, fastd_peer_t *peer, fastd_buffer_t buffer) {
- if (!peer->protocol_state || !fastd_peer_is_established(peer) || !check_session(ctx, peer)) {
+static void protocol_send(fastd_peer_t *peer, fastd_buffer_t buffer) {
+ if (!peer->protocol_state || !fastd_peer_is_established(peer) || !check_session(peer)) {
fastd_buffer_free(buffer);
return;
}
- check_session_refresh(ctx, peer);
+ check_session_refresh(peer);
- if (peer->protocol_state->session.method->provider->session_is_initiator(ctx, peer->protocol_state->session.method_state) && is_session_valid(ctx, &peer->protocol_state->old_session)) {
- pr_debug2(ctx, "sending packet for old session to %P", peer);
- session_send(ctx, peer, buffer, &peer->protocol_state->old_session);
+ if (peer->protocol_state->session.method->provider->session_is_initiator(peer->protocol_state->session.method_state) && is_session_valid(&peer->protocol_state->old_session)) {
+ pr_debug2("sending packet for old session to %P", peer);
+ session_send(peer, buffer, &peer->protocol_state->old_session);
}
else {
- session_send(ctx, peer, buffer, &peer->protocol_state->session);
+ session_send(peer, buffer, &peer->protocol_state->session);
}
}
-void fastd_protocol_ec25519_fhmqvc_send_empty(fastd_context_t *ctx, fastd_peer_t *peer, protocol_session_t *session) {
- session_send(ctx, peer, fastd_buffer_alloc(ctx, 0, alignto(session->method->provider->min_encrypt_head_space, 8), session->method->provider->min_encrypt_tail_space), session);
+void fastd_protocol_ec25519_fhmqvc_send_empty(fastd_peer_t *peer, protocol_session_t *session) {
+ session_send(peer, fastd_buffer_alloc(0, alignto(session->method->provider->min_encrypt_head_space, 8), session->method->provider->min_encrypt_tail_space), session);
}
const fastd_protocol_t fastd_protocol_ec25519_fhmqvc = {
diff --git a/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.h b/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.h
index be316db..468a7b2 100644
--- a/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.h
+++ b/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.h
@@ -76,23 +76,23 @@ struct fastd_protocol_peer_state {
};
-bool fastd_protocol_ec25519_fhmqvc_peer_check(fastd_context_t *ctx, fastd_peer_config_t *peer_conf);
-bool fastd_protocol_ec25519_fhmqvc_peer_check_temporary(fastd_context_t *ctx, fastd_peer_t *peer);
+bool fastd_protocol_ec25519_fhmqvc_peer_check(fastd_peer_config_t *peer_conf);
+bool fastd_protocol_ec25519_fhmqvc_peer_check_temporary(fastd_peer_t *peer);
-void fastd_protocol_ec25519_fhmqvc_maintenance(fastd_context_t *ctx);
-void fastd_protocol_ec25519_fhmqvc_init_peer_state(fastd_context_t *ctx, fastd_peer_t *peer);
-void fastd_protocol_ec25519_fhmqvc_reset_peer_state(fastd_context_t *ctx, fastd_peer_t *peer);
-void fastd_protocol_ec25519_fhmqvc_free_peer_state(fastd_context_t *ctx, fastd_peer_t *peer);
+void fastd_protocol_ec25519_fhmqvc_maintenance(void);
+void fastd_protocol_ec25519_fhmqvc_init_peer_state(fastd_peer_t *peer);
+void fastd_protocol_ec25519_fhmqvc_reset_peer_state(fastd_peer_t *peer);
+void fastd_protocol_ec25519_fhmqvc_free_peer_state(fastd_peer_t *peer);
-void fastd_protocol_ec25519_fhmqvc_handshake_init(fastd_context_t *ctx, const fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, fastd_peer_t *peer);
-void fastd_protocol_ec25519_fhmqvc_handshake_handle(fastd_context_t *ctx, fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, fastd_peer_t *peer, const fastd_handshake_t *handshake, const fastd_method_info_t *method);
+void fastd_protocol_ec25519_fhmqvc_handshake_init(const fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, fastd_peer_t *peer);
+void fastd_protocol_ec25519_fhmqvc_handshake_handle(fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, fastd_peer_t *peer, const fastd_handshake_t *handshake, const fastd_method_info_t *method);
-void fastd_protocol_ec25519_fhmqvc_send_empty(fastd_context_t *ctx, fastd_peer_t *peer, protocol_session_t *session);
+void fastd_protocol_ec25519_fhmqvc_send_empty(fastd_peer_t *peer, protocol_session_t *session);
-void fastd_protocol_ec25519_fhmqvc_generate_key(fastd_context_t *ctx);
+void fastd_protocol_ec25519_fhmqvc_generate_key(void);
void fastd_protocol_ec25519_fhmqvc_show_key(void);
void fastd_protocol_ec25519_fhmqvc_set_shell_env(const fastd_peer_t *peer);
-bool fastd_protocol_ec25519_fhmqvc_describe_peer(const fastd_context_t *ctx UNUSED, const fastd_peer_t *peer, char *buf, size_t len);
+bool fastd_protocol_ec25519_fhmqvc_describe_peer(const fastd_peer_t *peer, char *buf, size_t len);
static inline void hexdump(char out[65], const unsigned char d[32]) {
@@ -102,6 +102,6 @@ static inline void hexdump(char out[65], const unsigned char d[32]) {
}
-static inline bool is_session_valid(fastd_context_t *ctx, const protocol_session_t *session) {
- return (session->method && session->method->provider->session_is_valid(ctx, session->method_state));
+static inline bool is_session_valid(const protocol_session_t *session) {
+ return (session->method && session->method->provider->session_is_valid(session->method_state));
}
diff --git a/src/protocols/ec25519_fhmqvc/handshake.c b/src/protocols/ec25519_fhmqvc/handshake.c
index dda798b..df53157 100644
--- a/src/protocols/ec25519_fhmqvc/handshake.c
+++ b/src/protocols/ec25519_fhmqvc/handshake.c
@@ -68,46 +68,46 @@ static void derive_key(fastd_sha256_t *out, size_t blocks, const uint32_t *salt,
fastd_hkdf_sha256_expand(out, blocks, &prk, info, sizeof(info));
}
-static inline void supersede_session(fastd_context_t *ctx, fastd_peer_t *peer, const fastd_method_info_t *method) {
- if (is_session_valid(ctx, &peer->protocol_state->session) && !is_session_valid(ctx, &peer->protocol_state->old_session)) {
+static inline void supersede_session(fastd_peer_t *peer, const fastd_method_info_t *method) {
+ if (is_session_valid(&peer->protocol_state->session) && !is_session_valid(&peer->protocol_state->old_session)) {
if (peer->protocol_state->old_session.method)
- peer->protocol_state->old_session.method->provider->session_free(ctx, peer->protocol_state->old_session.method_state);
+ peer->protocol_state->old_session.method->provider->session_free(peer->protocol_state->old_session.method_state);
peer->protocol_state->old_session = peer->protocol_state->session;
}
else {
if (peer->protocol_state->session.method)
- peer->protocol_state->session.method->provider->session_free(ctx, peer->protocol_state->session.method_state);
+ peer->protocol_state->session.method->provider->session_free(peer->protocol_state->session.method_state);
}
if (peer->protocol_state->old_session.method) {
if (peer->protocol_state->old_session.method != method) {
- pr_debug(ctx, "method of %P has changed, terminating old session", peer);
- peer->protocol_state->old_session.method->provider->session_free(ctx, peer->protocol_state->old_session.method_state);
+ pr_debug("method of %P has changed, terminating old session", peer);
+ peer->protocol_state->old_session.method->provider->session_free(peer->protocol_state->old_session.method_state);
peer->protocol_state->old_session = (protocol_session_t){};
}
else {
- peer->protocol_state->old_session.method->provider->session_superseded(ctx, peer->protocol_state->old_session.method_state);
+ peer->protocol_state->old_session.method->provider->session_superseded(peer->protocol_state->old_session.method_state);
}
}
}
-static inline bool new_session(fastd_context_t *ctx, fastd_peer_t *peer, const fastd_method_info_t *method, bool initiator,
+static inline bool new_session(fastd_peer_t *peer, const fastd_method_info_t *method, bool initiator,
const aligned_int256_t *A, const aligned_int256_t *B, const aligned_int256_t *X, const aligned_int256_t *Y,
const aligned_int256_t *sigma, const uint32_t *salt, uint64_t serial) {
- supersede_session(ctx, peer, method);
+ supersede_session(peer, method);
if (salt) {
- size_t blocks = block_count(method->provider->key_length(ctx, method->method), sizeof(fastd_sha256_t));
+ size_t blocks = block_count(method->provider->key_length(method->method), sizeof(fastd_sha256_t));
fastd_sha256_t secret[blocks];
derive_key(secret, blocks, salt, method->name, A, B, X, Y, sigma);
- peer->protocol_state->session.method_state = method->provider->session_init(ctx, method->method, (const uint8_t*)secret, initiator);
+ peer->protocol_state->session.method_state = method->provider->session_init(method->method, (const uint8_t*)secret, initiator);
}
else {
fastd_sha256_t hash;
fastd_sha256_blocks(&hash, X->u32, Y->u32, A->u32, B->u32, sigma->u32, NULL);
- peer->protocol_state->session.method_state = method->provider->session_init_compat(ctx, method->method, hash.b, HASHBYTES, initiator);
+ peer->protocol_state->session.method_state = method->provider->session_init_compat(method->method, hash.b, HASHBYTES, initiator);
}
if (!peer->protocol_state->session.method_state)
@@ -121,44 +121,44 @@ static inline bool new_session(fastd_context_t *ctx, fastd_peer_t *peer, const f
return true;
}
-static bool establish(fastd_context_t *ctx, fastd_peer_t *peer, const fastd_method_info_t *method, fastd_socket_t *sock,
+static bool establish(fastd_peer_t *peer, const fastd_method_info_t *method, fastd_socket_t *sock,
const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, bool initiator,
const aligned_int256_t *A, const aligned_int256_t *B, const aligned_int256_t *X, const aligned_int256_t *Y,
const aligned_int256_t *sigma, const uint32_t *salt, uint64_t serial) {
if (serial <= peer->protocol_state->last_serial) {
- pr_debug(ctx, "ignoring handshake from %P[%I] because of handshake key reuse", peer, remote_addr);
+ pr_debug("ignoring handshake from %P[%I] because of handshake key reuse", peer, remote_addr);
return false;
}
if (!salt && !method->provider->session_init_compat) {
- pr_warn(ctx, "can't establish compat session with %P[%I] (method without compat support)", peer, remote_addr);
+ pr_warn("can't establish compat session with %P[%I] (method without compat support)", peer, remote_addr);
return false;
}
- pr_verbose(ctx, "%I authorized as %P", remote_addr, peer);
+ pr_verbose("%I authorized as %P", remote_addr, peer);
- if (!fastd_peer_claim_address(ctx, peer, sock, local_addr, remote_addr)) {
- pr_warn(ctx, "can't set address %I which is used by a fixed peer", remote_addr);
- fastd_peer_reset(ctx, peer);
+ if (!fastd_peer_claim_address(peer, sock, local_addr, remote_addr)) {
+ pr_warn("can't set address %I which is used by a fixed peer", remote_addr);
+ fastd_peer_reset(peer);
return false;
}
- if (!new_session(ctx, peer, method, initiator, A, B, X, Y, sigma, salt, serial)) {
- pr_error(ctx, "failed to initialize method session for %P (method `%s'%s)", peer, method->name, salt ? "" : " (compat mode)");
- fastd_peer_reset(ctx, peer);
+ if (!new_session(peer, method, initiator, A, B, X, Y, sigma, salt, serial)) {
+ pr_error("failed to initialize method session for %P (method `%s'%s)", peer, method->name, salt ? "" : " (compat mode)");
+ fastd_peer_reset(peer);
return false;
}
- peer->establish_handshake_timeout = fastd_in_seconds(ctx, conf.min_handshake_interval);
- fastd_peer_seen(ctx, peer);
- fastd_peer_set_established(ctx, peer);
+ peer->establish_handshake_timeout = fastd_in_seconds(conf.min_handshake_interval);
+ fastd_peer_seen(peer);
+ fastd_peer_set_established(peer);
- pr_verbose(ctx, "new session with %P established using method `%s'%s.", peer, method->name, salt ? "" : " (compat mode)");
+ pr_verbose("new session with %P established using method `%s'%s.", peer, method->name, salt ? "" : " (compat mode)");
if (initiator)
- fastd_peer_schedule_handshake_default(ctx, peer);
+ fastd_peer_schedule_handshake_default(peer);
else
- fastd_protocol_ec25519_fhmqvc_send_empty(ctx, peer, &peer->protocol_state->session);
+ fastd_protocol_ec25519_fhmqvc_send_empty(peer, &peer->protocol_state->session);
return true;
}
@@ -260,7 +260,7 @@ static bool update_shared_handshake_key(const fastd_peer_t *peer, const handshak
return true;
}
-static void clear_shared_handshake_key(fastd_context_t *ctx UNUSED, const fastd_peer_t *peer) {
+static void clear_shared_handshake_key(const fastd_peer_t *peer) {
memset(&peer->protocol_state->sigma, 0, sizeof(peer->protocol_state->sigma));
memset(&peer->protocol_state->shared_handshake_key, 0, sizeof(peer->protocol_state->shared_handshake_key));
memset(&peer->protocol_state->shared_handshake_key_compat, 0, sizeof(peer->protocol_state->shared_handshake_key_compat));
@@ -269,37 +269,37 @@ static void clear_shared_handshake_key(fastd_context_t *ctx UNUSED, const fastd_
memset(&peer->protocol_state->peer_handshake_key, 0, sizeof(peer->protocol_state->peer_handshake_key));
}
-static void respond_handshake(fastd_context_t *ctx, const fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, fastd_peer_t *peer,
+static void respond_handshake(const fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, fastd_peer_t *peer,
const handshake_key_t *handshake_key, const aligned_int256_t *peer_handshake_key, const fastd_handshake_t *handshake, const fastd_method_info_t *method) {
- pr_debug(ctx, "responding handshake with %P[%I]...", peer, remote_addr);
+ pr_debug("responding handshake with %P[%I]...", peer, remote_addr);
if (!update_shared_handshake_key(peer, handshake_key, peer_handshake_key))
return;
- fastd_buffer_t buffer = fastd_handshake_new_reply(ctx, handshake, method, true, 4*(4+PUBLICKEYBYTES) + 2*(4+HASHBYTES));
+ fastd_buffer_t buffer = fastd_handshake_new_reply(handshake, method, true, 4*(4+PUBLICKEYBYTES) + 2*(4+HASHBYTES));
- fastd_handshake_add(ctx, &buffer, RECORD_SENDER_KEY, PUBLICKEYBYTES, &conf.protocol_config->key.public);
- fastd_handshake_add(ctx, &buffer, RECORD_RECEIPIENT_KEY, PUBLICKEYBYTES, &peer->protocol_config->public_key);
- fastd_handshake_add(ctx, &buffer, RECORD_SENDER_HANDSHAKE_KEY, PUBLICKEYBYTES, &handshake_key->key.public);
- fastd_handshake_add(ctx, &buffer, RECORD_RECEIPIENT_HANDSHAKE_KEY, PUBLICKEYBYTES, peer_handshake_key);
+ fastd_handshake_add(&buffer, RECORD_SENDER_KEY, PUBLICKEYBYTES, &conf.protocol_config->key.public);
+ fastd_handshake_add(&buffer, RECORD_RECEIPIENT_KEY, PUBLICKEYBYTES, &peer->protocol_config->public_key);
+ fastd_handshake_add(&buffer, RECORD_SENDER_HANDSHAKE_KEY, PUBLICKEYBYTES, &handshake_key->key.public);
+ fastd_handshake_add(&buffer, RECORD_RECEIPIENT_HANDSHAKE_KEY, PUBLICKEYBYTES, peer_handshake_key);
fastd_sha256_t hmacbuf;
if (!conf.secure_handshakes) {
fastd_hmacsha256_blocks(&hmacbuf, peer->protocol_state->shared_handshake_key_compat.w, conf.protocol_config->key.public.u32, handshake_key->key.public.u32, NULL);
- fastd_handshake_add(ctx, &buffer, RECORD_T, HASHBYTES, hmacbuf.b);
+ fastd_handshake_add(&buffer, RECORD_T, HASHBYTES, hmacbuf.b);
}
- uint8_t *mac = fastd_handshake_add_zero(ctx, &buffer, RECORD_TLV_MAC, HASHBYTES);
+ uint8_t *mac = fastd_handshake_add_zero(&buffer, RECORD_TLV_MAC, HASHBYTES);
fastd_hmacsha256(&hmacbuf, peer->protocol_state->shared_handshake_key.w, fastd_handshake_tlv_data(&buffer), fastd_handshake_tlv_len(&buffer));
memcpy(mac, hmacbuf.b, HASHBYTES);
- fastd_send_handshake(ctx, sock, local_addr, remote_addr, peer, buffer);
+ fastd_send_handshake(sock, local_addr, remote_addr, peer, buffer);
}
-static void finish_handshake(fastd_context_t *ctx, fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, fastd_peer_t *peer, const handshake_key_t *handshake_key, const aligned_int256_t *peer_handshake_key,
+static void finish_handshake(fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, fastd_peer_t *peer, const handshake_key_t *handshake_key, const aligned_int256_t *peer_handshake_key,
const fastd_handshake_t *handshake, const fastd_method_info_t *method) {
- pr_debug(ctx, "finishing handshake with %P[%I]...", peer, remote_addr);
+ pr_debug("finishing handshake with %P[%I]...", peer, remote_addr);
bool compat = !secure_handshake(handshake);
@@ -328,40 +328,40 @@ static void finish_handshake(fastd_context_t *ctx, fastd_socket_t *sock, const f
}
if (!valid) {
- pr_warn(ctx, "received invalid protocol handshake response from %P[%I]", peer, remote_addr);
+ pr_warn("received invalid protocol handshake response from %P[%I]", peer, remote_addr);
return;
}
- if (!establish(ctx, peer, method, sock, local_addr, remote_addr, true, &handshake_key->key.public, peer_handshake_key, &conf.protocol_config->key.public,
+ if (!establish(peer, method, sock, local_addr, remote_addr, true, &handshake_key->key.public, peer_handshake_key, &conf.protocol_config->key.public,
&peer->protocol_config->public_key, &sigma, compat ? NULL : shared_handshake_key.w, handshake_key->serial))
return;
- fastd_buffer_t buffer = fastd_handshake_new_reply(ctx, handshake, method, false, 4*(4+PUBLICKEYBYTES) + 2*(4+HASHBYTES));
+ fastd_buffer_t buffer = fastd_handshake_new_reply(handshake, method, false, 4*(4+PUBLICKEYBYTES) + 2*(4+HASHBYTES));
- fastd_handshake_add(ctx, &buffer, RECORD_SENDER_KEY, PUBLICKEYBYTES, &conf.protocol_config->key.public);
- fastd_handshake_add(ctx, &buffer, RECORD_RECEIPIENT_KEY, PUBLICKEYBYTES, &peer->protocol_config->public_key);
- fastd_handshake_add(ctx, &buffer, RECORD_SENDER_HANDSHAKE_KEY, PUBLICKEYBYTES, &handshake_key->key.public);
- fastd_handshake_add(ctx, &buffer, RECORD_RECEIPIENT_HANDSHAKE_KEY, PUBLICKEYBYTES, peer_handshake_key);
+ fastd_handshake_add(&buffer, RECORD_SENDER_KEY, PUBLICKEYBYTES, &conf.protocol_config->key.public);
+ fastd_handshake_add(&buffer, RECORD_RECEIPIENT_KEY, PUBLICKEYBYTES, &peer->protocol_config->public_key);
+ fastd_handshake_add(&buffer, RECORD_SENDER_HANDSHAKE_KEY, PUBLICKEYBYTES, &handshake_key->key.public);
+ fastd_handshake_add(&buffer, RECORD_RECEIPIENT_HANDSHAKE_KEY, PUBLICKEYBYTES, peer_handshake_key);
if (!compat) {
fastd_sha256_t hmacbuf;
- uint8_t *mac = fastd_handshake_add_zero(ctx, &buffer, RECORD_TLV_MAC, HASHBYTES);
+ uint8_t *mac = fastd_handshake_add_zero(&buffer, RECORD_TLV_MAC, HASHBYTES);
fastd_hmacsha256(&hmacbuf, shared_handshake_key.w, fastd_handshake_tlv_data(&buffer), fastd_handshake_tlv_len(&buffer));
memcpy(mac, hmacbuf.b, HASHBYTES);
}
else {
fastd_sha256_t hmacbuf;
fastd_hmacsha256_blocks(&hmacbuf, shared_handshake_key_compat.w, conf.protocol_config->key.public.u32, handshake_key->key.public.u32, NULL);
- fastd_handshake_add(ctx, &buffer, RECORD_T, HASHBYTES, hmacbuf.b);
+ fastd_handshake_add(&buffer, RECORD_T, HASHBYTES, hmacbuf.b);
}
- fastd_send_handshake(ctx, sock, local_addr, remote_addr, peer, buffer);
+ fastd_send_handshake(sock, local_addr, remote_addr, peer, buffer);
}
-static void handle_finish_handshake(fastd_context_t *ctx, fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr,
+static void handle_finish_handshake(fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr,
fastd_peer_t *peer, const handshake_key_t *handshake_key, const aligned_int256_t *peer_handshake_key,
const fastd_handshake_t *handshake, const fastd_method_info_t *method) {
- pr_debug(ctx, "handling handshake finish with %P[%I]...", peer, remote_addr);
+ pr_debug("handling handshake finish with %P[%I]...", peer, remote_addr);
bool compat = !secure_handshake(handshake);
@@ -381,27 +381,27 @@ static void handle_finish_handshake(fastd_context_t *ctx, fastd_socket_t *sock,
}
if (!valid) {
- pr_warn(ctx, "received invalid protocol handshake finish from %P[%I]", peer, remote_addr);
+ pr_warn("received invalid protocol handshake finish from %P[%I]", peer, remote_addr);
return;
}
- establish(ctx, peer, method, sock, local_addr, remote_addr, false, peer_handshake_key, &handshake_key->key.public, &peer->protocol_config->public_key,
+ establish(peer, method, sock, local_addr, remote_addr, false, peer_handshake_key, &handshake_key->key.public, &peer->protocol_config->public_key,
&conf.protocol_config->key.public, &peer->protocol_state->sigma, compat ? NULL : peer->protocol_state->shared_handshake_key.w, handshake_key->serial);
- clear_shared_handshake_key(ctx, peer);
+ clear_shared_handshake_key(peer);
}
-static fastd_peer_t* find_sender_key(fastd_context_t *ctx, const fastd_peer_address_t *address, const unsigned char key[32]) {
+static fastd_peer_t* find_sender_key(const fastd_peer_address_t *address, const unsigned char key[32]) {
errno = 0;
fastd_peer_t *ret = NULL;
size_t i;
- for (i = 0; i < VECTOR_LEN(ctx->peers); i++) {
- fastd_peer_t *peer = VECTOR_INDEX(ctx->peers, i);
+ for (i = 0; i < VECTOR_LEN(ctx.peers); i++) {
+ fastd_peer_t *peer = VECTOR_INDEX(ctx.peers, i);
if (memcmp(&peer->protocol_config->public_key, key, PUBLICKEYBYTES) == 0) {
- if (!fastd_peer_matches_address(ctx, peer, address)) {
+ if (!fastd_peer_matches_address(peer, address)) {
errno = EPERM;
return NULL;
}
@@ -410,7 +410,7 @@ static fastd_peer_t* find_sender_key(fastd_context_t *ctx, const fastd_peer_addr
continue;
}
- if (fastd_peer_owns_address(ctx, peer, address)) {
+ if (fastd_peer_owns_address(peer, address)) {
errno = EPERM;
return NULL;
}
@@ -422,23 +422,23 @@ static fastd_peer_t* find_sender_key(fastd_context_t *ctx, const fastd_peer_addr
return ret;
}
-static fastd_peer_t* match_sender_key(fastd_context_t *ctx, const fastd_socket_t *sock, const fastd_peer_address_t *address, fastd_peer_t *peer, const unsigned char key[32]) {
+static fastd_peer_t* match_sender_key(const fastd_socket_t *sock, const fastd_peer_address_t *address, fastd_peer_t *peer, const unsigned char key[32]) {
errno = 0;
if (sock->peer && peer != sock->peer)
- exit_bug(ctx, "packet without correct peer set on dynamic socket");
+ exit_bug("packet without correct peer set on dynamic socket");
if (peer) {
if (memcmp(&peer->protocol_config->public_key, key, PUBLICKEYBYTES) == 0)
return peer;
- if (fastd_peer_owns_address(ctx, peer, address)) {
+ if (fastd_peer_owns_address(peer, address)) {
errno = EPERM;
return NULL;
}
}
- return find_sender_key(ctx, address, key);
+ return find_sender_key(address, key);
}
static size_t key_count(const unsigned char key[32]) {
@@ -456,7 +456,7 @@ static size_t key_count(const unsigned char key[32]) {
return ret;
}
-bool fastd_protocol_ec25519_fhmqvc_peer_check(fastd_context_t *ctx, fastd_peer_config_t *peer_conf) {
+bool fastd_protocol_ec25519_fhmqvc_peer_check(fastd_peer_config_t *peer_conf) {
if (!peer_conf->protocol_config)
return false;
@@ -466,18 +466,18 @@ bool fastd_protocol_ec25519_fhmqvc_peer_check(fastd_context_t *ctx, fastd_peer_c
if (key_count(peer_conf->protocol_config->public_key.u8) > 1) {
char buf[65];
hexdump(buf, peer_conf->protocol_config->public_key.u8);
- pr_warn(ctx, "more than one peer is configured with key %s, disabling %s", buf, peer_conf->name);
+ pr_warn("more than one peer is configured with key %s, disabling %s", buf, peer_conf->name);
return false;
}
return true;
}
-bool fastd_protocol_ec25519_fhmqvc_peer_check_temporary(fastd_context_t *ctx, fastd_peer_t *peer) {
+bool fastd_protocol_ec25519_fhmqvc_peer_check_temporary(fastd_peer_t *peer) {
if (key_count(peer->protocol_config->public_key.u8)) {
char buf[65];
hexdump(buf, peer->protocol_config->public_key.u8);
- pr_info(ctx, "key %s is configured now, deleting temporary peer.", buf);
+ pr_info("key %s is configured now, deleting temporary peer.", buf);
return false;
}
@@ -488,18 +488,18 @@ static inline bool allow_unknown(void) {
return fastd_shell_command_isset(&conf.on_verify);
}
-static inline fastd_peer_t* add_temporary(fastd_context_t *ctx, const fastd_peer_address_t *addr, const unsigned char key[32]) {
+static inline fastd_peer_t* add_temporary(const fastd_peer_address_t *addr, const unsigned char key[32]) {
if (!allow_unknown()) {
- pr_debug(ctx, "ignoring handshake from %I (unknown key)", addr);
+ pr_debug("ignoring handshake from %I (unknown key)", addr);
return NULL;
}
if (key_count(key)) {
- pr_debug(ctx, "ignoring handshake from %I (disabled key)", addr);
+ pr_debug("ignoring handshake from %I (disabled key)", addr);
return NULL;
}
- fastd_peer_t *peer = fastd_peer_add_temporary(ctx);
+ fastd_peer_t *peer = fastd_peer_add_temporary();
peer->protocol_config = malloc(sizeof(fastd_protocol_peer_config_t));
memcpy(&peer->protocol_config->public_key, key, PUBLICKEYBYTES);
@@ -511,79 +511,79 @@ static inline fastd_peer_t* add_temporary(fastd_context_t *ctx, const fastd_peer
}
-void fastd_protocol_ec25519_fhmqvc_handshake_init(fastd_context_t *ctx, const fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, fastd_peer_t *peer) {
- fastd_protocol_ec25519_fhmqvc_maintenance(ctx);
+void fastd_protocol_ec25519_fhmqvc_handshake_init(const fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, fastd_peer_t *peer) {
+ fastd_protocol_ec25519_fhmqvc_maintenance();
- fastd_buffer_t buffer = fastd_handshake_new_init(ctx, 3*(4+PUBLICKEYBYTES) /* sender key, receipient key, handshake key */);
+ fastd_buffer_t buffer = fastd_handshake_new_init(3*(4+PUBLICKEYBYTES) /* sender key, receipient key, handshake key */);
- fastd_handshake_add(ctx, &buffer, RECORD_SENDER_KEY, PUBLICKEYBYTES, &conf.protocol_config->key.public);
+ fastd_handshake_add(&buffer, RECORD_SENDER_KEY, PUBLICKEYBYTES, &conf.protocol_config->key.public);
if (peer)
- fastd_handshake_add(ctx, &buffer, RECORD_RECEIPIENT_KEY, PUBLICKEYBYTES, &peer->protocol_config->public_key);
+ fastd_handshake_add(&buffer, RECORD_RECEIPIENT_KEY, PUBLICKEYBYTES, &peer->protocol_config->public_key);
else
- pr_debug(ctx, "sending handshake to unknown peer %I", remote_addr);
+ pr_debug("sending handshake to unknown peer %I", remote_addr);
- fastd_handshake_add(ctx, &buffer, RECORD_SENDER_HANDSHAKE_KEY, PUBLICKEYBYTES, &ctx->protocol_state->handshake_key.key.public);
+ fastd_handshake_add(&buffer, RECORD_SENDER_HANDSHAKE_KEY, PUBLICKEYBYTES, &ctx.protocol_state->handshake_key.key.public);
if (!peer || !fastd_peer_is_established(peer))
- fastd_shell_command_exec(ctx, &conf.on_connect, peer, (local_addr && local_addr->sa.sa_family) ? local_addr : sock->bound_addr, remote_addr);
+ fastd_shell_command_exec(&conf.on_connect, peer, (local_addr && local_addr->sa.sa_family) ? local_addr : sock->bound_addr, remote_addr);
- fastd_send_handshake(ctx, sock, local_addr, remote_addr, peer, buffer);
+ fastd_send_handshake(sock, local_addr, remote_addr, peer, buffer);
}
-void fastd_protocol_ec25519_fhmqvc_handshake_handle(fastd_context_t *ctx, fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr,
+void fastd_protocol_ec25519_fhmqvc_handshake_handle(fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr,
fastd_peer_t *peer, const fastd_handshake_t *handshake, const fastd_method_info_t *method) {
- fastd_protocol_ec25519_fhmqvc_maintenance(ctx);
+ fastd_protocol_ec25519_fhmqvc_maintenance();
if (!has_field(handshake, RECORD_SENDER_KEY, PUBLICKEYBYTES)) {
- pr_debug(ctx, "received handshake without sender key from %I", remote_addr);
+ pr_debug("received handshake without sender key from %I", remote_addr);
return;
}
- peer = match_sender_key(ctx, sock, remote_addr, peer, handshake->records[RECORD_SENDER_KEY].data);
+ peer = match_sender_key(sock, remote_addr, peer, handshake->records[RECORD_SENDER_KEY].data);
if (!peer) {
switch (errno) {
case EPERM:
- pr_debug(ctx, "ignoring handshake from %I (incorrect source address)", remote_addr);
+ pr_debug("ignoring handshake from %I (incorrect source address)", remote_addr);
return;
case ENOENT:
- peer = add_temporary(ctx, remote_addr, handshake->records[RECORD_SENDER_KEY].data);
+ peer = add_temporary(remote_addr, handshake->records[RECORD_SENDER_KEY].data);
if (peer)
break;
return;
default:
- exit_bug(ctx, "match_sender_key: unknown error");
+ exit_bug("match_sender_key: unknown error");
}
}
- if (fastd_peer_is_temporary(peer) && !fastd_peer_verify_temporary(ctx, peer, local_addr, remote_addr)) {
- pr_debug(ctx, "ignoring handshake from %P[%I] (verification failed)", peer, remote_addr);
- fastd_peer_delete(ctx, peer);
+ if (fastd_peer_is_temporary(peer) && !fastd_peer_verify_temporary(peer, local_addr, remote_addr)) {
+ pr_debug("ignoring handshake from %P[%I] (verification failed)", peer, remote_addr);
+ fastd_peer_delete(peer);
return;
}
- if (!fastd_peer_may_connect(ctx, peer)) {
- pr_debug(ctx, "ignoring handshake from %P[%I] because of local constraints", peer, remote_addr);
+ if (!fastd_peer_may_connect(peer)) {
+ pr_debug("ignoring handshake from %P[%I] because of local constraints", peer, remote_addr);
return;
}
- if (!fastd_timed_out(ctx, &peer->establish_handshake_timeout)) {
- pr_debug(ctx, "received repeated handshakes from %P[%I], ignoring", peer, remote_addr);
+ if (!fastd_timed_out(&peer->establish_handshake_timeout)) {
+ pr_debug("received repeated handshakes from %P[%I], ignoring", peer, remote_addr);
return;
}
if (has_field(handshake, RECORD_RECEIPIENT_KEY, PUBLICKEYBYTES)) {
if (memcmp(&conf.protocol_config->key.public, handshake->records[RECORD_RECEIPIENT_KEY].data, PUBLICKEYBYTES) != 0) {
- pr_debug(ctx, "received protocol handshake with wrong receipient key from %P[%I]", peer, remote_addr);
+ pr_debug("received protocol handshake with wrong receipient key from %P[%I]", peer, remote_addr);
return;
}
}
if (!has_field(handshake, RECORD_SENDER_HANDSHAKE_KEY, PUBLICKEYBYTES)) {
- pr_debug(ctx, "received handshake without sender handshake key from %P[%I]", peer, remote_addr);
+ pr_debug("received handshake without sender handshake key from %P[%I]", peer, remote_addr);
return;
}
@@ -591,65 +591,65 @@ void fastd_protocol_ec25519_fhmqvc_handshake_handle(fastd_context_t *ctx, fastd_
memcpy(&peer_handshake_key, handshake->records[RECORD_SENDER_HANDSHAKE_KEY].data, PUBLICKEYBYTES);
if (handshake->type == 1) {
- if (!fastd_timed_out(ctx, &peer->last_handshake_response_timeout)
+ if (!fastd_timed_out(&peer->last_handshake_response_timeout)
&& fastd_peer_address_equal(remote_addr, &peer->last_handshake_response_address)) {
- pr_debug(ctx, "not responding to repeated handshake from %P[%I]", peer, remote_addr);
+ pr_debug("not responding to repeated handshake from %P[%I]", peer, remote_addr);
return;
}
- pr_verbose(ctx, "received handshake from %P[%I]%s%s", peer, remote_addr, handshake->peer_version ? " using fastd " : "", handshake->peer_version ?: "");
+ pr_verbose("received handshake from %P[%I]%s%s", peer, remote_addr, handshake->peer_version ? " using fastd " : "", handshake->peer_version ?: "");
- peer->last_handshake_response_timeout = fastd_in_seconds(ctx, conf.min_handshake_interval);
+ peer->last_handshake_response_timeout = fastd_in_seconds(conf.min_handshake_interval);
peer->last_handshake_response_address = *remote_addr;
- respond_handshake(ctx, sock, local_addr, remote_addr, peer, &ctx->protocol_state->handshake_key, &peer_handshake_key, handshake, method);
+ respond_handshake(sock, local_addr, remote_addr, peer, &ctx.protocol_state->handshake_key, &peer_handshake_key, handshake, method);
return;
}
if (!has_field(handshake, RECORD_RECEIPIENT_KEY, PUBLICKEYBYTES)) {
- pr_debug(ctx, "received handshake reply without receipient key from %P[%I]", peer, remote_addr);
+ pr_debug("received handshake reply without receipient key from %P[%I]", peer, remote_addr);
return;
}
if (!has_field(handshake, RECORD_RECEIPIENT_HANDSHAKE_KEY, PUBLICKEYBYTES)) {
- pr_debug(ctx, "received handshake reply without receipient handshake key from %P[%I]", peer, remote_addr);
+ pr_debug("received handshake reply without receipient handshake key from %P[%I]", peer, remote_addr);
return;
}
if (!secure_handshake(handshake)) {
if (conf.secure_handshakes || !has_field(handshake, RECORD_T, HASHBYTES)) {
- pr_debug(ctx, "received handshake reply without HMAC from %P[%I]", peer, remote_addr);
+ pr_debug("received handshake reply without HMAC from %P[%I]", peer, remote_addr);
return;
}
}
handshake_key_t *handshake_key;
- if (is_handshake_key_valid(ctx, &ctx->protocol_state->handshake_key) &&
- memcmp(&ctx->protocol_state->handshake_key.key.public, handshake->records[RECORD_RECEIPIENT_HANDSHAKE_KEY].data, PUBLICKEYBYTES) == 0) {
- handshake_key = &ctx->protocol_state->handshake_key;
+ if (is_handshake_key_valid(&ctx.protocol_state->handshake_key) &&
+ memcmp(&ctx.protocol_state->handshake_key.key.public, handshake->records[RECORD_RECEIPIENT_HANDSHAKE_KEY].data, PUBLICKEYBYTES) == 0) {
+ handshake_key = &ctx.protocol_state->handshake_key;
}
- else if (is_handshake_key_valid(ctx, &ctx->protocol_state->prev_handshake_key) &&
- memcmp(&ctx->protocol_state->prev_handshake_key.key.public, handshake->records[RECORD_RECEIPIENT_HANDSHAKE_KEY].data, PUBLICKEYBYTES) == 0) {
- handshake_key = &ctx->protocol_state->prev_handshake_key;
+ else if (is_handshake_key_valid(&ctx.protocol_state->prev_handshake_key) &&
+ memcmp(&ctx.protocol_state->prev_handshake_key.key.public, handshake->records[RECORD_RECEIPIENT_HANDSHAKE_KEY].data, PUBLICKEYBYTES) == 0) {
+ handshake_key = &ctx.protocol_state->prev_handshake_key;
}
else {
- pr_debug(ctx, "received handshake reply with unexpected receipient handshake key from %P[%I]", peer, remote_addr);
+ pr_debug("received handshake reply with unexpected receipient handshake key from %P[%I]", peer, remote_addr);
return;
}
switch (handshake->type) {
case 2:
- pr_verbose(ctx, "received handshake response from %P[%I]%s%s", peer, remote_addr, handshake->peer_version ? " using fastd " : "", handshake->peer_version ?: "");
+ pr_verbose("received handshake response from %P[%I]%s%s", peer, remote_addr, handshake->peer_version ? " using fastd " : "", handshake->peer_version ?: "");
- finish_handshake(ctx, sock, local_addr, remote_addr, peer, handshake_key, &peer_handshake_key, handshake, method);
+ finish_handshake(sock, local_addr, remote_addr, peer, handshake_key, &peer_handshake_key, handshake, method);
break;
case 3:
- pr_debug(ctx, "received handshake finish from %P[%I]%s%s", peer, remote_addr, handshake->peer_version ? " using fastd " : "", handshake->peer_version ?: "");
+ pr_debug("received handshake finish from %P[%I]%s%s", peer, remote_addr, handshake->peer_version ? " using fastd " : "", handshake->peer_version ?: "");
- handle_finish_handshake(ctx, sock, local_addr, remote_addr, peer, handshake_key, &peer_handshake_key, handshake, method);
+ handle_finish_handshake(sock, local_addr, remote_addr, peer, handshake_key, &peer_handshake_key, handshake, method);
break;
default:
- pr_debug(ctx, "received handshake reply with unknown type %u from %P[%I]", handshake->type, peer, remote_addr);
+ pr_debug("received handshake reply with unknown type %u from %P[%I]", handshake->type, peer, remote_addr);
}
}
diff --git a/src/protocols/ec25519_fhmqvc/handshake.h b/src/protocols/ec25519_fhmqvc/handshake.h
index 867b0fa..1578913 100644
--- a/src/protocols/ec25519_fhmqvc/handshake.h
+++ b/src/protocols/ec25519_fhmqvc/handshake.h
@@ -43,10 +43,10 @@ struct fastd_protocol_state {
};
-static inline bool is_handshake_key_valid(fastd_context_t *ctx, const handshake_key_t *handshake_key) {
- return !fastd_timed_out(ctx, &handshake_key->valid_till);
+static inline bool is_handshake_key_valid(const handshake_key_t *handshake_key) {
+ return !fastd_timed_out(&handshake_key->valid_till);
}
-static inline bool is_handshake_key_preferred(fastd_context_t *ctx, const handshake_key_t *handshake_key) {
- return !fastd_timed_out(ctx, &handshake_key->preferred_till);
+static inline bool is_handshake_key_preferred(const handshake_key_t *handshake_key) {
+ return !fastd_timed_out(&handshake_key->preferred_till);
}
diff --git a/src/protocols/ec25519_fhmqvc/state.c b/src/protocols/ec25519_fhmqvc/state.c
index fe0dcde..7f3b847 100644
--- a/src/protocols/ec25519_fhmqvc/state.c
+++ b/src/protocols/ec25519_fhmqvc/state.c
@@ -28,17 +28,17 @@
#include "../../crypto.h"
-static void init_protocol_state(fastd_context_t *ctx) {
- if (!ctx->protocol_state) {
- ctx->protocol_state = calloc(1, sizeof(fastd_protocol_state_t));
+static void init_protocol_state(void) {
+ if (!ctx.protocol_state) {
+ ctx.protocol_state = calloc(1, sizeof(fastd_protocol_state_t));
- ctx->protocol_state->prev_handshake_key.preferred_till = ctx->now;
- ctx->protocol_state->handshake_key.preferred_till = ctx->now;
+ ctx.protocol_state->prev_handshake_key.preferred_till = ctx.now;
+ ctx.protocol_state->handshake_key.preferred_till = ctx.now;
}
}
-static void new_handshake_key(fastd_context_t *ctx, keypair_t *key) {
- fastd_random_bytes(ctx, key->secret.p, 32, false);
+static void new_handshake_key(keypair_t *key) {
+ fastd_random_bytes(key->secret.p, 32, false);
ecc_25519_gf_sanitize_secret(&key->secret, &key->secret);
ecc_25519_work_t work;
@@ -46,51 +46,51 @@ static void new_handshake_key(fastd_context_t *ctx, keypair_t *key) {
ecc_25519_store_packed(&key->public.int256, &work);
}
-void fastd_protocol_ec25519_fhmqvc_maintenance(fastd_context_t *ctx) {
- init_protocol_state(ctx);
+void fastd_protocol_ec25519_fhmqvc_maintenance(void) {
+ init_protocol_state();
- if (!is_handshake_key_preferred(ctx, &ctx->protocol_state->handshake_key)) {
- pr_debug(ctx, "generating new handshake key");
+ if (!is_handshake_key_preferred(&ctx.protocol_state->handshake_key)) {
+ pr_debug("generating new handshake key");
- ctx->protocol_state->prev_handshake_key = ctx->protocol_state->handshake_key;
+ ctx.protocol_state->prev_handshake_key = ctx.protocol_state->handshake_key;
- ctx->protocol_state->handshake_key.serial++;
+ ctx.protocol_state->handshake_key.serial++;
- new_handshake_key(ctx, &ctx->protocol_state->handshake_key.key);
+ new_handshake_key(&ctx.protocol_state->handshake_key.key);
- ctx->protocol_state->handshake_key.preferred_till = fastd_in_seconds(ctx, 15);
- ctx->protocol_state->handshake_key.valid_till = fastd_in_seconds(ctx, 30);
+ ctx.protocol_state->handshake_key.preferred_till = fastd_in_seconds(15);
+ ctx.protocol_state->handshake_key.valid_till = fastd_in_seconds(30);
}
}
-void fastd_protocol_ec25519_fhmqvc_init_peer_state(fastd_context_t *ctx, fastd_peer_t *peer) {
- init_protocol_state(ctx);
+void fastd_protocol_ec25519_fhmqvc_init_peer_state(fastd_peer_t *peer) {
+ init_protocol_state();
if (peer->protocol_state)
- exit_bug(ctx, "tried to reinit peer state");
+ exit_bug("tried to reinit peer state");
peer->protocol_state = calloc(1, sizeof(fastd_protocol_peer_state_t));
- peer->protocol_state->last_serial = ctx->protocol_state->handshake_key.serial;
+ peer->protocol_state->last_serial = ctx.protocol_state->handshake_key.serial;
}
-static void reset_session(fastd_context_t *ctx, protocol_session_t *session) {
+static void reset_session(protocol_session_t *session) {
if (session->method)
- session->method->provider->session_free(ctx, session->method_state);
+ session->method->provider->session_free(session->method_state);
secure_memzero(session, sizeof(protocol_session_t));
}
-void fastd_protocol_ec25519_fhmqvc_reset_peer_state(fastd_context_t *ctx, fastd_peer_t *peer) {
+void fastd_protocol_ec25519_fhmqvc_reset_peer_state(fastd_peer_t *peer) {
if (!peer->protocol_state)
return;
- reset_session(ctx, &peer->protocol_state->old_session);
- reset_session(ctx, &peer->protocol_state->session);
+ reset_session(&peer->protocol_state->old_session);
+ reset_session(&peer->protocol_state->session);
}
-void fastd_protocol_ec25519_fhmqvc_free_peer_state(fastd_context_t *ctx, fastd_peer_t *peer) {
+void fastd_protocol_ec25519_fhmqvc_free_peer_state(fastd_peer_t *peer) {
if (peer->protocol_state) {
- reset_session(ctx, &peer->protocol_state->old_session);
- reset_session(ctx, &peer->protocol_state->session);
+ reset_session(&peer->protocol_state->old_session);
+ reset_session(&peer->protocol_state->session);
free(peer->protocol_state);
}
diff --git a/src/protocols/ec25519_fhmqvc/util.c b/src/protocols/ec25519_fhmqvc/util.c
index a72ebbf..5bd23b3 100644
--- a/src/protocols/ec25519_fhmqvc/util.c
+++ b/src/protocols/ec25519_fhmqvc/util.c
@@ -34,14 +34,14 @@ static inline void print_hexdump(const char *desc, unsigned char d[32]) {
printf("%s%s\n", desc, buf);
}
-void fastd_protocol_ec25519_fhmqvc_generate_key(fastd_context_t *ctx) {
+void fastd_protocol_ec25519_fhmqvc_generate_key(void) {
ecc_int256_t secret_key;
ecc_int256_t public_key;
if (!conf.machine_readable)
- pr_info(ctx, "Reading 32 bytes from /dev/random...");
+ pr_info("Reading 32 bytes from /dev/random...");
- fastd_random_bytes(ctx, secret_key.p, 32, true);
+ fastd_random_bytes(secret_key.p, 32, true);
ecc_25519_gf_sanitize_secret(&secret_key, &secret_key);
ecc_25519_work_t work;
@@ -79,7 +79,7 @@ void fastd_protocol_ec25519_fhmqvc_set_shell_env(const fastd_peer_t *peer) {
}
}
-bool fastd_protocol_ec25519_fhmqvc_describe_peer(const fastd_context_t *ctx UNUSED, const fastd_peer_t *peer, char *buf, size_t len) {
+bool fastd_protocol_ec25519_fhmqvc_describe_peer(const fastd_peer_t *peer, char *buf, size_t len) {
if (peer && peer->protocol_config) {
char dumpbuf[65];