diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-11-02 13:42:55 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-11-02 13:42:55 +0100 |
commit | 7a3c8bee42879add84a143ff98f28cbd0251dc7b (patch) | |
tree | 3138520bf3e16cd33fa03dfe68c1fedf67c3d901 /src/methods | |
parent | f2c2f2926bce65c5c09d274c514d382ffd98f78c (diff) | |
download | fastd-7a3c8bee42879add84a143ff98f28cbd0251dc7b.tar fastd-7a3c8bee42879add84a143ff98f28cbd0251dc7b.zip |
Allow flexible specification of methods provided by an implementation
Diffstat (limited to 'src/methods')
-rw-r--r-- | src/methods/aes128_gcm/aes128_gcm.c | 12 | ||||
-rw-r--r-- | src/methods/methods.c.in | 4 | ||||
-rw-r--r-- | src/methods/null/null.c | 12 | ||||
-rw-r--r-- | src/methods/xsalsa20_poly1305/xsalsa20_poly1305.c | 12 |
4 files changed, 26 insertions, 14 deletions
diff --git a/src/methods/aes128_gcm/aes128_gcm.c b/src/methods/aes128_gcm/aes128_gcm.c index 59e6914..8a6325e 100644 --- a/src/methods/aes128_gcm/aes128_gcm.c +++ b/src/methods/aes128_gcm/aes128_gcm.c @@ -40,6 +40,10 @@ struct fastd_method_session_state { }; +static bool method_provides(fastd_context_t *ctx UNUSED, const char *name) { + return !strcmp(name, "aes128-gcm"); +} + static size_t method_max_packet_size(fastd_context_t *ctx) { return (fastd_max_packet_size(ctx) + COMMON_NONCEBYTES + sizeof(fastd_block128_t)); } @@ -66,7 +70,7 @@ 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, const uint8_t *secret, bool initiator) { +static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx, const char *name 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); @@ -87,11 +91,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 uint8_t *secret, size_t length, bool initiator) { +static fastd_method_session_state_t* method_session_init_compat(fastd_context_t *ctx, const char *name, const 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); + return method_session_init(ctx, name, secret, initiator); } static bool method_session_is_valid(fastd_context_t *ctx, fastd_method_session_state_t *session) { @@ -235,7 +239,7 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho } const fastd_method_t fastd_method_aes128_gcm = { - .name = "aes128-gcm", + .provides = method_provides, .max_packet_size = method_max_packet_size, .min_encrypt_head_space = method_min_encrypt_head_space, diff --git a/src/methods/methods.c.in b/src/methods/methods.c.in index 8f5bb10..f39fbc1 100644 --- a/src/methods/methods.c.in +++ b/src/methods/methods.c.in @@ -33,10 +33,10 @@ static const fastd_method_t *const methods[] = { @METHOD_LIST@ }; -const fastd_method_t* fastd_method_get_by_name(const char *name) { +const fastd_method_t* fastd_method_get_by_name(fastd_context_t *ctx, const char *name) { size_t i; for (i = 0; i < array_size(methods); i++) { - if (!strcmp(methods[i]->name, name)) + if (methods[i]->provides(ctx, name)) return methods[i]; } diff --git a/src/methods/null/null.c b/src/methods/null/null.c index f49d94a..cba7931 100644 --- a/src/methods/null/null.c +++ b/src/methods/null/null.c @@ -33,6 +33,10 @@ struct fastd_method_session_state { }; +static bool method_provides(fastd_context_t *ctx UNUSED, const char *name) { + return !strcmp(name, "null"); +} + static size_t method_max_packet_size(fastd_context_t *ctx) { return fastd_max_packet_size(ctx); } @@ -45,7 +49,7 @@ 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, const uint8_t *secret UNUSED, bool initiator) { +static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx UNUSED, const char *name UNUSED, const uint8_t *secret UNUSED, bool initiator) { fastd_method_session_state_t *session = malloc(sizeof(fastd_method_session_state_t)); session->valid = true; @@ -54,8 +58,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 uint8_t *secret, size_t length UNUSED, bool initiator) { - return method_session_init(ctx, secret, initiator); +static fastd_method_session_state_t* method_session_init_compat(fastd_context_t *ctx, const char *name, const uint8_t *secret, size_t length UNUSED, bool initiator) { + return method_session_init(ctx, name, secret, initiator); } static bool method_session_is_valid(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session) { @@ -84,7 +88,7 @@ static bool method_passthrough(fastd_context_t *ctx UNUSED, fastd_peer_t *peer U } const fastd_method_t fastd_method_null = { - .name = "null", + .provides = method_provides, .max_packet_size = method_max_packet_size, .min_encrypt_head_space = method_min_head_tail_space, diff --git a/src/methods/xsalsa20_poly1305/xsalsa20_poly1305.c b/src/methods/xsalsa20_poly1305/xsalsa20_poly1305.c index 768e5c8..220e913 100644 --- a/src/methods/xsalsa20_poly1305/xsalsa20_poly1305.c +++ b/src/methods/xsalsa20_poly1305/xsalsa20_poly1305.c @@ -37,6 +37,10 @@ struct fastd_method_session_state { }; +static bool method_provides(fastd_context_t *ctx UNUSED, const char *name) { + return !strcmp(name, "xsalsa20-poly1305"); +} + static size_t method_max_packet_size(fastd_context_t *ctx) { return (fastd_max_packet_size(ctx) + COMMON_NONCEBYTES + crypto_secretbox_xsalsa20poly1305_ZEROBYTES - crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES); } @@ -58,7 +62,7 @@ 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, const uint8_t *secret, bool initiator) { +static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx, const char *name 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); @@ -68,11 +72,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 uint8_t *secret, size_t length, bool initiator) { +static fastd_method_session_state_t* method_session_init_compat(fastd_context_t *ctx, const char *name, 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, secret, initiator); + return method_session_init(ctx, name, secret, initiator); } static bool method_session_is_valid(fastd_context_t *ctx, fastd_method_session_state_t *session) { @@ -162,7 +166,7 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho } const fastd_method_t fastd_method_xsalsa20_poly1305 = { - .name = "xsalsa20-poly1305", + .provides = method_provides, .max_packet_size = method_max_packet_size, .min_encrypt_head_space = method_min_encrypt_head_space, |