diff options
-rw-r--r-- | src/crypto/cipher/ciphers.c.in | 17 | ||||
-rw-r--r-- | src/fastd.h | 2 | ||||
-rw-r--r-- | src/methods/aes128_gcm/aes128_gcm.c | 3 |
3 files changed, 13 insertions, 9 deletions
diff --git a/src/crypto/cipher/ciphers.c.in b/src/crypto/cipher/ciphers.c.in index ee710f8..7ae2dea 100644 --- a/src/crypto/cipher/ciphers.c.in +++ b/src/crypto/cipher/ciphers.c.in @@ -77,8 +77,10 @@ void fastd_cipher_init(fastd_context_t *ctx) { ctx->cipher_contexts = calloc(array_size(ciphers), sizeof(fastd_cipher_context_t*)); size_t i; - for (i = 0; i < array_size(ciphers); i++) - ctx->cipher_contexts[i] = ctx->conf->ciphers[i]->initialize(ctx); + for (i = 0; i < array_size(ciphers); i++) { + if (ctx->conf->ciphers[i]) + ctx->cipher_contexts[i] = ctx->conf->ciphers[i]->initialize(ctx); + } } void fastd_cipher_free(fastd_context_t *ctx) { @@ -89,15 +91,16 @@ void fastd_cipher_free(fastd_context_t *ctx) { free(ctx->cipher_contexts); } -bool fastd_cipher_get_by_name(fastd_context_t *ctx, const char *name, const fastd_cipher_t **cipher, fastd_cipher_context_t **cctx) { +const fastd_cipher_t* fastd_cipher_get_by_name(fastd_context_t *ctx, const char *name, fastd_cipher_context_t **cctx) { size_t i; for (i = 0; i < array_size(ciphers); i++) { if (!strcmp(ciphers[i].name, name)) { - *cipher = ctx->conf->ciphers[i]; - *cctx = ctx->cipher_contexts[i]; - return true; + if (cctx) + *cctx = ctx->cipher_contexts[i]; + + return ctx->conf->ciphers[i]; } } - return false; + return NULL; } diff --git a/src/fastd.h b/src/fastd.h index be4cf11..2607322 100644 --- a/src/fastd.h +++ b/src/fastd.h @@ -367,7 +367,7 @@ bool fastd_cipher_config(const fastd_cipher_t **cipher_conf, const char *name, c void fastd_cipher_init(fastd_context_t *ctx); void fastd_cipher_free(fastd_context_t *ctx); -bool fastd_cipher_get_by_name(fastd_context_t *ctx, const char *name, const fastd_cipher_t **cipher, fastd_cipher_context_t **cctx); +const fastd_cipher_t* fastd_cipher_get_by_name(fastd_context_t *ctx, const char *name, fastd_cipher_context_t **cctx); bool fastd_config_protocol(fastd_context_t *ctx, fastd_config_t *conf, const char *name); bool fastd_config_method(fastd_context_t *ctx, fastd_config_t *conf, const char *name); diff --git a/src/methods/aes128_gcm/aes128_gcm.c b/src/methods/aes128_gcm/aes128_gcm.c index 20f393f..59e6914 100644 --- a/src/methods/aes128_gcm/aes128_gcm.c +++ b/src/methods/aes128_gcm/aes128_gcm.c @@ -71,7 +71,8 @@ static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx, c fastd_method_common_init(ctx, &session->common, initiator); - if (!fastd_cipher_get_by_name(ctx, "aes128-ctr", &session->aes128_ctr, &session->aes128_ctr_ctx)) + session->aes128_ctr = fastd_cipher_get_by_name(ctx, "aes128-ctr", &session->aes128_ctr_ctx); + if (!session->aes128_ctr) exit_bug(ctx, "aes128-gcm: can't instanciate aes128-ctr"); session->aes128_ctr_state = session->aes128_ctr->init_state(ctx, session->aes128_ctr_ctx, secret); |