diff --git a/configure.in b/configure.in index 63f7baaf9..438a24b49 100644 --- a/configure.in +++ b/configure.in @@ -325,6 +325,14 @@ AC_ARG_ENABLE( xcbc=true ) +AC_ARG_ENABLE( + [test-vectors], + AS_HELP_STRING([--enable-test-vectprs],[enable plugin providing crypto test vectors (default is NO).]), + [if test x$enableval = xyes; then + test_vectors=true + fi] +) + AC_ARG_ENABLE( [mysql], AS_HELP_STRING([--enable-mysql],[enable MySQL database support (default is NO). Requires libmysqlclient_r.]), @@ -1048,6 +1056,10 @@ dnl ====================================== libstrongswan_plugins= pluto_plugins= +if test x$test_vectors = xtrue; then + libstrongswan_plugins=${libstrongswan_plugins}" test-vectors" + pluto_plugins=${pluto_plugins}" test-vectors" +fi if test x$curl = xtrue; then libstrongswan_plugins=${libstrongswan_plugins}" curl" pluto_plugins=${pluto_plugins}" curl" @@ -1144,6 +1156,7 @@ dnl ========================= dnl libstrongswan plugins dnl ===================== +AM_CONDITIONAL(USE_TEST_VECTORS, test x$test_vectors = xtrue) AM_CONDITIONAL(USE_CURL, test x$curl = xtrue) AM_CONDITIONAL(USE_LDAP, test x$ldap = xtrue) AM_CONDITIONAL(USE_AES, test x$aes = xtrue) @@ -1264,6 +1277,7 @@ AC_OUTPUT( src/libstrongswan/plugins/openssl/Makefile src/libstrongswan/plugins/gcrypt/Makefile src/libstrongswan/plugins/agent/Makefile + src/libstrongswan/plugins/test_vectors/Makefile src/libstrongswan/fips/Makefile src/libfreeswan/Makefile src/pluto/Makefile diff --git a/src/libstrongswan/Makefile.am b/src/libstrongswan/Makefile.am index 681434e4c..a3f8fcef0 100644 --- a/src/libstrongswan/Makefile.am +++ b/src/libstrongswan/Makefile.am @@ -209,6 +209,10 @@ if USE_AGENT SUBDIRS += plugins/agent endif +if USE_TEST_VECTORS + SUBDIRS += plugins/test_vectors +endif + if USE_INTEGRITY_TEST SUBDIRS += fips endif diff --git a/src/libstrongswan/plugins/test_vectors/Makefile.am b/src/libstrongswan/plugins/test_vectors/Makefile.am new file mode 100644 index 000000000..62db7ff9b --- /dev/null +++ b/src/libstrongswan/plugins/test_vectors/Makefile.am @@ -0,0 +1,11 @@ + +INCLUDES = -I$(top_srcdir)/src/libstrongswan + +AM_CFLAGS = -rdynamic + +plugin_LTLIBRARIES = libstrongswan-test-vectors.la + +libstrongswan_test_vectors_la_SOURCES = \ + test_vectors_plugin.h test_vectors_plugin.c +libstrongswan_test_vectors_la_LDFLAGS = -module + diff --git a/src/libstrongswan/plugins/test_vectors/test_vectors.h b/src/libstrongswan/plugins/test_vectors/test_vectors.h new file mode 100644 index 000000000..6256ec52f --- /dev/null +++ b/src/libstrongswan/plugins/test_vectors/test_vectors.h @@ -0,0 +1,15 @@ +/* + * Copyright (C) 2009 Martin Willi + * Hochschule fuer Technik Rapperswil + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See . + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + diff --git a/src/libstrongswan/plugins/test_vectors/test_vectors_plugin.c b/src/libstrongswan/plugins/test_vectors/test_vectors_plugin.c new file mode 100644 index 000000000..b96dc0c9a --- /dev/null +++ b/src/libstrongswan/plugins/test_vectors/test_vectors_plugin.c @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2009 Martin Willi + * Hochschule fuer Technik Rapperswil + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See . + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "test_vectors_plugin.h" + +#include +#include + +/* define symbols of all test vectors */ +#define TEST_VECTOR_CRYPTER(x) crypter_test_vector_t x; +#define TEST_VECTOR_SIGNER(x) signer_test_vector_t x; +#define TEST_VECTOR_HASHER(x) hasher_test_vector_t x; +#define TEST_VECTOR_PRF(x) prf_test_vector_t x; +#define TEST_VECTOR_RNG(x) rng_test_vector_t x; + +#include "test_vectors.h" + +#undef TEST_VECTOR_CRYPTER +#undef TEST_VECTOR_SIGNER +#undef TEST_VECTOR_HASHER +#undef TEST_VECTOR_PRF +#undef TEST_VECTOR_RNG + +#define TEST_VECTOR_CRYPTER(x) +#define TEST_VECTOR_SIGNER(x) +#define TEST_VECTOR_HASHER(x) +#define TEST_VECTOR_PRF(x) +#define TEST_VECTOR_RNG(x) + +/* create test vector arrays */ +#undef TEST_VECTOR_CRYPTER +#define TEST_VECTOR_CRYPTER(x) &x, +static crypter_test_vector_t *crypter[] = { +#include "test_vectors.h" +}; +#undef TEST_VECTOR_CRYPTER +#define TEST_VECTOR_CRYPTER(x) + +#undef TEST_VECTOR_SIGNER +#define TEST_VECTOR_SIGNER(x) &x, +static signer_test_vector_t *signer[] = { +#include "test_vectors.h" +}; +#undef TEST_VECTOR_SIGNER +#define TEST_VECTOR_SIGNER(x) + +#undef TEST_VECTOR_HASHER +#define TEST_VECTOR_HASHER(x) &x, +static hasher_test_vector_t *hasher[] = { +#include "test_vectors.h" +}; +#undef TEST_VECTOR_HASHER +#define TEST_VECTOR_HASHER(x) + +#undef TEST_VECTOR_PRF +#define TEST_VECTOR_PRF(x) &x, +static prf_test_vector_t *prf[] = { +#include "test_vectors.h" +}; +#undef TEST_VECTOR_PRF +#define TEST_VECTOR_PRF(x) + +#undef TEST_VECTOR_RNG +#define TEST_VECTOR_RNG(x) &x, +static rng_test_vector_t *rng[] = { +#include "test_vectors.h" +}; +#undef TEST_VECTOR_RNG +#define TEST_VECTOR_RNG(x) + +typedef struct private_test_vectors_plugin_t private_test_vectors_plugin_t; + +/** + * private data of test_vectors_plugin + */ +struct private_test_vectors_plugin_t { + + /** + * public functions + */ + test_vectors_plugin_t public; +}; + +/** + * Implementation of test_vectors_plugin_t.test_vectorstroy + */ +static void destroy(private_test_vectors_plugin_t *this) +{ + free(this); +} + +/* + * see header file + */ +plugin_t *plugin_create() +{ + private_test_vectors_plugin_t *this = malloc_thing(private_test_vectors_plugin_t); + int i; + + this->public.plugin.destroy = (void(*)(plugin_t*))destroy; + + for (i = 0; i < countof(crypter); i++) + { + lib->crypto->add_test_vector(lib->crypto, + ENCRYPTION_ALGORITHM, crypter[i]); + } + for (i = 0; i < countof(signer); i++) + { + lib->crypto->add_test_vector(lib->crypto, + INTEGRITY_ALGORITHM, signer[i]); + } + for (i = 0; i < countof(hasher); i++) + { + lib->crypto->add_test_vector(lib->crypto, + HASH_ALGORITHM, hasher[i]); + } + for (i = 0; i < countof(prf); i++) + { + lib->crypto->add_test_vector(lib->crypto, + PSEUDO_RANDOM_FUNCTION, prf[i]); + } + for (i = 0; i < countof(rng); i++) + { + lib->crypto->add_test_vector(lib->crypto, + RANDOM_NUMBER_GENERATOR, rng[i]); + } + + return &this->public.plugin; +} + diff --git a/src/libstrongswan/plugins/test_vectors/test_vectors_plugin.h b/src/libstrongswan/plugins/test_vectors/test_vectors_plugin.h new file mode 100644 index 000000000..9cb959c88 --- /dev/null +++ b/src/libstrongswan/plugins/test_vectors/test_vectors_plugin.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2009 Martin Willi + * Hochschule fuer Technik Rapperswil + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See . + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +/** + * @defgroup test_vectors_p test_vectors + * @ingroup plugins + * + * @defgroup test_vectors_plugin test_vectors_plugin + * @{ @ingroup test_vectors_p + */ + +#ifndef TEST_VECTORS_PLUGIN_H_ +#define TEST_VECTORS_PLUGIN_H_ + +#include + +typedef struct test_vectors_plugin_t test_vectors_plugin_t; + +/** + * Plugin providing various crypto test vectors. + */ +struct test_vectors_plugin_t { + + /** + * implements plugin interface + */ + plugin_t plugin; +}; + +/** + * Create a test_vectors_plugin instance. + */ +plugin_t *plugin_create(); + +#endif /** TEST_VECTORS_PLUGIN_H_ @}*/