summaryrefslogtreecommitdiffstats
path: root/src/methods
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-11-29 22:24:02 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-11-29 22:24:02 +0100
commita09d04a02231964fa5a8f0113e9909cfb140fe4e (patch)
tree2d3da68cf388d88ebff299f7c3866c608c847f40 /src/methods
parentd0707b161d10cf79242d40b24853988c89c7604a (diff)
downloadfastd-a09d04a02231964fa5a8f0113e9909cfb140fe4e.tar
fastd-a09d04a02231964fa5a8f0113e9909cfb140fe4e.zip
Revert "crypto: separate cipher/MAC availability check from information request"
This reverts commit d0707b161d10cf79242d40b24853988c89c7604a.
Diffstat (limited to 'src/methods')
-rw-r--r--src/methods/cipher_test/cipher_test.c28
-rw-r--r--src/methods/composed_gmac/composed_gmac.c36
-rw-r--r--src/methods/generic_gcm/generic_gcm.c39
-rw-r--r--src/methods/generic_gmac/generic_gmac.c40
-rw-r--r--src/methods/generic_poly1305/generic_poly1305.c33
5 files changed, 100 insertions, 76 deletions
diff --git a/src/methods/cipher_test/cipher_test.c b/src/methods/cipher_test/cipher_test.c
index 32512b3..573e90a 100644
--- a/src/methods/cipher_test/cipher_test.c
+++ b/src/methods/cipher_test/cipher_test.c
@@ -38,7 +38,7 @@ 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) {
+static bool cipher_get(fastd_context_t *ctx, const char *name, const fastd_cipher_info_t **info, const fastd_cipher_t **cipher, const fastd_cipher_context_t **cctx) {
size_t len = strlen(name);
if (len < 12)
@@ -51,25 +51,33 @@ static bool cipher_get(fastd_context_t *ctx, const char *name, const fastd_ciphe
memcpy(cipher_name, name, len-12);
cipher_name[len-12] = 0;
- if (check && !fastd_cipher_is_available(cipher_name))
- return false;
+ const fastd_cipher_info_t *cipher_info = NULL;
+
+ if (ctx) {
+ *cipher = fastd_cipher_get_by_name(ctx, cipher_name, &cipher_info, cctx);
+ if (!*cipher)
+ return false;
+ }
+ else {
+ cipher_info = fastd_cipher_info_get_by_name(cipher_name);
+ if (!cipher_info)
+ return false;
+ }
- if (ctx)
- *cipher = fastd_cipher_get_by_name(ctx, cipher_name, cipher_info, cctx);
- else if (cipher_info)
- *cipher_info = fastd_cipher_info_get_by_name(cipher_name);
+ if (info)
+ *info = cipher_info;
return true;
}
static bool method_provides(const char *name) {
- return cipher_get(NULL, name, NULL, NULL, NULL, 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 *info;
- if (!cipher_get(NULL, name, &info, NULL, NULL, false))
+ if (!cipher_get(NULL, name, &info, NULL, NULL))
exit_bug(ctx, "cipher-test: can't get cipher key length");
return info->key_length;
@@ -80,7 +88,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, "cipher-test: can't instanciate cipher");
session->cipher_state = session->cipher->init_state(ctx, session->cipher_ctx, secret);
diff --git a/src/methods/composed_gmac/composed_gmac.c b/src/methods/composed_gmac/composed_gmac.c
index 870b82b..b8ee2f6 100644
--- a/src/methods/composed_gmac/composed_gmac.c
+++ b/src/methods/composed_gmac/composed_gmac.c
@@ -52,9 +52,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,
- const fastd_cipher_info_t **gmac_cipher_info, const fastd_cipher_t **gmac_cipher, const fastd_cipher_context_t **gmac_cctx,
- bool check) {
- if (check && !fastd_mac_is_available("ghash"))
+ const fastd_cipher_info_t **gmac_cipher_info, const fastd_cipher_t **gmac_cipher, const fastd_cipher_context_t **gmac_cctx) {
+ if (!fastd_mac_info_get_by_name("ghash"))
return false;
size_t len = strlen(name);
@@ -77,20 +76,28 @@ static bool cipher_get(fastd_context_t *ctx, const char *name,
*gmac_cipher_name = 0;
gmac_cipher_name++;
- if (check && (!fastd_cipher_is_available(cipher_name) || !fastd_cipher_is_available(gmac_cipher_name)))
- return false;
+ const fastd_cipher_info_t *info = NULL;
+ const fastd_cipher_info_t *gmac_info = NULL;
if (ctx) {
- *cipher = fastd_cipher_get_by_name(ctx, cipher_name, cipher_info, cctx);
- *gmac_cipher = fastd_cipher_get_by_name(ctx, gmac_cipher_name, gmac_cipher_info, gmac_cctx);
+ *cipher = fastd_cipher_get_by_name(ctx, cipher_name, &info, cctx);
+ *gmac_cipher = fastd_cipher_get_by_name(ctx, gmac_cipher_name, &gmac_info, gmac_cctx);
+ if (!(*cipher && *gmac_cipher))
+ return false;
}
else {
- if (cipher_info)
- *cipher_info = fastd_cipher_info_get_by_name(cipher_name);
- if (gmac_cipher_info)
- *gmac_cipher_info = fastd_cipher_info_get_by_name(gmac_cipher_name);
+ info = fastd_cipher_info_get_by_name(cipher_name);
+ gmac_info = fastd_cipher_info_get_by_name(gmac_cipher_name);
+ if (!(info && gmac_info))
+ return false;
}
+ if (cipher_info)
+ *cipher_info = info;
+
+ if (gmac_cipher_info)
+ *gmac_cipher_info = gmac_info;
+
return true;
}
@@ -98,7 +105,7 @@ static bool cipher_get(fastd_context_t *ctx, const char *name,
static bool method_provides(const char *name) {
const fastd_cipher_info_t *gmac_cipher_info;
- if (!cipher_get(NULL, name, NULL, NULL, NULL, &gmac_cipher_info, NULL, NULL, true))
+ if (!cipher_get(NULL, name, NULL, NULL, NULL, &gmac_cipher_info, NULL, NULL))
return false;
if (gmac_cipher_info->iv_length <= COMMON_NONCEBYTES)
@@ -111,7 +118,7 @@ static size_t method_key_length(fastd_context_t *ctx, const char *name) {
const fastd_cipher_info_t *cipher_info;
const fastd_cipher_info_t *gmac_cipher_info;
- if (!cipher_get(NULL, name, &cipher_info, NULL, NULL, &gmac_cipher_info, NULL, NULL, false))
+ if (!cipher_get(NULL, name, &cipher_info, NULL, NULL, &gmac_cipher_info, NULL, NULL))
exit_bug(ctx, "composed-gmac: can't get cipher key length");
return cipher_info->key_length + gmac_cipher_info->key_length;
@@ -124,8 +131,7 @@ static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx, c
if (!cipher_get(ctx, name,
&session->cipher_info, &session->cipher, &session->cipher_ctx,
- &session->gmac_cipher_info, &session->gmac_cipher, &session->gmac_cipher_ctx,
- false))
+ &session->gmac_cipher_info, &session->gmac_cipher, &session->gmac_cipher_ctx))
exit_bug(ctx, "composed-gmac: can't instanciate cipher");
session->cipher_state = session->cipher->init_state(ctx, session->cipher_ctx, secret);
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);
diff --git a/src/methods/generic_gmac/generic_gmac.c b/src/methods/generic_gmac/generic_gmac.c
index 50f4f57..5501076 100644
--- a/src/methods/generic_gmac/generic_gmac.c
+++ b/src/methods/generic_gmac/generic_gmac.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);
@@ -62,32 +62,36 @@ static bool cipher_get(fastd_context_t *ctx, const char *name, const fastd_ciphe
memcpy(cipher_name, name, len-5);
cipher_name[len-5] = 0;
- if (check && !fastd_cipher_is_available(cipher_name))
+ const fastd_cipher_info_t *info = NULL;
+
+ if (ctx) {
+ *cipher = fastd_cipher_get_by_name(ctx, cipher_name, &info, cctx);
+ if (!*cipher)
+ return false;
+ }
+ else {
+ info = fastd_cipher_info_get_by_name(cipher_name);
+ if (!info)
+ return false;
+ }
+
+ if (info->iv_length <= COMMON_NONCEBYTES)
return false;
- if (ctx)
- *cipher = fastd_cipher_get_by_name(ctx, cipher_name, cipher_info, cctx);
- else if (cipher_info)
- *cipher_info = fastd_cipher_info_get_by_name(cipher_name);
+ 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;
+static bool method_provides(const char *name) {
+ 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-gmac: can't get cipher key length");
return cipher_info->key_length + sizeof(fastd_block128_t);
@@ -98,7 +102,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-gmac: can't instanciate cipher");
session->cipher_state = session->cipher->init_state(ctx, session->cipher_ctx, secret);
diff --git a/src/methods/generic_poly1305/generic_poly1305.c b/src/methods/generic_poly1305/generic_poly1305.c
index 80ced8c..3820907 100644
--- a/src/methods/generic_poly1305/generic_poly1305.c
+++ b/src/methods/generic_poly1305/generic_poly1305.c
@@ -43,7 +43,7 @@ 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) {
+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) {
size_t len = strlen(name);
if (len < 9)
@@ -56,28 +56,31 @@ static bool cipher_get(fastd_context_t *ctx, const char *name, const fastd_ciphe
memcpy(cipher_name, name, len-9);
cipher_name[len-9] = 0;
- if (check && !fastd_cipher_is_available(cipher_name))
+ const fastd_cipher_info_t *info = NULL;
+
+ if (ctx) {
+ *cipher = fastd_cipher_get_by_name(ctx, cipher_name, &info, cctx);
+ if (!*cipher)
+ return false;
+ }
+ else {
+ info = fastd_cipher_info_get_by_name(cipher_name);
+ if (!info)
+ return false;
+ }
+
+ if (info->iv_length <= COMMON_NONCEBYTES)
return false;
- if (ctx)
- *cipher = fastd_cipher_get_by_name(ctx, cipher_name, cipher_info, cctx);
- else if (cipher_info)
- *cipher_info = fastd_cipher_info_get_by_name(cipher_name);
+ 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) {