summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.c16
-rw-r--r--src/method.h18
-rw-r--r--src/methods/CMakeLists.txt2
-rw-r--r--src/methods/cipher_test/cipher_test.c36
-rw-r--r--src/methods/composed_gmac/composed_gmac.c60
-rw-r--r--src/methods/generic_gcm/generic_gcm.c52
-rw-r--r--src/methods/generic_gmac/generic_gmac.c47
-rw-r--r--src/methods/generic_poly1305/generic_poly1305.c38
-rw-r--r--src/methods/methods.c.in10
-rw-r--r--src/methods/null/null.c14
-rw-r--r--src/methods/xsalsa20_poly1305/xsalsa20_poly1305.c14
-rw-r--r--src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c16
-rw-r--r--src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.h2
-rw-r--r--src/protocols/ec25519_fhmqvc/handshake.c16
-rw-r--r--src/protocols/ec25519_fhmqvc/state.c2
-rw-r--r--src/types.h4
16 files changed, 173 insertions, 174 deletions
diff --git a/src/config.c b/src/config.c
index 726d04c..b6ea94f 100644
--- a/src/config.c
+++ b/src/config.c
@@ -480,13 +480,13 @@ static void configure_method_parameters(fastd_config_t *conf) {
size_t i;
for (i = 0; conf->methods[i].name; i++) {
- const fastd_method_t *method = conf->methods[i].method;
+ const fastd_method_provider_t *provider = conf->methods[i].provider;
- conf->max_overhead = max_size_t(conf->max_overhead, method->max_overhead);
- conf->min_encrypt_head_space = max_size_t(conf->min_encrypt_head_space, method->min_encrypt_head_space);
- conf->min_decrypt_head_space = max_size_t(conf->min_decrypt_head_space, method->min_decrypt_head_space);
- conf->min_encrypt_tail_space = max_size_t(conf->min_encrypt_tail_space, method->min_encrypt_tail_space);
- conf->min_decrypt_tail_space = max_size_t(conf->min_decrypt_tail_space, method->min_decrypt_tail_space);
+ conf->max_overhead = max_size_t(conf->max_overhead, provider->max_overhead);
+ conf->min_encrypt_head_space = max_size_t(conf->min_encrypt_head_space, provider->min_encrypt_head_space);
+ conf->min_decrypt_head_space = max_size_t(conf->min_decrypt_head_space, provider->min_decrypt_head_space);
+ conf->min_encrypt_tail_space = max_size_t(conf->min_encrypt_tail_space, provider->min_encrypt_tail_space);
+ conf->min_decrypt_tail_space = max_size_t(conf->min_decrypt_tail_space, provider->min_decrypt_tail_space);
}
conf->min_encrypt_head_space = alignto(conf->min_encrypt_head_space, 16);
@@ -505,7 +505,7 @@ static void configure_methods(fastd_context_t *ctx, fastd_config_t *conf) {
for (i = 0, method_name = conf->method_list; method_name; i++, method_name = method_name->next) {
conf->methods[i].name = method_name->str;
- if (!fastd_method_create_by_name(method_name->str, &conf->methods[i].method, &conf->methods[i].ctx))
+ if (!fastd_method_create_by_name(method_name->str, &conf->methods[i].provider, &conf->methods[i].method))
exit_error(ctx, "method `%s' not supported", method_name->str);
}
@@ -515,7 +515,7 @@ static void configure_methods(fastd_context_t *ctx, fastd_config_t *conf) {
static void destroy_methods(fastd_config_t *conf) {
size_t i;
for (i = 0; conf->methods[i].name; i++) {
- conf->methods[i].method->destroy(conf->methods[i].ctx);
+ conf->methods[i].provider->destroy(conf->methods[i].method);
}
free(conf->methods);
diff --git a/src/method.h b/src/method.h
index b56db14..c329734 100644
--- a/src/method.h
+++ b/src/method.h
@@ -32,24 +32,24 @@
struct fastd_method_info {
const char *name;
- const fastd_method_t *method;
- fastd_method_context_t *ctx;
+ const fastd_method_provider_t *provider;
+ fastd_method_t *method;
};
-struct fastd_method {
+struct fastd_method_provider {
size_t max_overhead;
size_t min_encrypt_head_space;
size_t min_decrypt_head_space;
size_t min_encrypt_tail_space;
size_t min_decrypt_tail_space;
- bool (*create_by_name)(const char *name, fastd_method_context_t **method_ctx);
- void (*destroy)(fastd_method_context_t *method_ctx);
+ bool (*create_by_name)(const char *name, fastd_method_t **method);
+ void (*destroy)(fastd_method_t *method);
- size_t (*key_length)(fastd_context_t *ctx, const fastd_method_context_t *method_ctx);
+ size_t (*key_length)(fastd_context_t *ctx, const fastd_method_t *method);
- fastd_method_session_state_t* (*session_init)(fastd_context_t *ctx, const fastd_method_context_t *method_ctx, const uint8_t *secret, bool initiator);
- fastd_method_session_state_t* (*session_init_compat)(fastd_context_t *ctx, const fastd_method_context_t *method_ctx, const uint8_t *secret, size_t length, bool initiator);
+ fastd_method_session_state_t* (*session_init)(fastd_context_t *ctx, const fastd_method_t *method, const uint8_t *secret, bool initiator);
+ fastd_method_session_state_t* (*session_init_compat)(fastd_context_t *ctx, const fastd_method_t *method, const uint8_t *secret, size_t length, bool initiator);
bool (*session_is_valid)(fastd_context_t *ctx, fastd_method_session_state_t *session);
bool (*session_is_initiator)(fastd_context_t *ctx, fastd_method_session_state_t *session);
bool (*session_want_refresh)(fastd_context_t *ctx, fastd_method_session_state_t *session);
@@ -61,7 +61,7 @@ struct fastd_method {
};
-bool fastd_method_create_by_name(const char *name, const fastd_method_t **method, fastd_method_context_t **method_ctx);
+bool fastd_method_create_by_name(const char *name, const fastd_method_provider_t **provider, fastd_method_t **method);
static inline const fastd_method_info_t* fastd_method_get_by_name(fastd_context_t *ctx, const char *name) {
diff --git a/src/methods/CMakeLists.txt b/src/methods/CMakeLists.txt
index 63f4ee9..8bd04c8 100644
--- a/src/methods/CMakeLists.txt
+++ b/src/methods/CMakeLists.txt
@@ -38,7 +38,7 @@ get_property(METHODS GLOBAL PROPERTY FASTD_METHODS)
foreach(method ${METHODS})
string(REPLACE - _ method_ "${method}")
- set(METHOD_DEFINITIONS "${METHOD_DEFINITIONS}\nextern const fastd_method_t fastd_method_${method_};")
+ set(METHOD_DEFINITIONS "${METHOD_DEFINITIONS}\nextern const fastd_method_provider_t fastd_method_${method_};")
set(METHOD_LIST "${METHOD_LIST}\n&fastd_method_${method_},")
endforeach(method)
diff --git a/src/methods/cipher_test/cipher_test.c b/src/methods/cipher_test/cipher_test.c
index fcf58e6..240e15d 100644
--- a/src/methods/cipher_test/cipher_test.c
+++ b/src/methods/cipher_test/cipher_test.c
@@ -29,21 +29,21 @@
#include "../common.h"
-struct fastd_method_context {
+struct fastd_method {
const fastd_cipher_info_t *cipher_info;
};
struct fastd_method_session_state {
fastd_method_common_t common;
- const fastd_method_context_t *ctx;
+ const fastd_method_t *method;
const fastd_cipher_t *cipher;
fastd_cipher_state_t *cipher_state;
};
-static bool method_create_by_name(const char *name, fastd_method_context_t **method_ctx) {
- fastd_method_context_t ctx;
+static bool method_create_by_name(const char *name, fastd_method_t **method) {
+ fastd_method_t m;
size_t len = strlen(name);
if (len < 12)
@@ -56,30 +56,30 @@ static bool method_create_by_name(const char *name, fastd_method_context_t **met
memcpy(cipher_name, name, len-12);
cipher_name[len-12] = 0;
- ctx.cipher_info = fastd_cipher_info_get_by_name(cipher_name);
- if (!ctx.cipher_info)
+ m.cipher_info = fastd_cipher_info_get_by_name(cipher_name);
+ if (!m.cipher_info)
return false;
- *method_ctx = malloc(sizeof(fastd_method_context_t));
- **method_ctx = ctx;
+ *method = malloc(sizeof(fastd_method_t));
+ **method = m;
return true;
}
-static void method_destroy(fastd_method_context_t *method_ctx) {
- free(method_ctx);
+static void method_destroy(fastd_method_t *method) {
+ free(method);
}
-static size_t method_key_length(fastd_context_t *ctx UNUSED, const fastd_method_context_t *method_ctx) {
- return method_ctx->cipher_info->key_length;
+static size_t method_key_length(fastd_context_t *ctx UNUSED, 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_context_t *method_ctx, const uint8_t *secret, bool initiator) {
+static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx, 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);
- session->ctx = method_ctx;
- session->cipher = fastd_cipher_get(ctx, session->ctx->cipher_info);
+ session->method = method;
+ session->cipher = fastd_cipher_get(ctx, method->cipher_info);
session->cipher_state = session->cipher->init(ctx, secret);
pr_warn(ctx, "using cipher-test method; this method must be used for testing and benchmarks only");
@@ -117,7 +117,7 @@ static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer UNUSED, fast
if (tail_len)
memset(in.data+in.len, 0, tail_len);
- size_t iv_length = session->ctx->cipher_info->iv_length;
+ size_t iv_length = session->method->cipher_info->iv_length;
uint8_t nonce[iv_length];
if (iv_length) {
memset(nonce, 0, iv_length);
@@ -161,7 +161,7 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
if (common_nonce[COMMON_NONCEBYTES]) /* flags */
return false;
- size_t iv_length = session->ctx->cipher_info->iv_length;
+ size_t iv_length = session->method->cipher_info->iv_length;
uint8_t nonce[iv_length];
if (iv_length) {
memset(nonce, 0, iv_length);
@@ -200,7 +200,7 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
return true;
}
-const fastd_method_t fastd_method_cipher_test = {
+const fastd_method_provider_t fastd_method_cipher_test = {
.max_overhead = COMMON_HEADBYTES,
.min_encrypt_head_space = 0,
.min_decrypt_head_space = 0,
diff --git a/src/methods/composed_gmac/composed_gmac.c b/src/methods/composed_gmac/composed_gmac.c
index d1627ee..fafc77b 100644
--- a/src/methods/composed_gmac/composed_gmac.c
+++ b/src/methods/composed_gmac/composed_gmac.c
@@ -32,7 +32,7 @@
static const fastd_block128_t ZERO_BLOCK = {};
-struct fastd_method_context {
+struct fastd_method {
const fastd_cipher_info_t *cipher_info;
const fastd_cipher_info_t *gmac_cipher_info;
const fastd_mac_info_t *ghash_info;
@@ -41,7 +41,7 @@ struct fastd_method_context {
struct fastd_method_session_state {
fastd_method_common_t common;
- const fastd_method_context_t *ctx;
+ const fastd_method_t *method;
const fastd_cipher_t *cipher;
fastd_cipher_state_t *cipher_state;
@@ -54,11 +54,11 @@ struct fastd_method_session_state {
};
-static bool method_create_by_name(const char *name, fastd_method_context_t **method_ctx) {
- fastd_method_context_t ctx;
+static bool method_create_by_name(const char *name, fastd_method_t **method) {
+ fastd_method_t m;
- ctx.ghash_info = fastd_mac_info_get_by_name("ghash");
- if (!ctx.ghash_info)
+ m.ghash_info = fastd_mac_info_get_by_name("ghash");
+ if (!m.ghash_info)
return false;
size_t len = strlen(name);
@@ -80,50 +80,50 @@ static bool method_create_by_name(const char *name, fastd_method_context_t **met
*gmac_cipher_name = 0;
gmac_cipher_name++;
- ctx.cipher_info = fastd_cipher_info_get_by_name(cipher_name);
- if (!ctx.cipher_info)
+ m.cipher_info = fastd_cipher_info_get_by_name(cipher_name);
+ if (!m.cipher_info)
return false;
- if (ctx.cipher_info->iv_length && ctx.cipher_info->iv_length <= COMMON_NONCEBYTES)
+ if (m.cipher_info->iv_length && m.cipher_info->iv_length <= COMMON_NONCEBYTES)
return false;
- ctx.gmac_cipher_info = fastd_cipher_info_get_by_name(gmac_cipher_name);
- if (!ctx.gmac_cipher_info)
+ m.gmac_cipher_info = fastd_cipher_info_get_by_name(gmac_cipher_name);
+ if (!m.gmac_cipher_info)
return false;
- if (ctx.gmac_cipher_info->iv_length <= COMMON_NONCEBYTES)
+ if (m.gmac_cipher_info->iv_length <= COMMON_NONCEBYTES)
return false;
- *method_ctx = malloc(sizeof(fastd_method_context_t));
- **method_ctx = ctx;
+ *method = malloc(sizeof(fastd_method_t));
+ **method = m;
return true;
}
-static void method_destroy(fastd_method_context_t *method_ctx) {
- free(method_ctx);
+static void method_destroy(fastd_method_t *method) {
+ free(method);
}
-static size_t method_key_length(fastd_context_t *ctx UNUSED, const fastd_method_context_t *method_ctx) {
- return method_ctx->cipher_info->key_length + method_ctx->gmac_cipher_info->key_length;
+static size_t method_key_length(fastd_context_t *ctx UNUSED, 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_context_t *method_ctx, const uint8_t *secret, bool initiator) {
+static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx, 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);
- session->ctx = method_ctx;
+ session->method = method;
- session->cipher = fastd_cipher_get(ctx, session->ctx->cipher_info);
+ session->cipher = fastd_cipher_get(ctx, method->cipher_info);
session->cipher_state = session->cipher->init(ctx, secret);
- session->gmac_cipher = fastd_cipher_get(ctx, session->ctx->gmac_cipher_info);
- session->gmac_cipher_state = session->gmac_cipher->init(ctx, secret + session->ctx->cipher_info->key_length);
+ session->gmac_cipher = fastd_cipher_get(ctx, method->gmac_cipher_info);
+ session->gmac_cipher_state = session->gmac_cipher->init(ctx, secret + method->cipher_info->key_length);
fastd_block128_t H;
- size_t gmac_iv_length = session->ctx->gmac_cipher_info->iv_length;
+ size_t gmac_iv_length = method->gmac_cipher_info->iv_length;
uint8_t zeroiv[gmac_iv_length];
memset(zeroiv, 0, gmac_iv_length);
@@ -135,7 +135,7 @@ static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx, c
return NULL;
}
- session->ghash = fastd_mac_get(ctx, session->ctx->ghash_info);
+ session->ghash = fastd_mac_get(ctx, method->ghash_info);
session->ghash_state = session->ghash->init(ctx, H.b);
return session;
@@ -189,7 +189,7 @@ static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer UNUSED, fast
fastd_block128_t *outblocks = out->data;
fastd_block128_t sig;
- size_t gmac_iv_length = session->ctx->gmac_cipher_info->iv_length;
+ size_t gmac_iv_length = session->method->gmac_cipher_info->iv_length;
uint8_t gmac_nonce[gmac_iv_length];
memset(gmac_nonce, 0, gmac_iv_length);
memcpy(gmac_nonce, session->common.send_nonce, COMMON_NONCEBYTES);
@@ -198,7 +198,7 @@ static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer UNUSED, fast
bool ok = session->gmac_cipher->crypt(ctx, session->gmac_cipher_state, outblocks, &ZERO_BLOCK, sizeof(fastd_block128_t), gmac_nonce);
if (ok) {
- size_t iv_length = session->ctx->cipher_info->iv_length;
+ size_t iv_length = session->method->cipher_info->iv_length;
uint8_t nonce[iv_length];
if (iv_length) {
memset(nonce, 0, iv_length);
@@ -253,13 +253,13 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
if (!fastd_method_is_nonce_valid(ctx, &session->common, common_nonce, &age))
return false;
- size_t gmac_iv_length = session->ctx->gmac_cipher_info->iv_length;
+ size_t gmac_iv_length = session->method->gmac_cipher_info->iv_length;
uint8_t gmac_nonce[gmac_iv_length];
memset(gmac_nonce, 0, gmac_iv_length);
memcpy(gmac_nonce, common_nonce, COMMON_NONCEBYTES);
gmac_nonce[gmac_iv_length-1] = 1;
- size_t iv_length = session->ctx->cipher_info->iv_length;
+ size_t iv_length = session->method->cipher_info->iv_length;
uint8_t nonce[iv_length];
if (iv_length) {
memset(nonce, 0, iv_length);
@@ -309,7 +309,7 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
return true;
}
-const fastd_method_t fastd_method_composed_gmac = {
+const fastd_method_provider_t fastd_method_composed_gmac = {
.max_overhead = COMMON_HEADBYTES + sizeof(fastd_block128_t),
.min_encrypt_head_space = 0,
.min_decrypt_head_space = 0,
diff --git a/src/methods/generic_gcm/generic_gcm.c b/src/methods/generic_gcm/generic_gcm.c
index 3490f8b..5aa4210 100644
--- a/src/methods/generic_gcm/generic_gcm.c
+++ b/src/methods/generic_gcm/generic_gcm.c
@@ -28,16 +28,16 @@
#include "../../method.h"
#include "../common.h"
-struct fastd_method_context {
+
+struct fastd_method {
const fastd_cipher_info_t *cipher_info;
const fastd_mac_info_t *ghash_info;
};
-
struct fastd_method_session_state {
fastd_method_common_t common;
- const fastd_method_context_t *ctx;
+ const fastd_method_t *method;
const fastd_cipher_t *cipher;
fastd_cipher_state_t *cipher_state;
@@ -47,11 +47,11 @@ struct fastd_method_session_state {
};
-static bool method_create_by_name(const char *name, fastd_method_context_t **method_ctx) {
- fastd_method_context_t ctx;
+static bool method_create_by_name(const char *name, fastd_method_t **method) {
+ fastd_method_t m;
- ctx.ghash_info = fastd_mac_info_get_by_name("ghash");
- if (!ctx.ghash_info)
+ m.ghash_info = fastd_mac_info_get_by_name("ghash");
+ if (!m.ghash_info)
return false;
size_t len = strlen(name);
@@ -65,40 +65,40 @@ static bool method_create_by_name(const char *name, fastd_method_context_t **met
memcpy(cipher_name, name, len-3);
strncpy(cipher_name+len-3, "ctr", 4);
- ctx.cipher_info = fastd_cipher_info_get_by_name(cipher_name);
- if (!ctx.cipher_info)
+ m.cipher_info = fastd_cipher_info_get_by_name(cipher_name);
+ if (!m.cipher_info)
return false;
- if (ctx.cipher_info->iv_length <= COMMON_NONCEBYTES)
+ if (m.cipher_info->iv_length <= COMMON_NONCEBYTES)
return false;
- *method_ctx = malloc(sizeof(fastd_method_context_t));
- **method_ctx = ctx;
+ *method = malloc(sizeof(fastd_method_t));
+ **method = m;
return true;
}
-static void method_destroy(fastd_method_context_t *method_ctx) {
- free(method_ctx);
+static void method_destroy(fastd_method_t *method) {
+ free(method);
}
-static size_t method_key_length(fastd_context_t *ctx UNUSED, const fastd_method_context_t *method_ctx) {
- return method_ctx->cipher_info->key_length;
+static size_t method_key_length(fastd_context_t *ctx UNUSED, 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_context_t *method_ctx, const uint8_t *secret, bool initiator) {
+static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx, 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);
- session->ctx = method_ctx;
+ session->method = method;
- session->cipher = fastd_cipher_get(ctx, session->ctx->cipher_info);
+ session->cipher = fastd_cipher_get(ctx, method->cipher_info);
session->cipher_state = session->cipher->init(ctx, secret);
static const fastd_block128_t zeroblock = {};
fastd_block128_t H;
- size_t iv_length = session->ctx->cipher_info->iv_length;
+ size_t iv_length = method->cipher_info->iv_length;
uint8_t zeroiv[iv_length];
memset(zeroiv, 0, iv_length);
@@ -108,17 +108,17 @@ static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx, c
return NULL;
}
- session->ghash = fastd_mac_get(ctx, session->ctx->ghash_info);
+ session->ghash = fastd_mac_get(ctx, method->ghash_info);
session->ghash_state = session->ghash->init(ctx, H.b);
return session;
}
-static fastd_method_session_state_t* method_session_init_compat(fastd_context_t *ctx, const fastd_method_context_t *method_ctx, const uint8_t *secret, size_t length, bool initiator) {
+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) {
if (length < sizeof(fastd_block128_t))
exit_bug(ctx, "generic-gcm: tried to init with short secret");
- return method_session_init(ctx, method_ctx, secret, initiator);
+ return method_session_init(ctx, method, secret, initiator);
}
static bool method_session_is_valid(fastd_context_t *ctx, fastd_method_session_state_t *session) {
@@ -165,7 +165,7 @@ static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer UNUSED, fast
if (tail_len)
memset(in.data+in.len, 0, tail_len);
- size_t iv_length = session->ctx->cipher_info->iv_length;
+ size_t iv_length = session->method->cipher_info->iv_length;
uint8_t nonce[iv_length];
memset(nonce, 0, iv_length);
memcpy(nonce, session->common.send_nonce, COMMON_NONCEBYTES);
@@ -219,7 +219,7 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
if (((const uint8_t*)in.data)[COMMON_NONCEBYTES]) /* flags */
return false;
- size_t iv_length = session->ctx->cipher_info->iv_length;
+ size_t iv_length = session->method->cipher_info->iv_length;
uint8_t nonce[iv_length];
memset(nonce, 0, iv_length);
memcpy(nonce, in.data, COMMON_NONCEBYTES);
@@ -268,7 +268,7 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
return true;
}
-const fastd_method_t fastd_method_generic_gcm = {
+const fastd_method_provider_t fastd_method_generic_gcm = {
.max_overhead = COMMON_HEADBYTES + sizeof(fastd_block128_t),
.min_encrypt_head_space = sizeof(fastd_block128_t),
.min_decrypt_head_space = 0,
diff --git a/src/methods/generic_gmac/generic_gmac.c b/src/methods/generic_gmac/generic_gmac.c
index 91b96cb..f7ea086 100644
--- a/src/methods/generic_gmac/generic_gmac.c
+++ b/src/methods/generic_gmac/generic_gmac.c
@@ -29,16 +29,15 @@
#include "../common.h"
-struct fastd_method_context {
+struct fastd_method {
const fastd_cipher_info_t *cipher_info;
const fastd_mac_info_t *ghash_info;
};
-
struct fastd_method_session_state {
fastd_method_common_t common;
- const fastd_method_context_t *ctx;
+ const fastd_method_t *method;
const fastd_cipher_t *cipher;
fastd_cipher_state_t *cipher_state;
@@ -48,11 +47,11 @@ struct fastd_method_session_state {
};
-static bool method_create_by_name(const char *name, fastd_method_context_t **method_ctx) {
- fastd_method_context_t ctx;
+static bool method_create_by_name(const char *name, fastd_method_t **method) {
+ fastd_method_t m;
- ctx.ghash_info = fastd_mac_info_get_by_name("ghash");
- if (!ctx.ghash_info)
+ m.ghash_info = fastd_mac_info_get_by_name("ghash");
+ if (!m.ghash_info)
return false;
size_t len = strlen(name);
@@ -69,38 +68,38 @@ static bool method_create_by_name(const char *name, fastd_method_context_t **met
memcpy(cipher_name, name, len-5);
cipher_name[len-5] = 0;
- ctx.cipher_info = fastd_cipher_info_get_by_name(cipher_name);
- if (!ctx.cipher_info)
+ m.cipher_info = fastd_cipher_info_get_by_name(cipher_name);
+ if (!m.cipher_info)
return false;
- if (ctx.cipher_info->iv_length <= COMMON_NONCEBYTES)
+ if (m.cipher_info->iv_length <= COMMON_NONCEBYTES)
return false;
- *method_ctx = malloc(sizeof(fastd_method_context_t));
- **method_ctx = ctx;
+ *method = malloc(sizeof(fastd_method_t));
+ **method = m;
return true;
}
-static void method_destroy(fastd_method_context_t *method_ctx) {
- free(method_ctx);
+static void method_destroy(fastd_method_t *method) {
+ free(method);
}
-static size_t method_key_length(fastd_context_t *ctx UNUSED, const fastd_method_context_t *method_ctx) {
- return method_ctx->cipher_info->key_length + method_ctx->ghash_info->key_length;
+static size_t method_key_length(fastd_context_t *ctx UNUSED, const fastd_method_t *method) {
+ return method->cipher_info->key_length + method->ghash_info->key_length;
}
-static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx, const fastd_method_context_t *method_ctx, const uint8_t *secret, bool initiator) {
+static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx, 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);
- session->ctx = method_ctx;
+ session->method = method;
- session->cipher = fastd_cipher_get(ctx, session->ctx->cipher_info);
+ session->cipher = fastd_cipher_get(ctx, method->cipher_info);
session->cipher_state = session->cipher->init(ctx, secret);
- session->ghash = fastd_mac_get(ctx, session->ctx->ghash_info);
- session->ghash_state = session->ghash->init(ctx, secret + session->ctx->cipher_info->key_length);
+ session->ghash = fastd_mac_get(ctx, method->ghash_info);
+ session->ghash_state = session->ghash->init(ctx, secret + method->cipher_info->key_length);
return session;
}
@@ -149,7 +148,7 @@ static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer UNUSED, fast
if (tail_len)
memset(in.data+in.len, 0, tail_len);
- size_t iv_length = session->ctx->cipher_info->iv_length;
+ size_t iv_length = session->method->cipher_info->iv_length;
uint8_t nonce[iv_length];
memset(nonce, 0, iv_length);
memcpy(nonce, session->common.send_nonce, COMMON_NONCEBYTES);
@@ -204,7 +203,7 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
return false;
- size_t iv_length = session->ctx->cipher_info->iv_length;
+ size_t iv_length = session->method->cipher_info->iv_length;
uint8_t nonce[iv_length];
memset(nonce, 0, iv_length);
memcpy(nonce, in.data, COMMON_NONCEBYTES);
@@ -253,7 +252,7 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
return true;
}
-const fastd_method_t fastd_method_generic_gmac = {
+const fastd_method_provider_t fastd_method_generic_gmac = {
.max_overhead = COMMON_HEADBYTES + sizeof(fastd_block128_t),
.min_encrypt_head_space = sizeof(fastd_block128_t),
.min_decrypt_head_space = 0,
diff --git a/src/methods/generic_poly1305/generic_poly1305.c b/src/methods/generic_poly1305/generic_poly1305.c
index f84046e..1f40655 100644
--- a/src/methods/generic_poly1305/generic_poly1305.c
+++ b/src/methods/generic_poly1305/generic_poly1305.c
@@ -34,21 +34,21 @@
#define AUTHBLOCKS 2
-struct fastd_method_context {
+struct fastd_method {
const fastd_cipher_info_t *cipher_info;
};
struct fastd_method_session_state {
fastd_method_common_t common;
- const fastd_method_context_t *ctx;
+ const fastd_method_t *method;
const fastd_cipher_t *cipher;
fastd_cipher_state_t *cipher_state;
};
-static bool method_create_by_name(const char *name, fastd_method_context_t **method_ctx) {
- fastd_method_context_t ctx;
+static bool method_create_by_name(const char *name, fastd_method_t **method) {
+ fastd_method_t m;
size_t len = strlen(name);
if (len < 9)
@@ -61,33 +61,33 @@ static bool method_create_by_name(const char *name, fastd_method_context_t **met
memcpy(cipher_name, name, len-9);
cipher_name[len-9] = 0;
- ctx.cipher_info = fastd_cipher_info_get_by_name(cipher_name);
- if (!ctx.cipher_info)
+ m.cipher_info = fastd_cipher_info_get_by_name(cipher_name);
+ if (!m.cipher_info)
return false;
- if (ctx.cipher_info->iv_length <= COMMON_NONCEBYTES)
+ if (m.cipher_info->iv_length <= COMMON_NONCEBYTES)
return false;
- *method_ctx = malloc(sizeof(fastd_method_context_t));
- **method_ctx = ctx;
+ *method = malloc(sizeof(fastd_method_t));
+ **method = m;
return true;
}
-static void method_destroy(fastd_method_context_t *method_ctx) {
- free(method_ctx);
+static void method_destroy(fastd_method_t *method) {
+ free(method);
}
-static size_t method_key_length(fastd_context_t *ctx UNUSED, const fastd_method_context_t *method_ctx) {
- return method_ctx->cipher_info->key_length;
+static size_t method_key_length(fastd_context_t *ctx UNUSED, 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_context_t *method_ctx, const uint8_t *secret, bool initiator) {
+static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx, 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);
- session->ctx = method_ctx;
- session->cipher = fastd_cipher_get(ctx, session->ctx->cipher_info);
+ session->method = method;
+ session->cipher = fastd_cipher_get(ctx, session->method->cipher_info);
session->cipher_state = session->cipher->init(ctx, secret);
return session;
@@ -126,7 +126,7 @@ static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer UNUSED, fast
if (tail_len)
memset(in.data+in.len, 0, tail_len);
- size_t iv_length = session->ctx->cipher_info->iv_length;
+ size_t iv_length = session->method->cipher_info->iv_length;
uint8_t nonce[iv_length];
memset(nonce, 0, iv_length);
memcpy(nonce, session->common.send_nonce, COMMON_NONCEBYTES);
@@ -174,7 +174,7 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
if (((const uint8_t*)in.data)[COMMON_NONCEBYTES]) /* flags */
return false;
- size_t iv_length = session->ctx->cipher_info->iv_length;
+ size_t iv_length = session->method->cipher_info->iv_length;
uint8_t nonce[iv_length];
memset(nonce, 0, iv_length);
memcpy(nonce, in.data, COMMON_NONCEBYTES);
@@ -233,7 +233,7 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
return true;
}
-const fastd_method_t fastd_method_generic_poly1305 = {
+const fastd_method_provider_t fastd_method_generic_poly1305 = {
.max_overhead = COMMON_HEADBYTES + crypto_onetimeauth_poly1305_BYTES,
.min_encrypt_head_space = AUTHBLOCKS*sizeof(fastd_block128_t),
.min_decrypt_head_space = AUTHBLOCKS*sizeof(fastd_block128_t) - crypto_onetimeauth_poly1305_BYTES,
diff --git a/src/methods/methods.c.in b/src/methods/methods.c.in
index a2c7963..d81a121 100644
--- a/src/methods/methods.c.in
+++ b/src/methods/methods.c.in
@@ -29,15 +29,15 @@
@METHOD_DEFINITIONS@
-static const fastd_method_t *const methods[] = { @METHOD_LIST@
+static const fastd_method_provider_t *const providers[] = { @METHOD_LIST@
};
-bool fastd_method_create_by_name(const char *name, const fastd_method_t **method, fastd_method_context_t **method_ctx) {
+bool fastd_method_create_by_name(const char *name, const fastd_method_provider_t **provider, fastd_method_t **method) {
size_t i;
- for (i = 0; i < array_size(methods); i++) {
- if (methods[i]->create_by_name(name, method_ctx)) {
- *method = methods[i];
+ for (i = 0; i < array_size(providers); i++) {
+ if (providers[i]->create_by_name(name, method)) {
+ *provider = providers[i];
return true;
}
}
diff --git a/src/methods/null/null.c b/src/methods/null/null.c
index f4784c8..b2b03bd 100644
--- a/src/methods/null/null.c
+++ b/src/methods/null/null.c
@@ -33,18 +33,18 @@ struct fastd_method_session_state {
};
-static bool method_create_by_name(const char *name, fastd_method_context_t **method_ctx UNUSED) {
+static bool method_create_by_name(const char *name, fastd_method_t **method UNUSED) {
return !strcmp(name, "null");
}
-static void method_destroy(fastd_method_context_t *method_ctx UNUSED) {
+static void method_destroy(fastd_method_t *method UNUSED) {
}
-static size_t method_key_length(fastd_context_t *ctx UNUSED, const fastd_method_context_t *method_ctx UNUSED) {
+static size_t method_key_length(fastd_context_t *ctx UNUSED, 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_context_t *method_ctx UNUSED, const uint8_t *secret UNUSED, bool initiator) {
+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) {
fastd_method_session_state_t *session = malloc(sizeof(fastd_method_session_state_t));
session->valid = true;
@@ -53,8 +53,8 @@ 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_context_t *method_ctx, const uint8_t *secret, size_t length UNUSED, bool initiator) {
- return method_session_init(ctx, method_ctx, secret, initiator);
+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 bool method_session_is_valid(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session) {
@@ -82,7 +82,7 @@ static bool method_passthrough(fastd_context_t *ctx UNUSED, fastd_peer_t *peer U
return true;
}
-const fastd_method_t fastd_method_null = {
+const fastd_method_provider_t fastd_method_null = {
.max_overhead = 0,
.min_encrypt_head_space = 0,
.min_decrypt_head_space = 0,
diff --git a/src/methods/xsalsa20_poly1305/xsalsa20_poly1305.c b/src/methods/xsalsa20_poly1305/xsalsa20_poly1305.c
index 88a0525..9d964a3 100644
--- a/src/methods/xsalsa20_poly1305/xsalsa20_poly1305.c
+++ b/src/methods/xsalsa20_poly1305/xsalsa20_poly1305.c
@@ -37,18 +37,18 @@ struct fastd_method_session_state {
};
-static bool method_create_by_name(const char *name, fastd_method_context_t **method_ctx UNUSED) {
+static bool method_create_by_name(const char *name, fastd_method_t **method UNUSED) {
return !strcmp(name, "xsalsa20-poly1305");
}
-static void method_destroy(fastd_method_context_t *method_ctx UNUSED) {
+static void method_destroy(fastd_method_t *method UNUSED) {
}
-static size_t method_key_length(fastd_context_t *ctx UNUSED, const fastd_method_context_t *method_ctx UNUSED) {
+static size_t method_key_length(fastd_context_t *ctx UNUSED, 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_context_t *method_ctx UNUSED, const uint8_t *secret, bool initiator) {
+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) {
fastd_method_session_state_t *session = malloc(sizeof(fastd_method_session_state_t));
fastd_method_common_init(ctx, &session->common, initiator);
@@ -58,11 +58,11 @@ static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx, c
return session;
}
-static fastd_method_session_state_t* method_session_init_compat(fastd_context_t *ctx, const fastd_method_context_t *method_ctx, const uint8_t *secret, size_t length, bool initiator) {
+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) {
if (length < crypto_secretbox_xsalsa20poly1305_KEYBYTES)
exit_bug(ctx, "xsalsa20-poly1305: tried to init with short secret");
- return method_session_init(ctx, method_ctx, secret, initiator);
+ return method_session_init(ctx, method, secret, initiator);
}
static bool method_session_is_valid(fastd_context_t *ctx, fastd_method_session_state_t *session) {
@@ -155,7 +155,7 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
return true;
}
-const fastd_method_t fastd_method_xsalsa20_poly1305 = {
+const fastd_method_provider_t fastd_method_xsalsa20_poly1305 = {
.max_overhead = COMMON_HEADBYTES + crypto_secretbox_xsalsa20poly1305_ZEROBYTES - crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES,
.min_encrypt_head_space = crypto_secretbox_xsalsa20poly1305_ZEROBYTES,
diff --git a/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c b/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c
index a8de436..05479d0 100644
--- a/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c
+++ b/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c
@@ -41,7 +41,7 @@ static inline bool read_key(uint8_t key[32], const char *hexkey) {
static inline void check_session_refresh(fastd_context_t *ctx, fastd_peer_t *peer) {
protocol_session_t *session = &peer->protocol_state->session;
- if (!session->refreshing && session->method->method->session_want_refresh(ctx, session->method_state)) {
+ if (!session->refreshing && session->method->provider->session_want_refresh(ctx, session->method_state)) {
pr_verbose(ctx, "refreshing session with %P", peer);
session->handshakes_cleaned = true;
session->refreshing = true;
@@ -104,17 +104,17 @@ static void protocol_handle_recv(fastd_context_t *ctx, fastd_peer_t *peer, fastd
bool ok = false;
if (is_session_valid(ctx, &peer->protocol_state->old_session)) {
- if (peer->protocol_state->old_session.method->method->decrypt(ctx, peer, peer->protocol_state->old_session.method_state, &recv_buffer, buffer))
+ if (peer->protocol_state->old_session.method->provider->decrypt(ctx, peer, peer->protocol_state->old_session.method_state, &recv_buffer, buffer))
ok = true;
}
if (!ok) {
- if (peer->protocol_state->session.method->method->decrypt(ctx, peer, peer->protocol_state->session.method_state, &recv_buffer, buffer)) {
+ if (peer->protocol_state->session.method->provider->decrypt(ctx, 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->method->session_free(ctx, peer->protocol_state->old_session.method_state);
+ peer->protocol_state->old_session.method->provider->session_free(ctx, peer->protocol_state->old_session.method_state);
peer->protocol_state->old_session = (protocol_session_t){};
}
@@ -123,7 +123,7 @@ static void protocol_handle_recv(fastd_context_t *ctx, fastd_peer_t *peer, fastd
fastd_peer_unschedule_handshake(ctx, peer);
peer->protocol_state->session.handshakes_cleaned = true;
- if (peer->protocol_state->session.method->method->session_is_initiator(ctx, peer->protocol_state->session.method_state))
+ 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);
}
@@ -153,7 +153,7 @@ static void session_send(fastd_context_t *ctx, fastd_peer_t *peer, fastd_buffer_
size_t stat_size = buffer.len;
fastd_buffer_t send_buffer;
- if (!session->method->method->encrypt(ctx, peer, session->method_state, &send_buffer, buffer)) {
+ if (!session->method->provider->encrypt(ctx, peer, session->method_state, &send_buffer, buffer)) {
fastd_buffer_free(buffer);
pr_error(ctx, "failed to encrypt packet for %P", peer);
return;
@@ -171,7 +171,7 @@ static void protocol_send(fastd_context_t *ctx, fastd_peer_t *peer, fastd_buffer
check_session_refresh(ctx, peer);
- if (peer->protocol_state->session.method->method->session_is_initiator(ctx, peer->protocol_state->session.method_state) && is_session_valid(ctx, &peer->protocol_state->old_session)) {
+ 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);
}
@@ -181,7 +181,7 @@ static void protocol_send(fastd_context_t *ctx, fastd_peer_t *peer, fastd_buffer
}
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->method->min_encrypt_head_space, 8), session->method->method->min_encrypt_tail_space), 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);
}
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 638117d..eae7f75 100644
--- a/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.h
+++ b/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.h
@@ -106,7 +106,7 @@ 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->method->session_is_valid(ctx, session->method_state));
+ return (session->method && session->method->provider->session_is_valid(ctx, session->method_state));
}
#endif /* _FASTD_PROTOCOL_EC25519_FHMQVC_H_ */
diff --git a/src/protocols/ec25519_fhmqvc/handshake.c b/src/protocols/ec25519_fhmqvc/handshake.c
index 0225513..4b70d9a 100644
--- a/src/protocols/ec25519_fhmqvc/handshake.c
+++ b/src/protocols/ec25519_fhmqvc/handshake.c
@@ -71,22 +71,22 @@ static void derive_key(fastd_sha256_t *out, size_t blocks, const uint32_t *salt,
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)) {
if (peer->protocol_state->old_session.method)
- peer->protocol_state->old_session.method->method->session_free(ctx, peer->protocol_state->old_session.method_state);
+ peer->protocol_state->old_session.method->provider->session_free(ctx, 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->method->session_free(ctx, peer->protocol_state->session.method_state);
+ peer->protocol_state->session.method->provider->session_free(ctx, 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->method->session_free(ctx, peer->protocol_state->old_session.method_state);
+ peer->protocol_state->old_session.method->provider->session_free(ctx, peer->protocol_state->old_session.method_state);
peer->protocol_state->old_session = (protocol_session_t){};
}
else {
- peer->protocol_state->old_session.method->method->session_superseded(ctx, peer->protocol_state->old_session.method_state);
+ peer->protocol_state->old_session.method->provider->session_superseded(ctx, peer->protocol_state->old_session.method_state);
}
}
}
@@ -98,16 +98,16 @@ static inline bool new_session(fastd_context_t *ctx, fastd_peer_t *peer, const f
supersede_session(ctx, peer, method);
if (salt) {
- size_t blocks = block_count(method->method->key_length(ctx, method->ctx), sizeof(fastd_sha256_t));
+ size_t blocks = block_count(method->provider->key_length(ctx, 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->method->session_init(ctx, method->ctx, (const uint8_t*)secret, initiator);
+ peer->protocol_state->session.method_state = method->provider->session_init(ctx, 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->method->session_init_compat(ctx, method->ctx, hash.b, HASHBYTES, initiator);
+ peer->protocol_state->session.method_state = method->provider->session_init_compat(ctx, method->method, hash.b, HASHBYTES, initiator);
}
if (!peer->protocol_state->session.method_state)
@@ -131,7 +131,7 @@ static bool establish(fastd_context_t *ctx, fastd_peer_t *peer, const fastd_meth
return false;
}
- if (!salt && !method->method->session_init_compat) {
+ 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);
return false;
}
diff --git a/src/protocols/ec25519_fhmqvc/state.c b/src/protocols/ec25519_fhmqvc/state.c
index f27fcc6..46374cc 100644
--- a/src/protocols/ec25519_fhmqvc/state.c
+++ b/src/protocols/ec25519_fhmqvc/state.c
@@ -77,7 +77,7 @@ void fastd_protocol_ec25519_fhmqvc_init_peer_state(fastd_context_t *ctx, fastd_p
static void reset_session(fastd_context_t *ctx, protocol_session_t *session) {
if (session->method)
- session->method->method->session_free(ctx, session->method_state);
+ session->method->provider->session_free(ctx, session->method_state);
secure_memzero(session, sizeof(protocol_session_t));
}
diff --git a/src/types.h b/src/types.h
index 664518d..d74c052 100644
--- a/src/types.h
+++ b/src/types.h
@@ -114,7 +114,7 @@ typedef struct fastd_context fastd_context_t;
typedef struct fastd_protocol fastd_protocol_t;
typedef struct fastd_method_info fastd_method_info_t;
-typedef struct fastd_method fastd_method_t;
+typedef struct fastd_method_provider fastd_method_provider_t;
typedef struct fastd_cipher_info fastd_cipher_info_t;
typedef struct fastd_cipher fastd_cipher_t;
@@ -142,7 +142,7 @@ typedef struct fastd_protocol_state fastd_protocol_state_t;
typedef struct fastd_protocol_peer_config fastd_protocol_peer_config_t;
typedef struct fastd_protocol_peer_state fastd_protocol_peer_state_t;
-typedef struct fastd_method_context fastd_method_context_t;
+typedef struct fastd_method fastd_method_t;
typedef struct fastd_method_session_state fastd_method_session_state_t;
typedef struct fastd_cipher_state fastd_cipher_state_t;