diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-11-27 20:53:00 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-11-27 20:53:00 +0100 |
commit | 7a08e6823ef636917a95dbc4928048723efe864d (patch) | |
tree | 3faa824113cb3ddbc9c2b734107db1d5ec3c5c07 /src/crypto/mac | |
parent | ba5abca808dc85e2de2e11351832329f1566bc7e (diff) | |
download | fastd-7a08e6823ef636917a95dbc4928048723efe864d.tar fastd-7a08e6823ef636917a95dbc4928048723efe864d.zip |
Allow checking if a crypto algorithm is available at runtime
Diffstat (limited to 'src/crypto/mac')
-rw-r--r-- | src/crypto/mac/ghash/builtin/ghash_builtin.c | 2 | ||||
-rw-r--r-- | src/crypto/mac/macs.c.in | 25 |
2 files changed, 20 insertions, 7 deletions
diff --git a/src/crypto/mac/ghash/builtin/ghash_builtin.c b/src/crypto/mac/ghash/builtin/ghash_builtin.c index cc47427..cc81e74 100644 --- a/src/crypto/mac/ghash/builtin/ghash_builtin.c +++ b/src/crypto/mac/ghash/builtin/ghash_builtin.c @@ -132,6 +132,8 @@ static void ghash_free(fastd_context_t *ctx UNUSED, fastd_mac_context_t *mctx UN } const fastd_mac_t fastd_mac_ghash_builtin = { + .available = fastd_true, + .initialize = ghash_initialize, .init_state = ghash_init_state, diff --git a/src/crypto/mac/macs.c.in b/src/crypto/mac/macs.c.in index 9952396..3587322 100644 --- a/src/crypto/mac/macs.c.in +++ b/src/crypto/mac/macs.c.in @@ -50,9 +50,15 @@ static const mac_entry_t macs[] = { @MAC_LIST@ const fastd_mac_t** fastd_mac_config_alloc(void) { const fastd_mac_t **mac_conf = calloc(array_size(macs), sizeof(const fastd_mac_t*)); - size_t i; - for (i = 0; i < array_size(macs); i++) - mac_conf[i] = macs[i].impls[0].impl; + size_t i, j; + for (i = 0; i < array_size(macs); i++) { + for (j = 0; macs[i].impls[j].impl; j++) { + if (macs[i].impls[j].impl->available()) + break; + } + + mac_conf[i] = macs[i].impls[j].impl; + } return mac_conf; } @@ -68,6 +74,9 @@ bool fastd_mac_config(const fastd_mac_t **mac_conf, const char *name, const char size_t j; for (j = 0; macs[i].impls[j].impl; j++) { if (!strcmp(macs[i].impls[j].name, impl)) { + if (!macs[i].impls[j].impl->available()) + return false; + mac_conf[i] = macs[i].impls[j].impl; return true; } @@ -99,15 +108,17 @@ void fastd_mac_free(fastd_context_t *ctx) { } const fastd_mac_info_t* fastd_mac_info_get_by_name(const char *name) { - size_t i; + size_t i, j; for (i = 0; i < array_size(macs); i++) { if (strcmp(macs[i].name, name)) continue; - if (!macs[i].impls[0].impl) - continue; + for (j = 0; macs[i].impls[j].impl; j++) { + if (macs[i].impls[j].impl->available()) + return macs[i].info; + } - return macs[i].info; + break; } return NULL; |