summaryrefslogtreecommitdiffstats
path: root/src/methods
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-11-30 03:44:06 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-11-30 03:44:06 +0100
commitd5a043a7c0672df5da19a6024da4ab1af45151a9 (patch)
treeebd86ebe9aaae77e7766c5fa804a847b2d23c537 /src/methods
parent8088a82a2a91d29967cef920ba780eecdf72518e (diff)
downloadfastd-d5a043a7c0672df5da19a6024da4ab1af45151a9.tar
fastd-d5a043a7c0672df5da19a6024da4ab1af45151a9.zip
Rename methods to methods providers and method contexts to methods to reflect their function better
Diffstat (limited to 'src/methods')
-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
9 files changed, 136 insertions, 137 deletions
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,