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 | |
parent | 60c2c11de820687887a643344fc1b0a91fd45226 (diff) | |
download | fastd-c62a0f592c49b41d393fae580ce9f1293ee7a16d.tar fastd-c62a0f592c49b41d393fae580ce9f1293ee7a16d.zip |
Move crypto algorithm information out of implementation
Diffstat (limited to 'src/crypto')
22 files changed, 293 insertions, 89 deletions
diff --git a/src/crypto/cipher/CMakeLists.txt b/src/crypto/cipher/CMakeLists.txt index b538227..e32b697 100644 --- a/src/crypto/cipher/CMakeLists.txt +++ b/src/crypto/cipher/CMakeLists.txt @@ -1,26 +1,25 @@ add_library(ciphers STATIC "${CMAKE_CURRENT_BINARY_DIR}/ciphers.c") -function(fastd_cipher name) - string(REPLACE - _ name_ "${name}") - string(TOUPPER "${name_}" NAME) +macro(fastd_cipher name) + fastd_module(cipher enabled "cipher" ${name} ${ARGN}) - set(WITH_CIPHER_${NAME} TRUE CACHE BOOL "Include the ${name} cipher") - - if(WITH_CIPHER_${NAME}) + if(${enabled}) set_property(GLOBAL APPEND PROPERTY FASTD_CIPHERS ${name}) - endif(WITH_CIPHER_${NAME}) -endfunction(fastd_cipher) + endif(${enabled}) +endmacro(fastd_cipher) macro(fastd_cipher_impl cipher name) string(REPLACE - _ cipher_ "${cipher}") string(TOUPPER "${cipher_}" CIPHER) - fastd_module(cipher enabled "cipher implementation" "${cipher} ${name}" ${ARGN}) + if(WITH_CIPHER_${CIPHER}) + fastd_module(cipher enabled "cipher implementation" "${cipher} ${name}" ${ARGN}) - if(${enabled}) - set_property(GLOBAL APPEND PROPERTY FASTD_CIPHER_${CIPHER}_IMPLS ${name}) - endif(${enabled}) + if(${enabled}) + set_property(TARGET "cipher_${cipher_}" APPEND PROPERTY FASTD_CIPHER_IMPLS ${name}) + endif(${enabled}) + endif(WITH_CIPHER_${CIPHER}) endmacro(fastd_cipher_impl) macro(fastd_cipher_impl_include_directories cipher name) @@ -52,16 +51,18 @@ foreach(cipher ${CIPHERS}) string(REPLACE - _ cipher_ "${cipher}") string(TOUPPER "${cipher_}" CIPHER) - set(CIPHER_LIST "${CIPHER_LIST}\n{\"${cipher}\", cipher_${cipher_}_impls},") - set(CIPHER_IMPLS "${CIPHER_IMPLS}\nstatic const fastd_cipher_t *const cipher_${cipher_}_impls[] = {") + set(CIPHER_DEFINITIONS "${CIPHER_DEFINITIONS}\nextern const fastd_cipher_info_t fastd_cipher_info_${cipher_};") + set(CIPHER_LIST "${CIPHER_LIST}\n{\"${cipher}\", &fastd_cipher_info_${cipher_}, cipher_${cipher_}_impls},") + set(CIPHER_IMPLS "${CIPHER_IMPLS}\nstatic const fastd_cipher_impl_t cipher_${cipher_}_impls[] = {") + - get_property(IMPLS GLOBAL PROPERTY FASTD_CIPHER_${CIPHER}_IMPLS) + get_property(IMPLS TARGET "cipher_${cipher_}" PROPERTY FASTD_CIPHER_IMPLS) foreach(impl ${IMPLS}) set(CIPHER_DEFINITIONS "${CIPHER_DEFINITIONS}\nextern const fastd_cipher_t fastd_cipher_${cipher_}_${impl};") - set(CIPHER_IMPLS "${CIPHER_IMPLS}&fastd_cipher_${cipher_}_${impl}, ") + set(CIPHER_IMPLS "${CIPHER_IMPLS}{\"${impl}\", &fastd_cipher_${cipher_}_${impl}}, ") endforeach(impl) - set(CIPHER_IMPLS "${CIPHER_IMPLS}NULL};") + set(CIPHER_IMPLS "${CIPHER_IMPLS}{NULL, NULL}};") endforeach(cipher) get_property(LIBS TARGET ciphers PROPERTY FASTD_LINK_LIBRARIES) diff --git a/src/crypto/cipher/aes128_ctr/CMakeLists.txt b/src/crypto/cipher/aes128_ctr/CMakeLists.txt index 16eeeab..27b507b 100644 --- a/src/crypto/cipher/aes128_ctr/CMakeLists.txt +++ b/src/crypto/cipher/aes128_ctr/CMakeLists.txt @@ -1,2 +1,2 @@ -fastd_cipher(aes128-ctr) +fastd_cipher(aes128-ctr aes128_ctr.c) add_subdirectory(nacl) diff --git a/src/crypto/cipher/aes128_ctr/aes128_ctr.c b/src/crypto/cipher/aes128_ctr/aes128_ctr.c new file mode 100644 index 0000000..b228602 --- /dev/null +++ b/src/crypto/cipher/aes128_ctr/aes128_ctr.c @@ -0,0 +1,33 @@ +/* + 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_cipher_info_t fastd_cipher_info_aes128_ctr = { + .key_length = 16, + .iv_length = 16, +}; diff --git a/src/crypto/cipher/aes128_ctr/nacl/cipher_aes128_ctr_nacl.c b/src/crypto/cipher/aes128_ctr/nacl/cipher_aes128_ctr_nacl.c index a520732..e5f6379 100644 --- a/src/crypto/cipher/aes128_ctr/nacl/cipher_aes128_ctr_nacl.c +++ b/src/crypto/cipher/aes128_ctr/nacl/cipher_aes128_ctr_nacl.c @@ -67,10 +67,6 @@ static void aes128_ctr_free(fastd_context_t *ctx UNUSED, fastd_cipher_context_t } const fastd_cipher_t fastd_cipher_aes128_ctr_nacl = { - .name = "nacl", - .key_length = 16, - .iv_length = 16, - .initialize = aes128_ctr_initialize, .init_state = aes128_ctr_init_state, diff --git a/src/crypto/cipher/blowfish_ctr/CMakeLists.txt b/src/crypto/cipher/blowfish_ctr/CMakeLists.txt index 56d283f..8cabb57 100644 --- a/src/crypto/cipher/blowfish_ctr/CMakeLists.txt +++ b/src/crypto/cipher/blowfish_ctr/CMakeLists.txt @@ -1,2 +1,2 @@ -fastd_cipher(blowfish-ctr) +fastd_cipher(blowfish-ctr blowfish_ctr.c) add_subdirectory(builtin) diff --git a/src/crypto/cipher/blowfish_ctr/blowfish_ctr.c b/src/crypto/cipher/blowfish_ctr/blowfish_ctr.c new file mode 100644 index 0000000..1e8010b --- /dev/null +++ b/src/crypto/cipher/blowfish_ctr/blowfish_ctr.c @@ -0,0 +1,33 @@ +/* + 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_cipher_info_t fastd_cipher_info_blowfish_ctr = { + .key_length = 56, + .iv_length = 8, +}; diff --git a/src/crypto/cipher/blowfish_ctr/builtin/blowfish_ctr.c b/src/crypto/cipher/blowfish_ctr/builtin/blowfish_ctr.c index 0ca8d2d..f3424b9 100644 --- a/src/crypto/cipher/blowfish_ctr/builtin/blowfish_ctr.c +++ b/src/crypto/cipher/blowfish_ctr/builtin/blowfish_ctr.c @@ -274,10 +274,6 @@ static void blowfish_ctr_free(fastd_context_t *ctx UNUSED, fastd_cipher_context_ } const fastd_cipher_t fastd_cipher_blowfish_ctr_builtin = { - .name = "builtin", - .key_length = 56, - .iv_length = 8, - .initialize = blowfish_ctr_initialize, .init_state = blowfish_ctr_init_state, diff --git a/src/crypto/cipher/ciphers.c.in b/src/crypto/cipher/ciphers.c.in index c912e60..508196e 100644 --- a/src/crypto/cipher/ciphers.c.in +++ b/src/crypto/cipher/ciphers.c.in @@ -30,14 +30,20 @@ @CIPHER_DEFINITIONS@ -typedef struct cipher_impl_list { +typedef struct fastd_cipher_impl { const char *name; - const fastd_cipher_t *const *impls; -} cipher_impl_list_t; + const fastd_cipher_t *impl; +} fastd_cipher_impl_t; + +typedef struct cipher_entry { + const char *name; + const fastd_cipher_info_t *info; + const fastd_cipher_impl_t *impls; +} cipher_entry_t; @CIPHER_IMPLS@ -static const cipher_impl_list_t ciphers[] = { @CIPHER_LIST@ +static const cipher_entry_t ciphers[] = { @CIPHER_LIST@ }; @@ -46,7 +52,7 @@ const fastd_cipher_t** fastd_cipher_config_alloc(void) { size_t i; for (i = 0; i < array_size(ciphers); i++) - cipher_conf[i] = ciphers[i].impls[0]; + cipher_conf[i] = ciphers[i].impls[0].impl; return cipher_conf; } @@ -60,9 +66,9 @@ bool fastd_cipher_config(const fastd_cipher_t **cipher_conf, const char *name, c for (i = 0; i < array_size(ciphers); i++) { if (!strcmp(ciphers[i].name, name)) { size_t j; - for (j = 0; ciphers[i].impls[j]; j++) { - if (!strcmp(ciphers[i].impls[j]->name, impl)) { - cipher_conf[i] = ciphers[i].impls[j]; + for (j = 0; ciphers[i].impls[j].impl; j++) { + if (!strcmp(ciphers[i].impls[j].name, impl)) { + cipher_conf[i] = ciphers[i].impls[j].impl; return true; } } @@ -92,20 +98,28 @@ void fastd_cipher_free(fastd_context_t *ctx) { free(ctx->cipher_contexts); } -bool fastd_cipher_available(const char *name) { +const fastd_cipher_info_t* fastd_cipher_info_get_by_name(const char *name) { size_t i; for (i = 0; i < array_size(ciphers); i++) { - if (!strcmp(ciphers[i].name, name)) - return ciphers[i].impls[0]; + if (strcmp(ciphers[i].name, name)) + continue; + + if (!ciphers[i].impls[0].impl) + continue; + + return ciphers[i].info; } - return false; + return NULL; } -const fastd_cipher_t* fastd_cipher_get_by_name(fastd_context_t *ctx, const char *name, const fastd_cipher_context_t **cctx) { +const fastd_cipher_t* fastd_cipher_get_by_name(fastd_context_t *ctx, const char *name, const fastd_cipher_info_t **info, const fastd_cipher_context_t **cctx) { size_t i; for (i = 0; i < array_size(ciphers); i++) { if (!strcmp(ciphers[i].name, name)) { + if (info) + *info = ciphers[i].info; + if (cctx) *cctx = ctx->cipher_contexts[i]; diff --git a/src/crypto/cipher/null/CMakeLists.txt b/src/crypto/cipher/null/CMakeLists.txt index e835d73..a05fdc5 100644 --- a/src/crypto/cipher/null/CMakeLists.txt +++ b/src/crypto/cipher/null/CMakeLists.txt @@ -1,2 +1,2 @@ -fastd_cipher(null) +fastd_cipher(null null.c) add_subdirectory(memcpy) diff --git a/src/crypto/cipher/null/memcpy/null_memcpy.c b/src/crypto/cipher/null/memcpy/null_memcpy.c index 45ad297..1784ac9 100644 --- a/src/crypto/cipher/null/memcpy/null_memcpy.c +++ b/src/crypto/cipher/null/memcpy/null_memcpy.c @@ -47,10 +47,6 @@ static void null_free(fastd_context_t *ctx UNUSED, fastd_cipher_context_t *cctx } const fastd_cipher_t fastd_cipher_null_memcpy = { - .name = "memcpy", - .key_length = 0, - .iv_length = 0, - .initialize = null_initialize, .init_state = null_init_state, diff --git a/src/crypto/cipher/null/null.c b/src/crypto/cipher/null/null.c new file mode 100644 index 0000000..07994f7 --- /dev/null +++ b/src/crypto/cipher/null/null.c @@ -0,0 +1,33 @@ +/* + 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_cipher_info_t fastd_cipher_info_null = { + .key_length = 0, + .iv_length = 0, +}; diff --git a/src/crypto/cipher/salsa20/CMakeLists.txt b/src/crypto/cipher/salsa20/CMakeLists.txt index 3d325dc..3d9654e 100644 --- a/src/crypto/cipher/salsa20/CMakeLists.txt +++ b/src/crypto/cipher/salsa20/CMakeLists.txt @@ -1,2 +1,2 @@ -fastd_cipher(salsa20) +fastd_cipher(salsa20 salsa20.c) add_subdirectory(nacl) diff --git a/src/crypto/cipher/salsa20/nacl/salsa20_nacl.c b/src/crypto/cipher/salsa20/nacl/salsa20_nacl.c index 93daad3..ddcc124 100644 --- a/src/crypto/cipher/salsa20/nacl/salsa20_nacl.c +++ b/src/crypto/cipher/salsa20/nacl/salsa20_nacl.c @@ -60,10 +60,6 @@ static void salsa20_free(fastd_context_t *ctx UNUSED, fastd_cipher_context_t *cc } const fastd_cipher_t fastd_cipher_salsa20_nacl = { - .name = "nacl", - .key_length = crypto_stream_salsa20_KEYBYTES, - .iv_length = crypto_stream_salsa20_NONCEBYTES, - .initialize = salsa20_initialize, .init_state = salsa20_init_state, diff --git a/src/crypto/cipher/salsa20/salsa20.c b/src/crypto/cipher/salsa20/salsa20.c new file mode 100644 index 0000000..bf6dc48 --- /dev/null +++ b/src/crypto/cipher/salsa20/salsa20.c @@ -0,0 +1,33 @@ +/* + 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_cipher_info_t fastd_cipher_info_salsa20 = { + .key_length = 32, + .iv_length = 8, +}; diff --git a/src/crypto/cipher/salsa2012/CMakeLists.txt b/src/crypto/cipher/salsa2012/CMakeLists.txt index 405ae9a..eb853e0 100644 --- a/src/crypto/cipher/salsa2012/CMakeLists.txt +++ b/src/crypto/cipher/salsa2012/CMakeLists.txt @@ -1,2 +1,2 @@ -fastd_cipher(salsa2012) +fastd_cipher(salsa2012 salsa2012.c) add_subdirectory(nacl) diff --git a/src/crypto/cipher/salsa2012/nacl/salsa2012_nacl.c b/src/crypto/cipher/salsa2012/nacl/salsa2012_nacl.c index 2703f0e..36985a6 100644 --- a/src/crypto/cipher/salsa2012/nacl/salsa2012_nacl.c +++ b/src/crypto/cipher/salsa2012/nacl/salsa2012_nacl.c @@ -60,10 +60,6 @@ static void salsa2012_free(fastd_context_t *ctx UNUSED, fastd_cipher_context_t * } const fastd_cipher_t fastd_cipher_salsa2012_nacl = { - .name = "nacl", - .key_length = crypto_stream_salsa2012_KEYBYTES, - .iv_length = crypto_stream_salsa2012_NONCEBYTES, - .initialize = salsa2012_initialize, .init_state = salsa2012_init_state, diff --git a/src/crypto/cipher/salsa2012/salsa2012.c b/src/crypto/cipher/salsa2012/salsa2012.c new file mode 100644 index 0000000..780702d --- /dev/null +++ b/src/crypto/cipher/salsa2012/salsa2012.c @@ -0,0 +1,33 @@ +/* + 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_cipher_info_t fastd_cipher_info_salsa2012 = { + .key_length = 32, + .iv_length = 8, +}; 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]; |