summaryrefslogtreecommitdiffstats
path: root/src/methods
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/methods
parentb9c8603931203f5d94091f7a05a5967304b62fbd (diff)
downloadfastd-7adeb6e88196a594ec3d36ffc1c658340ffcd7bc.tar
fastd-7adeb6e88196a594ec3d36ffc1c658340ffcd7bc.zip
Make ctx global
Diffstat (limited to 'src/methods')
-rw-r--r--src/methods/cipher_test/cipher_test.c42
-rw-r--r--src/methods/common.c18
-rw-r--r--src/methods/common.h36
-rw-r--r--src/methods/composed_gmac/composed_gmac.c42
-rw-r--r--src/methods/generic_gmac/generic_gmac.c44
-rw-r--r--src/methods/generic_poly1305/generic_poly1305.c58
-rw-r--r--src/methods/null/null.c20
-rw-r--r--src/methods/xsalsa20_poly1305/xsalsa20_poly1305.c76
8 files changed, 168 insertions, 168 deletions
diff --git a/src/methods/cipher_test/cipher_test.c b/src/methods/cipher_test/cipher_test.c
index 0cec4b0..52bca0f 100644
--- a/src/methods/cipher_test/cipher_test.c
+++ b/src/methods/cipher_test/cipher_test.c
@@ -70,49 +70,49 @@ static void method_destroy(fastd_method_t *method) {
free(method);
}
-static size_t method_key_length(fastd_context_t *ctx UNUSED, const fastd_method_t *method) {
+static size_t method_key_length(const fastd_method_t *method) {
return method->cipher_info->key_length;
}
-static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx, const fastd_method_t *method, const uint8_t *secret, bool initiator) {
+static fastd_method_session_state_t* method_session_init(const fastd_method_t *method, const uint8_t *secret, bool initiator) {
fastd_method_session_state_t *session = malloc(sizeof(fastd_method_session_state_t));
- fastd_method_common_init(ctx, &session->common, initiator);
+ fastd_method_common_init(&session->common, initiator);
session->method = method;
session->cipher = fastd_cipher_get(method->cipher_info);
session->cipher_state = session->cipher->init(secret);
- pr_warn(ctx, "using cipher-test method; this method must be used for testing and benchmarks only");
+ pr_warn("using cipher-test method; this method must be used for testing and benchmarks only");
return session;
}
-static bool method_session_is_valid(fastd_context_t *ctx, fastd_method_session_state_t *session) {
- return (session && fastd_method_session_common_is_valid(ctx, &session->common));
+static bool method_session_is_valid(fastd_method_session_state_t *session) {
+ return (session && fastd_method_session_common_is_valid(&session->common));
}
-static bool method_session_is_initiator(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session) {
+static bool method_session_is_initiator(fastd_method_session_state_t *session) {
return fastd_method_session_common_is_initiator(&session->common);
}
-static bool method_session_want_refresh(fastd_context_t *ctx, fastd_method_session_state_t *session) {
- return fastd_method_session_common_want_refresh(ctx, &session->common);
+static bool method_session_want_refresh(fastd_method_session_state_t *session) {
+ return fastd_method_session_common_want_refresh(&session->common);
}
-static void method_session_superseded(fastd_context_t *ctx, fastd_method_session_state_t *session) {
- fastd_method_session_common_superseded(ctx, &session->common);
+static void method_session_superseded(fastd_method_session_state_t *session) {
+ fastd_method_session_common_superseded(&session->common);
}
-static void method_session_free(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session) {
+static void method_session_free(fastd_method_session_state_t *session) {
if (session) {
session->cipher->free(session->cipher_state);
free(session);
}
}
-static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer UNUSED, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) {
+static bool method_encrypt(fastd_peer_t *peer UNUSED, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) {
size_t tail_len = alignto(in.len, sizeof(fastd_block128_t))-in.len;
- *out = fastd_buffer_alloc(ctx, in.len, alignto(COMMON_HEADBYTES, 16), sizeof(fastd_block128_t)+tail_len);
+ *out = fastd_buffer_alloc(in.len, alignto(COMMON_HEADBYTES, 16), sizeof(fastd_block128_t)+tail_len);
if (tail_len)
memset(in.data+in.len, 0, tail_len);
@@ -134,23 +134,23 @@ static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer UNUSED, fast
fastd_buffer_free(in);
- fastd_method_put_common_header(ctx, out, session->common.send_nonce, 0);
+ fastd_method_put_common_header(out, session->common.send_nonce, 0);
fastd_method_increment_nonce(&session->common);
return true;
}
-static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) {
+static bool method_decrypt(fastd_peer_t *peer, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) {
if (in.len < COMMON_HEADBYTES)
return false;
- if (!method_session_is_valid(ctx, session))
+ if (!method_session_is_valid(session))
return false;
uint8_t in_nonce[COMMON_NONCEBYTES];
uint8_t flags;
int64_t age;
- if (!fastd_method_handle_common_header(ctx, &session->common, &in, in_nonce, &flags, &age))
+ if (!fastd_method_handle_common_header(&session->common, &in, in_nonce, &flags, &age))
return false;
if (flags)
@@ -160,7 +160,7 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
fastd_method_expand_nonce(nonce, in_nonce, sizeof(nonce));
size_t tail_len = alignto(in.len, sizeof(fastd_block128_t))-in.len;
- *out = fastd_buffer_alloc(ctx, in.len, 0, tail_len);
+ *out = fastd_buffer_alloc(in.len, 0, tail_len);
int n_blocks = block_count(in.len, sizeof(fastd_block128_t));
@@ -174,9 +174,9 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
return false;
}
- if (!fastd_method_reorder_check(ctx, peer, &session->common, in_nonce, age)) {
+ if (!fastd_method_reorder_check(peer, &session->common, in_nonce, age)) {
fastd_buffer_free(*out);
- *out = fastd_buffer_alloc(ctx, 0, 0, 0);
+ *out = fastd_buffer_alloc(0, 0, 0);
}
fastd_buffer_free(in);
diff --git a/src/methods/common.c b/src/methods/common.c
index 166d3ab..17722cf 100644
--- a/src/methods/common.c
+++ b/src/methods/common.c
@@ -27,11 +27,11 @@
#include "common.h"
-void fastd_method_common_init(fastd_context_t *ctx, fastd_method_common_t *session, bool initiator) {
+void fastd_method_common_init(fastd_method_common_t *session, bool initiator) {
memset(session, 0, sizeof(*session));
- session->valid_till = fastd_in_seconds(ctx, conf.key_valid);
- session->refresh_after = fastd_in_seconds(ctx, conf.key_refresh - fastd_rand(ctx, 0, conf.key_refresh_splay));
+ session->valid_till = fastd_in_seconds(conf.key_valid);
+ session->refresh_after = fastd_in_seconds(conf.key_refresh - fastd_rand(0, conf.key_refresh_splay));
if (initiator) {
session->send_nonce[COMMON_NONCEBYTES-1] = 3;
@@ -42,7 +42,7 @@ void fastd_method_common_init(fastd_context_t *ctx, fastd_method_common_t *sessi
}
}
-bool fastd_method_is_nonce_valid(fastd_context_t *ctx, const fastd_method_common_t *session, const uint8_t nonce[COMMON_NONCEBYTES], int64_t *age) {
+bool fastd_method_is_nonce_valid(const fastd_method_common_t *session, const uint8_t nonce[COMMON_NONCEBYTES], int64_t *age) {
if ((nonce[0] & 1) != (session->receive_nonce[0] & 1))
return false;
@@ -57,7 +57,7 @@ bool fastd_method_is_nonce_valid(fastd_context_t *ctx, const fastd_method_common
*age >>= 1;
if (*age >= 0) {
- if (fastd_timed_out(ctx, &session->reorder_timeout))
+ if (fastd_timed_out(&session->reorder_timeout))
return false;
if (*age > 64)
@@ -67,7 +67,7 @@ bool fastd_method_is_nonce_valid(fastd_context_t *ctx, const fastd_method_common
return true;
}
-bool fastd_method_reorder_check(fastd_context_t *ctx, fastd_peer_t *peer, fastd_method_common_t *session, const uint8_t nonce[COMMON_NONCEBYTES], int64_t age) {
+bool fastd_method_reorder_check(fastd_peer_t *peer, fastd_method_common_t *session, const uint8_t nonce[COMMON_NONCEBYTES], int64_t age) {
if (age < 0) {
size_t shift = age < (-64) ? 64 : ((size_t)-age);
@@ -79,15 +79,15 @@ bool fastd_method_reorder_check(fastd_context_t *ctx, fastd_peer_t *peer, fastd_
session->receive_reorder_seen |= (1 << (shift-1));
memcpy(session->receive_nonce, nonce, COMMON_NONCEBYTES);
- session->reorder_timeout = fastd_in_seconds(ctx, conf.reorder_time);
+ session->reorder_timeout = fastd_in_seconds(conf.reorder_time);
return true;
}
else if (age == 0 || session->receive_reorder_seen & (1 << (age-1))) {
- pr_debug(ctx, "dropping duplicate packet from %P (age %u)", peer, (unsigned)age);
+ pr_debug("dropping duplicate packet from %P (age %u)", peer, (unsigned)age);
return false;
}
else {
- pr_debug2(ctx, "accepting reordered packet from %P (age %u)", peer, (unsigned)age);
+ pr_debug2("accepting reordered packet from %P (age %u)", peer, (unsigned)age);
session->receive_reorder_seen |= (1 << (age-1));
return true;
}
diff --git a/src/methods/common.h b/src/methods/common.h
index 510ad3f..ea4a13a 100644
--- a/src/methods/common.h
+++ b/src/methods/common.h
@@ -46,34 +46,34 @@ typedef struct fastd_method_common {
} fastd_method_common_t;
-void fastd_method_common_init(fastd_context_t *ctx, fastd_method_common_t *session, bool initiator);
-bool fastd_method_is_nonce_valid(fastd_context_t *ctx, const fastd_method_common_t *session, const uint8_t nonce[COMMON_NONCEBYTES], int64_t *age);
-bool fastd_method_reorder_check(fastd_context_t *ctx, fastd_peer_t *peer, fastd_method_common_t *session, const uint8_t nonce[COMMON_NONCEBYTES], int64_t age);
+void fastd_method_common_init(fastd_method_common_t *session, bool initiator);
+bool fastd_method_is_nonce_valid(const fastd_method_common_t *session, const uint8_t nonce[COMMON_NONCEBYTES], int64_t *age);
+bool fastd_method_reorder_check(fastd_peer_t *peer, fastd_method_common_t *session, const uint8_t nonce[COMMON_NONCEBYTES], int64_t age);
-static inline bool fastd_method_session_common_is_valid(fastd_context_t *ctx, const fastd_method_common_t *session) {
+static inline bool fastd_method_session_common_is_valid(const fastd_method_common_t *session) {
if (session->send_nonce[0] == 0xff && session->send_nonce[1] == 0xff)
return false;
- return (!fastd_timed_out(ctx, &session->valid_till));
+ return (!fastd_timed_out(&session->valid_till));
}
static inline bool fastd_method_session_common_is_initiator(const fastd_method_common_t *session) {
return (session->send_nonce[COMMON_NONCEBYTES-1] & 1);
}
-static inline bool fastd_method_session_common_want_refresh(fastd_context_t *ctx, const fastd_method_common_t *session) {
+static inline bool fastd_method_session_common_want_refresh(const fastd_method_common_t *session) {
if (session->send_nonce[0] == 0xff)
return true;
- if (fastd_method_session_common_is_initiator(session) && fastd_timed_out(ctx, &session->refresh_after))
+ if (fastd_method_session_common_is_initiator(session) && fastd_timed_out(&session->refresh_after))
return true;
return false;
}
-static inline void fastd_method_session_common_superseded(fastd_context_t *ctx, fastd_method_common_t *session) {
- struct timespec valid_max = fastd_in_seconds(ctx, conf.key_valid_old);
+static inline void fastd_method_session_common_superseded(fastd_method_common_t *session) {
+ struct timespec valid_max = fastd_in_seconds(conf.key_valid_old);
if (timespec_after(&session->valid_till, &valid_max))
session->valid_till = valid_max;
@@ -91,19 +91,19 @@ static inline void fastd_method_increment_nonce(fastd_method_common_t *session)
}
}
-static inline void fastd_method_put_common_header(fastd_context_t *ctx, fastd_buffer_t *buffer, const uint8_t nonce[COMMON_NONCEBYTES], uint8_t flags) {
- fastd_buffer_pull_head_from(ctx, buffer, nonce, COMMON_NONCEBYTES);
- fastd_buffer_pull_head_from(ctx, buffer, &flags, 1);
+static inline void fastd_method_put_common_header(fastd_buffer_t *buffer, const uint8_t nonce[COMMON_NONCEBYTES], uint8_t flags) {
+ fastd_buffer_pull_head_from(buffer, nonce, COMMON_NONCEBYTES);
+ fastd_buffer_pull_head_from(buffer, &flags, 1);
}
-static inline void fastd_method_take_common_header(fastd_context_t *ctx, fastd_buffer_t *buffer, uint8_t nonce[COMMON_NONCEBYTES], uint8_t *flags) {
- fastd_buffer_push_head_to(ctx, buffer, flags, 1);
- fastd_buffer_push_head_to(ctx, buffer, nonce, COMMON_NONCEBYTES);
+static inline void fastd_method_take_common_header(fastd_buffer_t *buffer, uint8_t nonce[COMMON_NONCEBYTES], uint8_t *flags) {
+ fastd_buffer_push_head_to(buffer, flags, 1);
+ fastd_buffer_push_head_to(buffer, nonce, COMMON_NONCEBYTES);
}
-static inline bool fastd_method_handle_common_header(fastd_context_t *ctx, const fastd_method_common_t *session, fastd_buffer_t *buffer, uint8_t nonce[COMMON_NONCEBYTES], uint8_t *flags, int64_t *age) {
- fastd_method_take_common_header(ctx, buffer, nonce, flags);
- return fastd_method_is_nonce_valid(ctx, session, nonce, age);
+static inline bool fastd_method_handle_common_header(const fastd_method_common_t *session, fastd_buffer_t *buffer, uint8_t nonce[COMMON_NONCEBYTES], uint8_t *flags, int64_t *age) {
+ fastd_method_take_common_header(buffer, nonce, flags);
+ return fastd_method_is_nonce_valid(session, nonce, age);
}
diff --git a/src/methods/composed_gmac/composed_gmac.c b/src/methods/composed_gmac/composed_gmac.c
index c848bbf..887fb5c 100644
--- a/src/methods/composed_gmac/composed_gmac.c
+++ b/src/methods/composed_gmac/composed_gmac.c
@@ -112,14 +112,14 @@ static void method_destroy(fastd_method_t *method) {
}
-static size_t method_key_length(fastd_context_t *ctx UNUSED, const fastd_method_t *method) {
+static size_t method_key_length(const fastd_method_t *method) {
return method->cipher_info->key_length + method->gmac_cipher_info->key_length;
}
-static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx, const fastd_method_t *method, const uint8_t *secret, bool initiator) {
+static fastd_method_session_state_t* method_session_init(const fastd_method_t *method, const uint8_t *secret, bool initiator) {
fastd_method_session_state_t *session = malloc(sizeof(fastd_method_session_state_t));
- fastd_method_common_init(ctx, &session->common, initiator);
+ fastd_method_common_init(&session->common, initiator);
session->method = method;
session->cipher = fastd_cipher_get(method->cipher_info);
@@ -148,23 +148,23 @@ static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx, c
return session;
}
-static bool method_session_is_valid(fastd_context_t *ctx, fastd_method_session_state_t *session) {
- return (session && fastd_method_session_common_is_valid(ctx, &session->common));
+static bool method_session_is_valid(fastd_method_session_state_t *session) {
+ return (session && fastd_method_session_common_is_valid(&session->common));
}
-static bool method_session_is_initiator(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session) {
+static bool method_session_is_initiator(fastd_method_session_state_t *session) {
return fastd_method_session_common_is_initiator(&session->common);
}
-static bool method_session_want_refresh(fastd_context_t *ctx, fastd_method_session_state_t *session) {
- return fastd_method_session_common_want_refresh(ctx, &session->common);
+static bool method_session_want_refresh(fastd_method_session_state_t *session) {
+ return fastd_method_session_common_want_refresh(&session->common);
}
-static void method_session_superseded(fastd_context_t *ctx, fastd_method_session_state_t *session) {
- fastd_method_session_common_superseded(ctx, &session->common);
+static void method_session_superseded(fastd_method_session_state_t *session) {
+ fastd_method_session_common_superseded(&session->common);
}
-static void method_session_free(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session) {
+static void method_session_free(fastd_method_session_state_t *session) {
if (session) {
session->cipher->free(session->cipher_state);
session->gmac_cipher->free(session->gmac_cipher_state);
@@ -183,9 +183,9 @@ static inline void put_size(fastd_block128_t *out, size_t len) {
out->b[7] = len << 3;
}
-static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer UNUSED, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) {
+static bool method_encrypt(fastd_peer_t *peer UNUSED, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) {
size_t tail_len = alignto(in.len, sizeof(fastd_block128_t))-in.len;
- *out = fastd_buffer_alloc(ctx, sizeof(fastd_block128_t)+in.len, alignto(COMMON_HEADBYTES, 16), sizeof(fastd_block128_t)+tail_len);
+ *out = fastd_buffer_alloc(sizeof(fastd_block128_t)+in.len, alignto(COMMON_HEADBYTES, 16), sizeof(fastd_block128_t)+tail_len);
if (tail_len)
memset(in.data+in.len, 0, tail_len);
@@ -226,23 +226,23 @@ static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer UNUSED, fast
fastd_buffer_free(in);
- fastd_method_put_common_header(ctx, out, session->common.send_nonce, 0);
+ fastd_method_put_common_header(out, session->common.send_nonce, 0);
fastd_method_increment_nonce(&session->common);
return true;
}
-static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) {
+static bool method_decrypt(fastd_peer_t *peer, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) {
if (in.len < COMMON_HEADBYTES+sizeof(fastd_block128_t))
return false;
- if (!method_session_is_valid(ctx, session))
+ if (!method_session_is_valid(session))
return false;
uint8_t in_nonce[COMMON_NONCEBYTES];
uint8_t flags;
int64_t age;
- if (!fastd_method_handle_common_header(ctx, &session->common, &in, in_nonce, &flags, &age))
+ if (!fastd_method_handle_common_header(&session->common, &in, in_nonce, &flags, &age))
return false;
if (flags)
@@ -255,7 +255,7 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
fastd_method_expand_nonce(gmac_nonce, in_nonce, sizeof(gmac_nonce));
size_t tail_len = alignto(in.len, sizeof(fastd_block128_t))-in.len;
- *out = fastd_buffer_alloc(ctx, in.len, 0, tail_len);
+ *out = fastd_buffer_alloc(in.len, 0, tail_len);
int n_blocks = block_count(in.len, sizeof(fastd_block128_t));
@@ -282,11 +282,11 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
return false;
}
- fastd_buffer_push_head(ctx, out, sizeof(fastd_block128_t));
+ fastd_buffer_push_head(out, sizeof(fastd_block128_t));
- if (!fastd_method_reorder_check(ctx, peer, &session->common, in_nonce, age)) {
+ if (!fastd_method_reorder_check(peer, &session->common, in_nonce, age)) {
fastd_buffer_free(*out);
- *out = fastd_buffer_alloc(ctx, 0, 0, 0);
+ *out = fastd_buffer_alloc(0, 0, 0);
}
fastd_buffer_free(in);
diff --git a/src/methods/generic_gmac/generic_gmac.c b/src/methods/generic_gmac/generic_gmac.c
index 88c1880..6b84a95 100644
--- a/src/methods/generic_gmac/generic_gmac.c
+++ b/src/methods/generic_gmac/generic_gmac.c
@@ -89,14 +89,14 @@ static void method_destroy(fastd_method_t *method) {
free(method);
}
-static size_t method_key_length(fastd_context_t *ctx UNUSED, const fastd_method_t *method) {
+static size_t method_key_length(const fastd_method_t *method) {
return method->cipher_info->key_length;
}
-static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx, const fastd_method_t *method, const uint8_t *secret, bool initiator) {
+static fastd_method_session_state_t* method_session_init(const fastd_method_t *method, const uint8_t *secret, bool initiator) {
fastd_method_session_state_t *session = malloc(sizeof(fastd_method_session_state_t));
- fastd_method_common_init(ctx, &session->common, initiator);
+ fastd_method_common_init(&session->common, initiator);
session->method = method;
session->cipher = fastd_cipher_get(method->cipher_info);
@@ -121,23 +121,23 @@ static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx, c
return session;
}
-static bool method_session_is_valid(fastd_context_t *ctx, fastd_method_session_state_t *session) {
- return (session && fastd_method_session_common_is_valid(ctx, &session->common));
+static bool method_session_is_valid(fastd_method_session_state_t *session) {
+ return (session && fastd_method_session_common_is_valid(&session->common));
}
-static bool method_session_is_initiator(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session) {
+static bool method_session_is_initiator(fastd_method_session_state_t *session) {
return fastd_method_session_common_is_initiator(&session->common);
}
-static bool method_session_want_refresh(fastd_context_t *ctx, fastd_method_session_state_t *session) {
- return fastd_method_session_common_want_refresh(ctx, &session->common);
+static bool method_session_want_refresh(fastd_method_session_state_t *session) {
+ return fastd_method_session_common_want_refresh(&session->common);
}
-static void method_session_superseded(fastd_context_t *ctx, fastd_method_session_state_t *session) {
- fastd_method_session_common_superseded(ctx, &session->common);
+static void method_session_superseded(fastd_method_session_state_t *session) {
+ fastd_method_session_common_superseded(&session->common);
}
-static void method_session_free(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session) {
+static void method_session_free(fastd_method_session_state_t *session) {
if (session) {
session->cipher->free(session->cipher_state);
session->ghash->free(session->ghash_state);
@@ -155,11 +155,11 @@ static inline void put_size(fastd_block128_t *out, size_t len) {
out->b[15] = len << 3;
}
-static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer UNUSED, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) {
- fastd_buffer_pull_head_zero(ctx, &in, sizeof(fastd_block128_t));
+static bool method_encrypt(fastd_peer_t *peer UNUSED, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) {
+ fastd_buffer_pull_head_zero(&in, sizeof(fastd_block128_t));
size_t tail_len = alignto(in.len, sizeof(fastd_block128_t))-in.len;
- *out = fastd_buffer_alloc(ctx, in.len, alignto(COMMON_HEADBYTES, 16), sizeof(fastd_block128_t)+tail_len);
+ *out = fastd_buffer_alloc(in.len, alignto(COMMON_HEADBYTES, 16), sizeof(fastd_block128_t)+tail_len);
if (tail_len)
memset(in.data+in.len, 0, tail_len);
@@ -193,23 +193,23 @@ static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer UNUSED, fast
fastd_buffer_free(in);
- fastd_method_put_common_header(ctx, out, session->common.send_nonce, 0);
+ fastd_method_put_common_header(out, session->common.send_nonce, 0);
fastd_method_increment_nonce(&session->common);
return true;
}
-static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) {
+static bool method_decrypt(fastd_peer_t *peer, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) {
if (in.len < COMMON_HEADBYTES+sizeof(fastd_block128_t))
return false;
- if (!method_session_is_valid(ctx, session))
+ if (!method_session_is_valid(session))
return false;
uint8_t in_nonce[COMMON_NONCEBYTES];
uint8_t flags;
int64_t age;
- if (!fastd_method_handle_common_header(ctx, &session->common, &in, in_nonce, &flags, &age))
+ if (!fastd_method_handle_common_header(&session->common, &in, in_nonce, &flags, &age))
return false;
if (flags)
@@ -219,7 +219,7 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
fastd_method_expand_nonce(nonce, in_nonce, sizeof(nonce));
size_t tail_len = alignto(in.len, sizeof(fastd_block128_t))-in.len;
- *out = fastd_buffer_alloc(ctx, in.len, 0, tail_len);
+ *out = fastd_buffer_alloc(in.len, 0, tail_len);
int n_blocks = block_count(in.len, sizeof(fastd_block128_t));
@@ -245,11 +245,11 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
fastd_buffer_free(in);
- fastd_buffer_push_head(ctx, out, sizeof(fastd_block128_t));
+ fastd_buffer_push_head(out, sizeof(fastd_block128_t));
- if (!fastd_method_reorder_check(ctx, peer, &session->common, in_nonce, age)) {
+ if (!fastd_method_reorder_check(peer, &session->common, in_nonce, age)) {
fastd_buffer_free(*out);
- *out = fastd_buffer_alloc(ctx, 0, 0, 0);
+ *out = fastd_buffer_alloc(0, 0, 0);
}
return true;
diff --git a/src/methods/generic_poly1305/generic_poly1305.c b/src/methods/generic_poly1305/generic_poly1305.c
index a8eb3d1..0e2641c 100644
--- a/src/methods/generic_poly1305/generic_poly1305.c
+++ b/src/methods/generic_poly1305/generic_poly1305.c
@@ -79,14 +79,14 @@ static void method_destroy(fastd_method_t *method) {
free(method);
}
-static size_t method_key_length(fastd_context_t *ctx UNUSED, const fastd_method_t *method) {
+static size_t method_key_length(const fastd_method_t *method) {
return method->cipher_info->key_length;
}
-static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx, const fastd_method_t *method, const uint8_t *secret, bool initiator) {
+static fastd_method_session_state_t* method_session_init(const fastd_method_t *method, const uint8_t *secret, bool initiator) {
fastd_method_session_state_t *session = malloc(sizeof(fastd_method_session_state_t));
- fastd_method_common_init(ctx, &session->common, initiator);
+ fastd_method_common_init(&session->common, initiator);
session->method = method;
session->cipher = fastd_cipher_get(session->method->cipher_info);
session->cipher_state = session->cipher->init(secret);
@@ -94,34 +94,34 @@ static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx, c
return session;
}
-static bool method_session_is_valid(fastd_context_t *ctx, fastd_method_session_state_t *session) {
- return (session && fastd_method_session_common_is_valid(ctx, &session->common));
+static bool method_session_is_valid(fastd_method_session_state_t *session) {
+ return (session && fastd_method_session_common_is_valid(&session->common));
}
-static bool method_session_is_initiator(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session) {
+static bool method_session_is_initiator(fastd_method_session_state_t *session) {
return fastd_method_session_common_is_initiator(&session->common);
}
-static bool method_session_want_refresh(fastd_context_t *ctx, fastd_method_session_state_t *session) {
- return fastd_method_session_common_want_refresh(ctx, &session->common);
+static bool method_session_want_refresh(fastd_method_session_state_t *session) {
+ return fastd_method_session_common_want_refresh(&session->common);
}
-static void method_session_superseded(fastd_context_t *ctx, fastd_method_session_state_t *session) {
- fastd_method_session_common_superseded(ctx, &session->common);
+static void method_session_superseded(fastd_method_session_state_t *session) {
+ fastd_method_session_common_superseded(&session->common);
}
-static void method_session_free(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session) {
+static void method_session_free(fastd_method_session_state_t *session) {
if (session) {
session->cipher->free(session->cipher_state);
free(session);
}
}
-static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer UNUSED, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) {
- fastd_buffer_pull_head_zero(ctx, &in, KEYBYTES);
+static bool method_encrypt(fastd_peer_t *peer UNUSED, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) {
+ fastd_buffer_pull_head_zero(&in, KEYBYTES);
size_t tail_len = alignto(in.len, sizeof(fastd_block128_t))-in.len;
- *out = fastd_buffer_alloc(ctx, in.len, alignto(COMMON_HEADBYTES, 16), sizeof(fastd_block128_t)+tail_len);
+ *out = fastd_buffer_alloc(in.len, alignto(COMMON_HEADBYTES, 16), sizeof(fastd_block128_t)+tail_len);
if (tail_len)
memset(in.data+in.len, 0, tail_len);
@@ -144,28 +144,28 @@ static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer UNUSED, fast
crypto_onetimeauth_poly1305(tag, outblocks->b+KEYBYTES, in.len - KEYBYTES, outblocks->b);
- fastd_buffer_push_head(ctx, out, KEYBYTES);
- fastd_buffer_pull_head_from(ctx, out, tag, TAGBYTES);
+ fastd_buffer_push_head(out, KEYBYTES);
+ fastd_buffer_pull_head_from(out, tag, TAGBYTES);
fastd_buffer_free(in);
- fastd_method_put_common_header(ctx, out, session->common.send_nonce, 0);
+ fastd_method_put_common_header(out, session->common.send_nonce, 0);
fastd_method_increment_nonce(&session->common);
return true;
}
-static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) {
+static bool method_decrypt(fastd_peer_t *peer, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) {
if (in.len < COMMON_HEADBYTES+TAGBYTES)
return false;
- if (!method_session_is_valid(ctx, session))
+ if (!method_session_is_valid(session))
return false;
uint8_t in_nonce[COMMON_NONCEBYTES];
uint8_t flags;
int64_t age;
- if (!fastd_method_handle_common_header(ctx, &session->common, &in, in_nonce, &flags, &age))
+ if (!fastd_method_handle_common_header(&session->common, &in, in_nonce, &flags, &age))
return false;
if (flags)
@@ -175,11 +175,11 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
fastd_method_expand_nonce(nonce, in_nonce, sizeof(nonce));
uint8_t tag[TAGBYTES] __attribute__((aligned(8)));
- fastd_buffer_push_head_to(ctx, &in, tag, TAGBYTES);
- fastd_buffer_pull_head_zero(ctx, &in, KEYBYTES);
+ fastd_buffer_push_head_to(&in, tag, TAGBYTES);
+ fastd_buffer_pull_head_zero(&in, KEYBYTES);
size_t tail_len = alignto(in.len, sizeof(fastd_block128_t))-in.len;
- *out = fastd_buffer_alloc(ctx, in.len, 0, tail_len);
+ *out = fastd_buffer_alloc(in.len, 0, tail_len);
int n_blocks = block_count(in.len, sizeof(fastd_block128_t));
fastd_block128_t *inblocks = in.data;
@@ -198,20 +198,20 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
fastd_buffer_free(*out);
/* restore input buffer */
- fastd_buffer_push_head(ctx, &in, KEYBYTES);
- fastd_buffer_pull_head_from(ctx, &in, tag, TAGBYTES);
- fastd_method_put_common_header(ctx, &in, in_nonce, 0);
+ fastd_buffer_push_head(&in, KEYBYTES);
+ fastd_buffer_pull_head_from(&in, tag, TAGBYTES);
+ fastd_method_put_common_header(&in, in_nonce, 0);
return false;
}
fastd_buffer_free(in);
- fastd_buffer_push_head(ctx, out, KEYBYTES);
+ fastd_buffer_push_head(out, KEYBYTES);
- if (!fastd_method_reorder_check(ctx, peer, &session->common, in_nonce, age)) {
+ if (!fastd_method_reorder_check(peer, &session->common, in_nonce, age)) {
fastd_buffer_free(*out);
- *out = fastd_buffer_alloc(ctx, 0, 0, 0);
+ *out = fastd_buffer_alloc(0, 0, 0);
}
return true;
diff --git a/src/methods/null/null.c b/src/methods/null/null.c
index 9c7dc43..76fd961 100644
--- a/src/methods/null/null.c
+++ b/src/methods/null/null.c
@@ -40,11 +40,11 @@ static bool method_create_by_name(const char *name, fastd_method_t **method UNUS
static void method_destroy(fastd_method_t *method UNUSED) {
}
-static size_t method_key_length(fastd_context_t *ctx UNUSED, const fastd_method_t *method UNUSED) {
+static size_t method_key_length(const fastd_method_t *method UNUSED) {
return 0;
}
-static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx UNUSED, const fastd_method_t *method UNUSED, const uint8_t *secret UNUSED, bool initiator) {
+static fastd_method_session_state_t* method_session_init(const fastd_method_t *method UNUSED, const uint8_t *secret UNUSED, bool initiator) {
fastd_method_session_state_t *session = malloc(sizeof(fastd_method_session_state_t));
session->valid = true;
@@ -53,31 +53,31 @@ static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx UN
return session;
}
-static fastd_method_session_state_t* method_session_init_compat(fastd_context_t *ctx, const fastd_method_t *method, const uint8_t *secret, size_t length UNUSED, bool initiator) {
- return method_session_init(ctx, method, secret, initiator);
+static fastd_method_session_state_t* method_session_init_compat(const fastd_method_t *method, const uint8_t *secret, size_t length UNUSED, bool initiator) {
+ return method_session_init(method, secret, initiator);
}
-static bool method_session_is_valid(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session) {
+static bool method_session_is_valid(fastd_method_session_state_t *session) {
return (session && session->valid);
}
-static bool method_session_is_initiator(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session) {
+static bool method_session_is_initiator(fastd_method_session_state_t *session) {
return (session->initiator);
}
-static bool method_session_want_refresh(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session UNUSED) {
+static bool method_session_want_refresh(fastd_method_session_state_t *session UNUSED) {
return false;
}
-static void method_session_superseded(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session) {
+static void method_session_superseded(fastd_method_session_state_t *session) {
session->valid = false;
}
-static void method_session_free(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session) {
+static void method_session_free(fastd_method_session_state_t *session) {
free(session);
}
-static bool method_passthrough(fastd_context_t *ctx UNUSED, fastd_peer_t *peer UNUSED, fastd_method_session_state_t *session UNUSED, fastd_buffer_t *out, fastd_buffer_t in) {
+static bool method_passthrough(fastd_peer_t *peer UNUSED, fastd_method_session_state_t *session UNUSED, fastd_buffer_t *out, fastd_buffer_t in) {
*out = in;
return true;
}
diff --git a/src/methods/xsalsa20_poly1305/xsalsa20_poly1305.c b/src/methods/xsalsa20_poly1305/xsalsa20_poly1305.c
index e11826f..f06e0f8 100644
--- a/src/methods/xsalsa20_poly1305/xsalsa20_poly1305.c
+++ b/src/methods/xsalsa20_poly1305/xsalsa20_poly1305.c
@@ -45,44 +45,44 @@ static bool method_create_by_name(const char *name, fastd_method_t **method UNUS
static void method_destroy(fastd_method_t *method UNUSED) {
}
-static size_t method_key_length(fastd_context_t *ctx UNUSED, const fastd_method_t *method UNUSED) {
+static size_t method_key_length(const fastd_method_t *method UNUSED) {
return crypto_secretbox_xsalsa20poly1305_KEYBYTES;
}
-static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx, const fastd_method_t *method UNUSED, const uint8_t *secret, bool initiator) {
+static fastd_method_session_state_t* method_session_init(const fastd_method_t *method UNUSED, const uint8_t *secret, bool initiator) {
fastd_method_session_state_t *session = malloc(sizeof(fastd_method_session_state_t));
- fastd_method_common_init(ctx, &session->common, initiator);
+ fastd_method_common_init(&session->common, initiator);
memcpy(session->key, secret, crypto_secretbox_xsalsa20poly1305_KEYBYTES);
return session;
}
-static fastd_method_session_state_t* method_session_init_compat(fastd_context_t *ctx, const fastd_method_t *method, const uint8_t *secret, size_t length, bool initiator) {
+static fastd_method_session_state_t* method_session_init_compat(const fastd_method_t *method, const uint8_t *secret, size_t length, bool initiator) {
if (length < crypto_secretbox_xsalsa20poly1305_KEYBYTES)
- exit_bug(ctx, "xsalsa20-poly1305: tried to init with short secret");
+ exit_bug("xsalsa20-poly1305: tried to init with short secret");
- return method_session_init(ctx, method, secret, initiator);
+ return method_session_init(method, secret, initiator);
}
-static bool method_session_is_valid(fastd_context_t *ctx, fastd_method_session_state_t *session) {
- return (session && fastd_method_session_common_is_valid(ctx, &session->common));
+static bool method_session_is_valid(fastd_method_session_state_t *session) {
+ return (session && fastd_method_session_common_is_valid(&session->common));
}
-static bool method_session_is_initiator(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session) {
+static bool method_session_is_initiator(fastd_method_session_state_t *session) {
return fastd_method_session_common_is_initiator(&session->common);
}
-static bool method_session_want_refresh(fastd_context_t *ctx, fastd_method_session_state_t *session) {
- return fastd_method_session_common_want_refresh(ctx, &session->common);
+static bool method_session_want_refresh(fastd_method_session_state_t *session) {
+ return fastd_method_session_common_want_refresh(&session->common);
}
-static void method_session_superseded(fastd_context_t *ctx, fastd_method_session_state_t *session) {
- fastd_method_session_common_superseded(ctx, &session->common);
+static void method_session_superseded(fastd_method_session_state_t *session) {
+ fastd_method_session_common_superseded(&session->common);
}
-static void method_session_free(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session) {
+static void method_session_free(fastd_method_session_state_t *session) {
if(session) {
secure_memzero(session, sizeof(fastd_method_session_state_t));
free(session);
@@ -96,30 +96,30 @@ static inline void memcpy_nonce(uint8_t *dst, const uint8_t *src) {
dst[i] = src[COMMON_NONCEBYTES-i-1];
}
-static inline void put_header(fastd_context_t *ctx, fastd_buffer_t *buffer, const uint8_t nonce[COMMON_NONCEBYTES], uint8_t flags) {
- fastd_buffer_pull_head_from(ctx, buffer, &flags, 1);
+static inline void put_header(fastd_buffer_t *buffer, const uint8_t nonce[COMMON_NONCEBYTES], uint8_t flags) {
+ fastd_buffer_pull_head_from(buffer, &flags, 1);
- fastd_buffer_pull_head(ctx, buffer, COMMON_NONCEBYTES);
+ fastd_buffer_pull_head(buffer, COMMON_NONCEBYTES);
memcpy_nonce(buffer->data, nonce);
}
-static inline void take_header(fastd_context_t *ctx, fastd_buffer_t *buffer, uint8_t nonce[COMMON_NONCEBYTES], uint8_t *flags) {
+static inline void take_header(fastd_buffer_t *buffer, uint8_t nonce[COMMON_NONCEBYTES], uint8_t *flags) {
memcpy_nonce(nonce, buffer->data );
- fastd_buffer_push_head(ctx, buffer, COMMON_NONCEBYTES);
+ fastd_buffer_push_head(buffer, COMMON_NONCEBYTES);
- fastd_buffer_push_head_to(ctx, buffer, flags, 1);
+ fastd_buffer_push_head_to(buffer, flags, 1);
}
-static inline bool handle_header(fastd_context_t *ctx, const fastd_method_common_t *session, fastd_buffer_t *buffer, uint8_t nonce[COMMON_NONCEBYTES], uint8_t *flags, int64_t *age) {
- take_header(ctx, buffer, nonce, flags);
- return fastd_method_is_nonce_valid(ctx, session, nonce, age);
+static inline bool handle_header(const fastd_method_common_t *session, fastd_buffer_t *buffer, uint8_t nonce[COMMON_NONCEBYTES], uint8_t *flags, int64_t *age) {
+ take_header(buffer, nonce, flags);
+ return fastd_method_is_nonce_valid(session, nonce, age);
}
-static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer UNUSED, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) {
- fastd_buffer_pull_head_zero(ctx, &in, crypto_secretbox_xsalsa20poly1305_ZEROBYTES);
+static bool method_encrypt(fastd_peer_t *peer UNUSED, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) {
+ fastd_buffer_pull_head_zero(&in, crypto_secretbox_xsalsa20poly1305_ZEROBYTES);
- *out = fastd_buffer_alloc(ctx, in.len, 0, 0);
+ *out = fastd_buffer_alloc(in.len, 0, 0);
uint8_t nonce[crypto_secretbox_xsalsa20poly1305_NONCEBYTES] __attribute__((aligned(8))) = {};
memcpy_nonce(nonce, session->common.send_nonce);
@@ -128,24 +128,24 @@ static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer UNUSED, fast
fastd_buffer_free(in);
- fastd_buffer_push_head(ctx, out, crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES);
- put_header(ctx, out, session->common.send_nonce, 0);
+ fastd_buffer_push_head(out, crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES);
+ put_header(out, session->common.send_nonce, 0);
fastd_method_increment_nonce(&session->common);
return true;
}
-static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) {
+static bool method_decrypt(fastd_peer_t *peer, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) {
if (in.len < COMMON_HEADBYTES)
return false;
- if (!method_session_is_valid(ctx, session))
+ if (!method_session_is_valid(session))
return false;
uint8_t in_nonce[COMMON_NONCEBYTES];
uint8_t flags;
int64_t age;
- if (!handle_header(ctx, &session->common, &in, in_nonce, &flags, &age))
+ if (!handle_header(&session->common, &in, in_nonce, &flags, &age))
return false;
if (flags)
@@ -154,27 +154,27 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
uint8_t nonce[crypto_secretbox_xsalsa20poly1305_NONCEBYTES] __attribute__((aligned(8))) = {};
memcpy_nonce(nonce, in_nonce);
- fastd_buffer_pull_head_zero(ctx, &in, crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES);
+ fastd_buffer_pull_head_zero(&in, crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES);
- *out = fastd_buffer_alloc(ctx, in.len, 0, 0);
+ *out = fastd_buffer_alloc(in.len, 0, 0);
if (crypto_secretbox_xsalsa20poly1305_open(out->data, in.data, in.len, nonce, session->key) != 0) {
fastd_buffer_free(*out);
/* restore input buffer */
- fastd_buffer_push_head(ctx, &in, crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES);
- put_header(ctx, &in, in_nonce, 0);
+ fastd_buffer_push_head(&in, crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES);
+ put_header(&in, in_nonce, 0);
return false;
}
fastd_buffer_free(in);
- if (!fastd_method_reorder_check(ctx, peer, &session->common, in_nonce, age)) {
+ if (!fastd_method_reorder_check(peer, &session->common, in_nonce, age)) {
fastd_buffer_free(*out);
- *out = fastd_buffer_alloc(ctx, crypto_secretbox_xsalsa20poly1305_ZEROBYTES, 0, 0);
+ *out = fastd_buffer_alloc(crypto_secretbox_xsalsa20poly1305_ZEROBYTES, 0, 0);
}
- fastd_buffer_push_head(ctx, out, crypto_secretbox_xsalsa20poly1305_ZEROBYTES);
+ fastd_buffer_push_head(out, crypto_secretbox_xsalsa20poly1305_ZEROBYTES);
return true;
}