diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-09-21 15:07:11 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-09-21 15:10:28 +0200 |
commit | 2acd81bd7a1b364b02831ae5f8e46457d9d07865 (patch) | |
tree | 969429177db12b56e402ad767531189b7a41834c /src/fastd.c | |
parent | 65912e3e6fce703b03eafc2b4bf11a17a02bd39e (diff) | |
download | fastd-2acd81bd7a1b364b02831ae5f8e46457d9d07865.tar fastd-2acd81bd7a1b364b02831ae5f8e46457d9d07865.zip |
Nicely encapsulate different crypto algorithm implementations
Diffstat (limited to 'src/fastd.c')
-rw-r--r-- | src/fastd.c | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/src/fastd.c b/src/fastd.c index f9d8403..5388384 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -27,8 +27,8 @@ #define _GNU_SOURCE #include "fastd.h" +#include "crypto.h" #include "handshake.h" -#include "linux_alg.h" #include "peer.h" #include "task.h" @@ -120,6 +120,32 @@ static void close_log(fastd_context *ctx) { closelog(); } +static void crypto_init(fastd_context *ctx) { +#ifdef USE_CRYPTO_AES128CTR + ctx->crypto_aes128ctr = ctx->conf->crypto_aes128ctr->init(ctx); + if (!ctx->crypto_aes128ctr) + exit_error(ctx, "Unable to initialize AES128-CTR implementation"); +#endif + +#ifdef USE_CRYPTO_GHASH + ctx->crypto_ghash = ctx->conf->crypto_ghash->init(ctx); + if (!ctx->crypto_ghash) + exit_error(ctx, "Unable to initialize GHASH implementation"); +#endif +} + +static void crypto_free(fastd_context *ctx) { +#ifdef USE_CRYPTO_AES128CTR + ctx->conf->crypto_aes128ctr->free(ctx, ctx->crypto_aes128ctr); + ctx->crypto_aes128ctr = NULL; +#endif + +#ifdef USE_CRYPTO_GHASH + ctx->conf->crypto_ghash->free(ctx, ctx->crypto_ghash); + ctx->crypto_ghash = NULL; +#endif +} + static void init_sockets(fastd_context *ctx) { struct sockaddr_in addr_in = ctx->conf->bind_addr_in; struct sockaddr_in6 addr_in6 = ctx->conf->bind_addr_in6; @@ -790,7 +816,7 @@ int main(int argc, char *argv[]) { init_log(&ctx); - fastd_linux_alg_init(&ctx); + crypto_init(&ctx); if (conf.generate_key) { conf.protocol->generate_key(&ctx); @@ -865,7 +891,7 @@ int main(int argc, char *argv[]) { free(ctx.protocol_state); free(ctx.eth_addr); - fastd_linux_alg_close(&ctx); + crypto_free(&ctx); close_log(&ctx); fastd_config_release(&ctx, &conf); |