summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-11-01 00:25:06 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-11-01 00:25:06 +0100
commit310cc1260fbd47016027bba04bc0c39b9c9144b3 (patch)
treeffecc2bea19317757528e57d3621f30fbc51e077
parent542861816d8305afa113653a84073be2fca68e50 (diff)
downloadfastd-310cc1260fbd47016027bba04bc0c39b9c9144b3.tar
fastd-310cc1260fbd47016027bba04bc0c39b9c9144b3.zip
Implement new session init API
-rw-r--r--src/fastd.h2
-rw-r--r--src/methods/aes128_gcm/aes128_gcm.c18
-rw-r--r--src/methods/null/null.c14
-rw-r--r--src/methods/xsalsa20_poly1305/xsalsa20_poly1305.c19
4 files changed, 43 insertions, 10 deletions
diff --git a/src/fastd.h b/src/fastd.h
index 2c3de6a..c47dafd 100644
--- a/src/fastd.h
+++ b/src/fastd.h
@@ -87,6 +87,8 @@ struct fastd_method {
size_t (*min_encrypt_tail_space)(fastd_context_t *ctx);
size_t (*min_decrypt_tail_space)(fastd_context_t *ctx);
+ size_t (*key_length)(fastd_context_t *ctx);
+ fastd_method_session_state_t* (*session_init)(fastd_context_t *ctx, uint8_t *secret, bool initiator);
fastd_method_session_state_t* (*session_init_compat)(fastd_context_t *ctx, 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);
diff --git a/src/methods/aes128_gcm/aes128_gcm.c b/src/methods/aes128_gcm/aes128_gcm.c
index 6608618..a2fbf17 100644
--- a/src/methods/aes128_gcm/aes128_gcm.c
+++ b/src/methods/aes128_gcm/aes128_gcm.c
@@ -59,10 +59,11 @@ static size_t method_min_decrypt_tail_space(fastd_context_t *ctx UNUSED) {
}
-static fastd_method_session_state_t* method_session_init_key(fastd_context_t *ctx, uint8_t *secret, size_t length, bool initiator) {
- if (length < sizeof(fastd_block128_t))
- exit_bug(ctx, "aes128-gcm: tried to init with short secret");
+static size_t method_key_length(fastd_context_t *ctx UNUSED) {
+ return sizeof(fastd_block128_t);
+}
+static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx, 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);
@@ -81,6 +82,13 @@ static fastd_method_session_state_t* method_session_init_key(fastd_context_t *ct
return session;
}
+static fastd_method_session_state_t* method_session_init_compat(fastd_context_t *ctx, uint8_t *secret, size_t length, bool initiator) {
+ if (length < sizeof(fastd_block128_t))
+ exit_bug(ctx, "aes128-gcm: tried to init with short secret");
+
+ return method_session_init(ctx, 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));
}
@@ -230,7 +238,9 @@ const fastd_method_t fastd_method_aes128_gcm = {
.min_encrypt_tail_space = method_min_encrypt_tail_space,
.min_decrypt_tail_space = method_min_decrypt_tail_space,
- .session_init_compat = method_session_init_key,
+ .key_length = method_key_length,
+ .session_init = method_session_init,
+ .session_init_compat = method_session_init_compat,
.session_is_valid = method_session_is_valid,
.session_is_initiator = method_session_is_initiator,
.session_want_refresh = method_session_want_refresh,
diff --git a/src/methods/null/null.c b/src/methods/null/null.c
index 004bb43..c51b592 100644
--- a/src/methods/null/null.c
+++ b/src/methods/null/null.c
@@ -41,7 +41,11 @@ static size_t method_min_head_tail_space(fastd_context_t *ctx UNUSED) {
return 0;
}
-static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx UNUSED, uint8_t *secret UNUSED, size_t length UNUSED, bool initiator) {
+static size_t method_key_length(fastd_context_t *ctx UNUSED) {
+ return 0;
+}
+
+static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx UNUSED, uint8_t *secret UNUSED, bool initiator) {
fastd_method_session_state_t *session = malloc(sizeof(fastd_method_session_state_t));
session->valid = true;
@@ -50,6 +54,10 @@ 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, uint8_t *secret, size_t length UNUSED, bool initiator) {
+ return method_session_init(ctx, secret, initiator);
+}
+
static bool method_session_is_valid(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session) {
return (session && session->valid);
}
@@ -84,7 +92,9 @@ const fastd_method_t fastd_method_null = {
.min_encrypt_tail_space = method_min_head_tail_space,
.min_decrypt_tail_space = method_min_head_tail_space,
- .session_init_compat = method_session_init,
+ .key_length = method_key_length,
+ .session_init = method_session_init,
+ .session_init_compat = method_session_init_compat,
.session_is_valid = method_session_is_valid,
.session_is_initiator = method_session_is_initiator,
.session_want_refresh = method_session_want_refresh,
diff --git a/src/methods/xsalsa20_poly1305/xsalsa20_poly1305.c b/src/methods/xsalsa20_poly1305/xsalsa20_poly1305.c
index 964f004..466ff34 100644
--- a/src/methods/xsalsa20_poly1305/xsalsa20_poly1305.c
+++ b/src/methods/xsalsa20_poly1305/xsalsa20_poly1305.c
@@ -53,10 +53,12 @@ static size_t method_min_tail_space(fastd_context_t *ctx UNUSED) {
return 0;
}
-static fastd_method_session_state_t* method_session_init_key(fastd_context_t *ctx, 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");
+static size_t method_key_length(fastd_context_t *ctx UNUSED) {
+ return crypto_secretbox_xsalsa20poly1305_KEYBYTES;
+}
+
+static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx, 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);
@@ -66,6 +68,13 @@ static fastd_method_session_state_t* method_session_init_key(fastd_context_t *ct
return session;
}
+static fastd_method_session_state_t* method_session_init_compat(fastd_context_t *ctx, 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, 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));
}
@@ -161,7 +170,9 @@ const fastd_method_t fastd_method_xsalsa20_poly1305 = {
.min_encrypt_tail_space = method_min_tail_space,
.min_decrypt_tail_space = method_min_tail_space,
- .session_init_compat = method_session_init_key,
+ .key_length = method_key_length,
+ .session_init = method_session_init,
+ .session_init_compat = method_session_init_compat,
.session_is_valid = method_session_is_valid,
.session_is_initiator = method_session_is_initiator,
.session_want_refresh = method_session_want_refresh,