summaryrefslogtreecommitdiffstats
path: root/src/methods/generic_gcm
diff options
context:
space:
mode:
Diffstat (limited to 'src/methods/generic_gcm')
-rw-r--r--src/methods/generic_gcm/generic_gcm.c39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/methods/generic_gcm/generic_gcm.c b/src/methods/generic_gcm/generic_gcm.c
index 2a7987c..9481100 100644
--- a/src/methods/generic_gcm/generic_gcm.c
+++ b/src/methods/generic_gcm/generic_gcm.c
@@ -43,8 +43,8 @@ struct fastd_method_session_state {
};
-static bool cipher_get(fastd_context_t *ctx, const char *name, const fastd_cipher_info_t **cipher_info, const fastd_cipher_t **cipher, const fastd_cipher_context_t **cctx, bool check) {
- if (check && !fastd_mac_is_available("ghash"))
+static bool cipher_get(fastd_context_t *ctx, const char *name, const fastd_cipher_info_t **cipher_info, const fastd_cipher_t **cipher, const fastd_cipher_context_t **cctx) {
+ if (!fastd_mac_info_get_by_name("ghash"))
return false;
size_t len = strlen(name);
@@ -59,33 +59,36 @@ static bool cipher_get(fastd_context_t *ctx, const char *name, const fastd_ciphe
memcpy(name_ctr, name, len-3);
strncpy(name_ctr+len-3, "ctr", 4);
- if (check && !fastd_cipher_is_available(name_ctr))
+ const fastd_cipher_info_t *info = NULL;
+
+ if (ctx) {
+ *cipher = fastd_cipher_get_by_name(ctx, name_ctr, &info, cctx);
+ if (!*cipher)
+ return false;
+ }
+ else {
+ info = fastd_cipher_info_get_by_name(name_ctr);
+ if (!info)
+ return false;
+ }
+
+ if (info->iv_length <= COMMON_NONCEBYTES)
return false;
- if (ctx)
- *cipher = fastd_cipher_get_by_name(ctx, name_ctr, cipher_info, cctx);
- else if (cipher_info)
- *cipher_info = fastd_cipher_info_get_by_name(name_ctr);
+ if (cipher_info)
+ *cipher_info = info;
return true;
}
static bool method_provides(const char *name) {
- const fastd_cipher_info_t *cipher_info;
-
- if (!cipher_get(NULL, name, &cipher_info, NULL, NULL, true))
- return false;
-
- if (cipher_info->iv_length <= COMMON_NONCEBYTES)
- return false;
-
- return true;
+ return cipher_get(NULL, name, NULL, NULL, NULL);
}
static size_t method_key_length(fastd_context_t *ctx, const char *name) {
const fastd_cipher_info_t *cipher_info;
- if (!cipher_get(NULL, name, &cipher_info, NULL, NULL, false))
+ if (!cipher_get(NULL, name, &cipher_info, NULL, NULL))
exit_bug(ctx, "generic-gcm: can't get cipher key length");
return cipher_info->key_length;
@@ -96,7 +99,7 @@ static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx, c
fastd_method_common_init(ctx, &session->common, initiator);
- if (!cipher_get(ctx, name, &session->cipher_info, &session->cipher, &session->cipher_ctx, false))
+ if (!cipher_get(ctx, name, &session->cipher_info, &session->cipher, &session->cipher_ctx))
exit_bug(ctx, "generic-gcm: can't instanciate cipher");
session->cipher_state = session->cipher->init_state(ctx, session->cipher_ctx, secret);