summaryrefslogtreecommitdiffstats
path: root/src/crypto/mac/macs.c.in
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-05-28 05:53:26 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-05-29 01:30:07 +0200
commitefcafca969d2e789cdf106609b04a86ef9b53a3d (patch)
tree001ca30403dea064b4d30bb521d8eb8de91f10a3 /src/crypto/mac/macs.c.in
parentd5da100c55d80391d2e941a41c0e0dccf2a6e33e (diff)
downloadfastd-efcafca969d2e789cdf106609b04a86ef9b53a3d.tar
fastd-efcafca969d2e789cdf106609b04a86ef9b53a3d.zip
Simplify configuration of cipher and MAC implementations
Let the cipher and MAC handlers just store the chosen implementations themselves instead of relying on the global configuration.
Diffstat (limited to 'src/crypto/mac/macs.c.in')
-rw-r--r--src/crypto/mac/macs.c.in22
1 files changed, 7 insertions, 15 deletions
diff --git a/src/crypto/mac/macs.c.in b/src/crypto/mac/macs.c.in
index 3a8c943..0db26d9 100644
--- a/src/crypto/mac/macs.c.in
+++ b/src/crypto/mac/macs.c.in
@@ -46,14 +46,14 @@ typedef struct mac_entry {
static const mac_entry_t macs[] = { @MAC_LIST@
};
+static const fastd_mac_t *mac_conf[array_size(macs)] = {};
+
static inline bool mac_available(const fastd_mac_t *mac) {
return (!mac->available) || mac->available();
}
-const fastd_mac_t** fastd_mac_config_alloc(void) {
- const fastd_mac_t **mac_conf = calloc(array_size(macs), sizeof(const fastd_mac_t*));
-
+void fastd_mac_init(void) {
size_t i, j;
for (i = 0; i < array_size(macs); i++) {
for (j = 0; macs[i].impls[j].impl; j++) {
@@ -63,15 +63,9 @@ const fastd_mac_t** fastd_mac_config_alloc(void) {
mac_conf[i] = macs[i].impls[j].impl;
}
-
- return mac_conf;
-}
-
-void fastd_mac_config_free(const fastd_mac_t **mac_conf) {
- free(mac_conf);
}
-bool fastd_mac_config(const fastd_mac_t **mac_conf, const char *name, const char *impl) {
+bool fastd_mac_config(const char *name, const char *impl) {
size_t i;
for (i = 0; i < array_size(macs); i++) {
if (!strcmp(macs[i].name, name)) {
@@ -99,10 +93,8 @@ const fastd_mac_info_t* fastd_mac_info_get_by_name(const char *name) {
if (strcmp(macs[i].name, name))
continue;
- for (j = 0; macs[i].impls[j].impl; j++) {
- if (mac_available(macs[i].impls[j].impl))
- return macs[i].info;
- }
+ if (mac_conf[i])
+ return macs[i].info;
break;
}
@@ -114,7 +106,7 @@ const fastd_mac_t* fastd_mac_get(const fastd_mac_info_t *info) {
size_t i;
for (i = 0; i < array_size(macs); i++) {
if (macs[i].info == info)
- return conf.macs[i];
+ return mac_conf[i];
}
return NULL;