diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-11-25 23:18:11 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-11-25 23:18:11 +0100 |
commit | c62a0f592c49b41d393fae580ce9f1293ee7a16d (patch) | |
tree | 6d8ef6b7c93fdcaa0fd1bcd590dba531ef8b5140 /src/crypto/mac | |
parent | 60c2c11de820687887a643344fc1b0a91fd45226 (diff) | |
download | fastd-c62a0f592c49b41d393fae580ce9f1293ee7a16d.tar fastd-c62a0f592c49b41d393fae580ce9f1293ee7a16d.zip |
Move crypto algorithm information out of implementation
Diffstat (limited to 'src/crypto/mac')
-rw-r--r-- | src/crypto/mac/CMakeLists.txt | 35 | ||||
-rw-r--r-- | src/crypto/mac/ghash/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/crypto/mac/ghash/builtin/ghash_builtin.c | 3 | ||||
-rw-r--r-- | src/crypto/mac/ghash/ghash.c | 32 | ||||
-rw-r--r-- | src/crypto/mac/macs.c.in | 40 |
5 files changed, 78 insertions, 34 deletions
diff --git a/src/crypto/mac/CMakeLists.txt b/src/crypto/mac/CMakeLists.txt index ca3b71d..22bc95e 100644 --- a/src/crypto/mac/CMakeLists.txt +++ b/src/crypto/mac/CMakeLists.txt @@ -1,26 +1,25 @@ add_library(macs STATIC "${CMAKE_CURRENT_BINARY_DIR}/macs.c") -function(fastd_mac name) - string(REPLACE - _ name_ "${name}") - string(TOUPPER "${name_}" NAME) +macro(fastd_mac name) + fastd_module(mac enabled "MAC" ${name} ${ARGN}) - set(WITH_MAC_${NAME} TRUE CACHE BOOL "Include the ${name} MAC") - - if(WITH_MAC_${NAME}) + if(${enabled}) set_property(GLOBAL APPEND PROPERTY FASTD_MACS ${name}) - endif(WITH_MAC_${NAME}) -endfunction(fastd_mac) + endif(${enabled}) +endmacro(fastd_mac) macro(fastd_mac_impl mac name) string(REPLACE - _ mac_ "${mac}") string(TOUPPER "${mac_}" MAC) - fastd_module(mac enabled "MAC implementation" "${mac} ${name}" ${ARGN}) + if(WITH_MAC_${MAC}) + fastd_module(mac enabled "MAC implementation" "${mac} ${name}" ${ARGN}) - if(${enabled}) - set_property(GLOBAL APPEND PROPERTY FASTD_MAC_${MAC}_IMPLS ${name}) - endif(${enabled}) + if(${enabled}) + set_property(TARGET "mac_${mac_}" APPEND PROPERTY FASTD_MAC_IMPLS ${name}) + endif(${enabled}) + endif(WITH_MAC_${MAC}) endmacro(fastd_mac_impl) macro(fastd_mac_impl_include_directories mac name) @@ -48,16 +47,18 @@ foreach(mac ${MACS}) string(REPLACE - _ mac_ "${mac}") string(TOUPPER "${mac_}" MAC) - set(MAC_LIST "${MAC_LIST}\n{\"${mac}\", mac_${mac_}_impls},") - set(MAC_IMPLS "${MAC_IMPLS}\nstatic const fastd_mac_t *const mac_${mac_}_impls[] = {") + set(MAC_DEFINITIONS "${MAC_DEFINITIONS}\nextern const fastd_mac_info_t fastd_mac_info_${mac_};") + set(MAC_LIST "${MAC_LIST}\n{\"${mac}\", &fastd_mac_info_${mac_}, mac_${mac_}_impls},") + set(MAC_IMPLS "${MAC_IMPLS}\nstatic const fastd_mac_impl_t mac_${mac_}_impls[] = {") + - get_property(IMPLS GLOBAL PROPERTY FASTD_MAC_${MAC}_IMPLS) + get_property(IMPLS TARGET "mac_${mac_}" PROPERTY FASTD_MAC_IMPLS) foreach(impl ${IMPLS}) set(MAC_DEFINITIONS "${MAC_DEFINITIONS}\nextern const fastd_mac_t fastd_mac_${mac_}_${impl};") - set(MAC_IMPLS "${MAC_IMPLS}&fastd_mac_${mac_}_${impl}, ") + set(MAC_IMPLS "${MAC_IMPLS}{\"${impl}\", &fastd_mac_${mac_}_${impl}}, ") endforeach(impl) - set(MAC_IMPLS "${MAC_IMPLS}NULL};") + set(MAC_IMPLS "${MAC_IMPLS}{NULL, NULL}};") endforeach(mac) get_property(LIBS TARGET macs PROPERTY FASTD_LINK_LIBRARIES) diff --git a/src/crypto/mac/ghash/CMakeLists.txt b/src/crypto/mac/ghash/CMakeLists.txt index 7d44b8a..1fd04a4 100644 --- a/src/crypto/mac/ghash/CMakeLists.txt +++ b/src/crypto/mac/ghash/CMakeLists.txt @@ -1,2 +1,2 @@ -fastd_mac(ghash) +fastd_mac(ghash ghash.c) add_subdirectory(builtin) diff --git a/src/crypto/mac/ghash/builtin/ghash_builtin.c b/src/crypto/mac/ghash/builtin/ghash_builtin.c index 0af30ed..cc47427 100644 --- a/src/crypto/mac/ghash/builtin/ghash_builtin.c +++ b/src/crypto/mac/ghash/builtin/ghash_builtin.c @@ -132,9 +132,6 @@ static void ghash_free(fastd_context_t *ctx UNUSED, fastd_mac_context_t *mctx UN } const fastd_mac_t fastd_mac_ghash_builtin = { - .name = "builtin", - .key_length = sizeof(fastd_block128_t), - .initialize = ghash_initialize, .init_state = ghash_init_state, diff --git a/src/crypto/mac/ghash/ghash.c b/src/crypto/mac/ghash/ghash.c new file mode 100644 index 0000000..6c165a4 --- /dev/null +++ b/src/crypto/mac/ghash/ghash.c @@ -0,0 +1,32 @@ +/* + Copyright (c) 2012-2013, Matthias Schiffer <mschiffer@universe-factory.net> + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "../../../crypto.h" + + +const fastd_mac_info_t fastd_mac_info_ghash = { + .key_length = 16, +}; diff --git a/src/crypto/mac/macs.c.in b/src/crypto/mac/macs.c.in index 43031ee..9952396 100644 --- a/src/crypto/mac/macs.c.in +++ b/src/crypto/mac/macs.c.in @@ -30,14 +30,20 @@ @MAC_DEFINITIONS@ -typedef struct mac_impl_list { +typedef struct fastd_mac_impl { const char *name; - const fastd_mac_t *const *impls; -} mac_impl_list_t; + const fastd_mac_t *impl; +} fastd_mac_impl_t; + +typedef struct mac_entry { + const char *name; + const fastd_mac_info_t *info; + const fastd_mac_impl_t *impls; +} mac_entry_t; @MAC_IMPLS@ -static const mac_impl_list_t macs[] = { @MAC_LIST@ +static const mac_entry_t macs[] = { @MAC_LIST@ }; @@ -46,7 +52,7 @@ const fastd_mac_t** fastd_mac_config_alloc(void) { size_t i; for (i = 0; i < array_size(macs); i++) - mac_conf[i] = macs[i].impls[0]; + mac_conf[i] = macs[i].impls[0].impl; return mac_conf; } @@ -60,9 +66,9 @@ bool fastd_mac_config(const fastd_mac_t **mac_conf, const char *name, const char for (i = 0; i < array_size(macs); i++) { if (!strcmp(macs[i].name, name)) { size_t j; - for (j = 0; macs[i].impls[j]; j++) { - if (!strcmp(macs[i].impls[j]->name, impl)) { - mac_conf[i] = macs[i].impls[j]; + for (j = 0; macs[i].impls[j].impl; j++) { + if (!strcmp(macs[i].impls[j].name, impl)) { + mac_conf[i] = macs[i].impls[j].impl; return true; } } @@ -92,20 +98,28 @@ void fastd_mac_free(fastd_context_t *ctx) { free(ctx->mac_contexts); } -bool fastd_mac_available(const char *name) { +const fastd_mac_info_t* fastd_mac_info_get_by_name(const char *name) { size_t i; for (i = 0; i < array_size(macs); i++) { - if (!strcmp(macs[i].name, name)) - return macs[i].impls[0]; + if (strcmp(macs[i].name, name)) + continue; + + if (!macs[i].impls[0].impl) + continue; + + return macs[i].info; } - return false; + return NULL; } -const fastd_mac_t* fastd_mac_get_by_name(fastd_context_t *ctx, const char *name, const fastd_mac_context_t **cctx) { +const fastd_mac_t* fastd_mac_get_by_name(fastd_context_t *ctx, const char *name, const fastd_mac_info_t **info, const fastd_mac_context_t **cctx) { size_t i; for (i = 0; i < array_size(macs); i++) { if (!strcmp(macs[i].name, name)) { + if (info) + *info = macs[i].info; + if (cctx) *cctx = ctx->mac_contexts[i]; |