summaryrefslogtreecommitdiffstats
path: root/src/crypto/cipher
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/cipher
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/cipher')
-rw-r--r--src/crypto/cipher/ciphers.c.in26
1 files changed, 10 insertions, 16 deletions
diff --git a/src/crypto/cipher/ciphers.c.in b/src/crypto/cipher/ciphers.c.in
index 1796cc5..01b5a35 100644
--- a/src/crypto/cipher/ciphers.c.in
+++ b/src/crypto/cipher/ciphers.c.in
@@ -46,14 +46,15 @@ typedef struct cipher_entry {
static const cipher_entry_t ciphers[] = { @CIPHER_LIST@
};
+static const fastd_cipher_t *cipher_conf[array_size(ciphers)] = {};
+
static inline bool cipher_available(const fastd_cipher_t *cipher) {
return (!cipher->available) || cipher->available();
}
-const fastd_cipher_t** fastd_cipher_config_alloc(void) {
- const fastd_cipher_t **cipher_conf = calloc(array_size(ciphers), sizeof(const fastd_cipher_t*));
-
+/** Initializes the list of ciphers */
+void fastd_cipher_init(void) {
size_t i, j;
for (i = 0; i < array_size(ciphers); i++) {
for (j = 0; ciphers[i].impls[j].impl; j++) {
@@ -63,15 +64,10 @@ const fastd_cipher_t** fastd_cipher_config_alloc(void) {
cipher_conf[i] = ciphers[i].impls[j].impl;
}
-
- return cipher_conf;
-}
-
-void fastd_cipher_config_free(const fastd_cipher_t **cipher_conf) {
- free(cipher_conf);
}
-bool fastd_cipher_config(const fastd_cipher_t **cipher_conf, const char *name, const char *impl) {
+/** Configures a cipher to use a specific implementation */
+bool fastd_cipher_config(const char *name, const char *impl) {
size_t i;
for (i = 0; i < array_size(ciphers); i++) {
if (!strcmp(ciphers[i].name, name)) {
@@ -94,15 +90,13 @@ bool fastd_cipher_config(const fastd_cipher_t **cipher_conf, const char *name, c
}
const fastd_cipher_info_t* fastd_cipher_info_get_by_name(const char *name) {
- size_t i, j;
+ size_t i;
for (i = 0; i < array_size(ciphers); i++) {
if (strcmp(ciphers[i].name, name))
continue;
- for (j = 0; ciphers[i].impls[j].impl; j++) {
- if (cipher_available(ciphers[i].impls[j].impl))
- return ciphers[i].info;
- }
+ if (cipher_conf[i])
+ return ciphers[i].info;
break;
}
@@ -114,7 +108,7 @@ const fastd_cipher_t* fastd_cipher_get(const fastd_cipher_info_t *info) {
size_t i;
for (i = 0; i < array_size(ciphers); i++) {
if (ciphers[i].info == info)
- return conf.ciphers[i];
+ return cipher_conf[i];
}
return NULL;