From 2acd81bd7a1b364b02831ae5f8e46457d9d07865 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 21 Sep 2012 15:07:11 +0200 Subject: Nicely encapsulate different crypto algorithm implementations --- src/fastd.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'src/fastd.c') 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); -- cgit v1.2.3