From: Tobias Brunner Date: Fri, 31 Oct 2014 14:32:43 +0000 (+0100) Subject: blowfish: Register proposal keyword parser to support variable key lengths X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=008482d883ea119363eba2af3ed58f8b49329adb;p=thirdparty%2Fstrongswan.git blowfish: Register proposal keyword parser to support variable key lengths --- diff --git a/src/libstrongswan/plugins/blowfish/blowfish_plugin.c b/src/libstrongswan/plugins/blowfish/blowfish_plugin.c index 7494c52c34..f26d28e2c6 100644 --- a/src/libstrongswan/plugins/blowfish/blowfish_plugin.c +++ b/src/libstrongswan/plugins/blowfish/blowfish_plugin.c @@ -1,4 +1,5 @@ /* + * Copyright (C) 2014 Tobias Brunner * Copyright (C) 2009 Andreas Steffen * Copyright (C) 2008 Martin Willi * Hochschule fuer Technik Rapperswil @@ -17,6 +18,7 @@ #include "blowfish_plugin.h" #include +#include #include "blowfish_crypter.h" typedef struct private_blowfish_plugin_t private_blowfish_plugin_t; @@ -32,6 +34,12 @@ struct private_blowfish_plugin_t { blowfish_plugin_t public; }; +/** + * proposal tokens for variable key lengths + */ +static hashtable_t *tokens; + + METHOD(plugin_t, get_name, char*, private_blowfish_plugin_t *this) { @@ -52,9 +60,53 @@ METHOD(plugin_t, get_features, int, METHOD(plugin_t, destroy, void, private_blowfish_plugin_t *this) { + enumerator_t *enumerator; + proposal_token_t *token; + char *name; + + enumerator = tokens->create_enumerator(tokens); + while (enumerator->enumerate(enumerator, &name, &token)) + { + free(name); + free(token); + } + enumerator->destroy(enumerator); + tokens->destroy(tokens); free(this); } +/** + * Parse blowfish for key lengths other than 128, 192 and 256. + */ +static proposal_token_t *blowfish_keyword(const char *algname) +{ + proposal_token_t *token; + int keylen; + + if (!strcasepfx(algname, "blowfish")) + { + return NULL; + } + token = tokens->get(tokens, algname); + if (token) + { + return token; + } + keylen = atoi(algname + strlen("blowfish")); + if (keylen < 40 || keylen > 448) + { + return NULL; + } + INIT(token, + .name = strdup(algname), + .type = ENCRYPTION_ALGORITHM, + .algorithm = ENCR_BLOWFISH, + .keysize = keylen, + ); + tokens->put(tokens, token->name, token); + return token; +} + /* * see header file */ @@ -72,5 +124,8 @@ plugin_t *blowfish_plugin_create() }, ); + tokens = hashtable_create(hashtable_hash_str, hashtable_equals_str, 4); + lib->proposal->register_algname_parser(lib->proposal, blowfish_keyword); + return &this->public.plugin; }