src/libstrongswan/plugins/af_alg/Makefile
src/libstrongswan/plugins/ntru/Makefile
src/libstrongswan/plugins/bliss/Makefile
+ src/libstrongswan/plugins/bliss/tests/Makefile
src/libstrongswan/plugins/test_vectors/Makefile
src/libstrongswan/tests/Makefile
src/libhydra/Makefile
endif
endif
+if USE_BLISS
+ SUBDIRS += plugins/bliss
+if MONOLITHIC
+ libstrongswan_la_LIBADD += plugins/bliss/libstrongswan-bliss.la
+endif
+endif
+
if USE_TEST_VECTORS
SUBDIRS += plugins/test_vectors
if MONOLITHIC
SUBDIRS += .
endif
SUBDIRS += tests
-
if USE_BLISS
- SUBDIRS += plugins/bliss
-if MONOLITHIC
- libstrongswan_la_LIBADD += plugins/bliss/libstrongswan-bliss.la
+ SUBDIRS += plugins/bliss/tests
endif
-endif
-
-
-bliss_tests
bliss_huffman
bliss_huffman_code_1.c
bliss_huffman_code_3.c
$(PLUGIN_CFLAGS) \
@COVERAGE_CFLAGS@
-if MONOLITHIC
-noinst_LTLIBRARIES = libstrongswan-bliss.la
-else
-plugin_LTLIBRARIES = libstrongswan-bliss.la
-endif
-
-libstrongswan_bliss_la_SOURCES = \
- bliss_plugin.h bliss_plugin.c \
+# these file are also used by bliss_huffman
+noinst_LTLIBRARIES = libbliss-params.la
+libbliss_params_la_SOURCES = \
bliss_param_set.h bliss_param_set.c \
+ bliss_fft_params.h bliss_fft_params.c
+
+# these files are also used by the tests, we can't directly refer to them
+# because of the subdirectory, which would cause distclean to fail
+noinst_LTLIBRARIES += libbliss.la
+libbliss_la_SOURCES = \
bliss_private_key.h bliss_private_key.c \
bliss_public_key.h bliss_public_key.c \
bliss_signature.h bliss_signature.c \
bliss_utils.h bliss_utils.c \
bliss_bitpacker.h bliss_bitpacker.c \
bliss_fft.h bliss_fft.c \
- bliss_fft_params.h bliss_fft_params.c \
bliss_huffman_code.h bliss_huffman_code.c \
bliss_huffman_code_1.c bliss_huffman_code_3.c bliss_huffman_code_4.c \
bliss_sampler.h bliss_sampler.c
+libbliss_la_LIBADD = libbliss-params.la
+
+CLEANFILES = \
+ bliss_huffman_code_1.c bliss_huffman_code_3.c bliss_huffman_code_4.c
+
+if MONOLITHIC
+noinst_LTLIBRARIES += libstrongswan-bliss.la
+else
+plugin_LTLIBRARIES = libstrongswan-bliss.la
+endif
+
+libstrongswan_bliss_la_SOURCES = \
+ bliss_plugin.h bliss_plugin.c
libstrongswan_bliss_la_LDFLAGS = -module -avoid-version
+libstrongswan_bliss_la_LIBADD = libbliss.la
+
noinst_PROGRAMS = bliss_huffman
bliss_huffman_SOURCES = bliss_huffman.c
-bliss_huffman_LDADD = \
- $(top_builddir)/src/libstrongswan/libstrongswan.la -lm \
- bliss_param_set.o bliss_fft_params.o
+bliss_huffman_LDADD = -lm libbliss-params.la
bliss_huffman_code_1.c : bliss_huffman bliss_huffman_code.h
$(AM_V_GEN) \
- ./bliss_huffman 1 8 > $@
+ ./bliss_huffman 1 8 > $@ 2>/dev/null
bliss_huffman_code_3.c : bliss_huffman bliss_huffman_code.h
$(AM_V_GEN) \
- ./bliss_huffman 3 16 > $@
+ ./bliss_huffman 3 16 > $@ 2>/dev/null
bliss_huffman_code_4.c : bliss_huffman bliss_huffman_code.h
$(AM_V_GEN) \
- ./bliss_huffman 4 32 > $@
-
-TESTS = bliss_tests
-
-check_PROGRAMS = $(TESTS)
-
-bliss_tests_SOURCES = \
- suites/test_bliss_fft.c \
- suites/test_bliss_bitpacker.c \
- suites/test_bliss_sampler.c \
- suites/test_bliss_sign.c \
- bliss_fft_params.c \
- bliss_fft.c \
- bliss_private_key.c \
- bliss_public_key.c \
- bliss_param_set.c \
- bliss_sampler.c \
- bliss_signature.c \
- bliss_utils.c \
- bliss_bitpacker.c \
- bliss_tests.h bliss_tests.c
-
-bliss_tests_CFLAGS = \
- -I$(top_srcdir)/src/libstrongswan \
- -I$(top_srcdir)/src/libstrongswan/tests \
- -DPLUGINDIR=\""$(abs_top_builddir)/src/libstrongswan/plugins\"" \
- -DPLUGINS=\""${s_plugins}\"" \
- @COVERAGE_CFLAGS@
-
-bliss_tests_LDFLAGS = @COVERAGE_LDFLAGS@
-bliss_tests_LDADD = \
- $(top_builddir)/src/libstrongswan/libstrongswan.la \
- $(top_builddir)/src/libstrongswan/tests/libtest.la
+ ./bliss_huffman 4 32 > $@ 2>/dev/null
/*
+ * Copyright (C) 2014 Tobias Brunner
* Copyright (C) 2014 Andreas Steffen
* HSR Hochschule fuer Technik Rapperswil
*
typedef struct node_t node_t;
struct node_t {
+ node_t *next;
node_t *l;
node_t *r;
tuple_t *tuple;
printf(" * Copyright (C) 2014 Andreas Steffen\n");
printf(" * HSR Hochschule fuer Technik Rapperswil\n");
printf(" *\n");
- printf(" * Optimum Huffman code for %N signatures\n",
- bliss_param_set_id_names, bliss_type);
+ printf(" * Optimum Huffman code for BLISS-X signatures\n");
printf(" *\n");
printf(" * This file has been automatically generated by the"
" bliss_huffman utility\n");
free(node);
}
+static void remove_node(node_t *list, node_t **last, node_t *node)
+{
+ node_t *current, *prev;
+
+ for (current = list->next, prev = list; current;
+ prev = current, current = current->next)
+ {
+ if (current == node)
+ {
+ prev->next = current->next;
+ if (*last == current)
+ {
+ *last = prev->next ?: prev;
+ }
+ break;
+ }
+ }
+}
+
/**
* Generate a Huffman code for the optimum encoding of BLISS signatures
*/
bliss_param_set_t *set;
int dx, bliss_type, depth = 1, groups, groups_left, pairs = 1;
int i_max = 9, k_max = 8, index_max = (2*k_max - 1) * i_max;
- int i, i_top, k, k_top;
+ int i, i_top, k, k_top;
uint16_t index;
double p, p_z1[i_max], p_z2[k_max], x_z1[i_max], x_z2[k_max];
double t, x, x0, p_sum, entropy = 0, erf_i, erf_k, erf_0 = 0;
tuple_t *tuple, *tuples[index_max];
node_t *node, *node_l, *node_r, *nodes = NULL;
- linked_list_t *node_list;
- enumerator_t *enumerator;
+ node_t *node_list, *node_last;
if (argc < 2)
{
fprintf(stderr, "%d code pairs with constant length\n\n", pairs);
groups_left = groups = pairs >> 1;
- library_init(NULL, "bliss_huffman");
- lib->plugins->load(lib->plugins, "bliss");
- atexit(library_deinit);
-
bliss_type = atoi(argv[1]);
set = bliss_param_set_get_by_id(bliss_type);
if (!set)
fprintf(stderr, "bliss type %d unsupported\n");
exit(1);
}
-
+
t = 1/(sqrt(2) * set->sigma);
/* Probability distribution for z1 */
for (k = 0; k < k_top; k++)
{
-
+
erf_k = erf(t*x) / 2;
p_z2[k] = (k == 0) ? 2*erf_k : erf_k - erf_0;
p_sum += (k == 0) ? p_z2[k] : 2*p_z2[k];
{
p_z2[k] /= p_sum;
}
-
+
/* Print the probability distribution for z2 */
fprintf(stderr, " k p_z2[k] dx = %d\n", dx);
for (k = 1 - k_top; k < k_top; k++)
{
-
+
fprintf(stderr, "%2d %18.16f ",k, p_z2[abs(k)]);
if (k < 0)
{
fprintf(stderr, "%7.1f ..%7.1f\n", -x_z2[-k], -x_z2[-k-1]);
- }
+ }
else if (k == 0)
{
fprintf(stderr, "%7.1f ..%7.1f\n", -x_z2[k], x_z2[k]);
else
{
fprintf(stderr, "%7.1f ..%7.1f\n", x_z2[k-1], x_z2[k]);
- }
+ }
}
fprintf(stderr, "\n");
/* Compute probabilities of tuples (z1, z2) */
- node_list =linked_list_create();
+ INIT(node_list);
+ node_last = node_list;
fprintf(stderr, "(i, k) p\n");
p_sum =0;
index = 0;
p_sum += p;
entropy += -log(p) * p;
- tuple = malloc_thing(tuple_t);
- node = malloc_thing(node_t);
- tuple->z1 = i;
- tuple->z2 = k;
- tuple->index = index;
+ INIT(tuple,
+ .z1 = i,
+ .z2 = k,
+ .index = index,
+ );
tuples[index++] = tuple;
- node->p = p;
- node->tuple = tuple;
- node->depth = 0;
- node->r = NULL;
- node->l = NULL;
- node_list->insert_last(node_list, node);
+
+ INIT(node,
+ .p = p,
+ .tuple = tuple,
+ );
+ node_last->next = node;
+ node_last = node;
}
}
entropy /= log(2);
p_sum, entropy, (int)(512 * entropy));
/* Build Huffman tree */
- while (node_list->get_count(node_list) > 1)
+ while (node_list->next != node_last)
{
node_r = node_l = NULL;
- enumerator = node_list->create_enumerator(node_list);
- while (enumerator->enumerate(enumerator, &node))
+ for (node = node_list->next; node; node = node->next)
{
if (pairs > 0)
{
node_l = node;
}
}
- enumerator->destroy(enumerator);
-
- node = malloc_thing(node_t);
- node->l = node_l;
- node->r = node_r;
- node->p = node_l->p + node_r->p;
- node->depth = 1 + max(node_l->depth, node_r->depth);
- node->tuple = NULL;
+ INIT(node,
+ .l = node_l,
+ .r = node_r,
+ .p = node_l->p + node_r->p,
+ .depth = 1 + max(node_l->depth, node_r->depth),
+ .tuple = NULL,
+ );
print_node(node_r);
print_node(node_l);
fprintf(stderr, " %18.16f", node->p);
- node_list->remove(node_list, node_l, NULL);
- node_list->remove(node_list, node_r, NULL);
- node_list->insert_last(node_list, node);
-
+ remove_node(node_list, &node_last, node_l);
+ remove_node(node_list, &node_last, node_r);
+ node_last->next = node;
+ node_last = node;
if (pairs > 0)
{
depth++;
}
}
- fprintf(stderr, " %3d\n\n", node_list->get_count(node_list));
+ fprintf(stderr, "\n\n");
}
- node_list->remove_first(node_list, (void**)&nodes);
- node_list->destroy(node_list);
+
+ nodes = node_list->next;
write_code_tables(bliss_type, i_top, k_top, nodes, tuples);
destroy_node(nodes);
+ destroy_node(node_list);
exit(0);
}
+++ /dev/null
-/*
- * Copyright (C) 2014 Andreas Steffen
- * HSR 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 <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * 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_runner.h>
-
-#include <library.h>
-
-/* declare test suite constructors */
-#define TEST_SUITE(x) test_suite_t* x();
-#include "bliss_tests.h"
-#undef TEST_SUITE
-
-static test_configuration_t tests[] = {
-#define TEST_SUITE(x) \
- { .suite = x, },
-#include "bliss_tests.h"
- { .suite = NULL, }
-};
-
-static bool test_runner_init(bool init)
-{
- if (init)
- {
- char *plugins, *plugindir;
-
- plugins = lib->settings->get_str(lib->settings,
- "tests.load", PLUGINS);
- plugindir = lib->settings->get_str(lib->settings,
- "tests.plugindir", PLUGINDIR);
- plugin_loader_add_plugindirs(plugindir, plugins);
- if (!lib->plugins->load(lib->plugins, plugins))
- {
- return FALSE;
- }
- }
- else
- {
- lib->processor->set_threads(lib->processor, 0);
- lib->processor->cancel(lib->processor);
- lib->plugins->unload(lib->plugins);
- }
- return TRUE;
-}
-
-int main(int argc, char *argv[])
-{
- return test_runner_run("bliss", tests, test_runner_init);
-}
+++ /dev/null
-/*
- * Copyright (C) 2014 Andreas Steffen
- * HSR 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 <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * 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.
- */
-
-TEST_SUITE(bliss_fft_suite_create)
-TEST_SUITE(bliss_bitpacker_suite_create)
-TEST_SUITE(bliss_sampler_suite_create)
-TEST_SUITE(bliss_sign_suite_create)
-
+++ /dev/null
-/*
- * Copyright (C) 2014 Andreas Steffen
- * HSR 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 <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * 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_suite.h"
-
-#include <bliss_bitpacker.h>
-
-static uint32_t bits[] = { 0, 1, 2, 3, 4, 7, 1, 14, 2, 29, 3, 28, 67};
-
-static chunk_t packed_bits = chunk_from_chars(0x6e, 0x71, 0xe1, 0x74,
- 0x37, 0x21, 0x80);
-
-START_TEST(test_bliss_sign_bitpacker_write)
-{
- chunk_t buf;
- bliss_bitpacker_t *packer;
- int i;
-
- packer = bliss_bitpacker_create(49);
-
- ck_assert(!packer->write_bits(packer, 0, 33));
-
- for (i = 0; i < countof(bits); i++)
- {
- ck_assert(packer->write_bits(packer, bits[i], 1 + i/2));
- }
- buf = packer->extract_buf(packer);
- ck_assert_int_eq(packer->get_bits(packer), 49);
- ck_assert_chunk_eq(buf, packed_bits);
-
- packer->destroy(packer);
- free(buf.ptr);
-}
-END_TEST
-
-START_TEST(test_bliss_sign_bitpacker_read)
-{
- uint32_t value;
- bliss_bitpacker_t *packer;
- int i;
-
- packer = bliss_bitpacker_create_from_data(packed_bits);
-
- ck_assert(!packer->read_bits(packer, &value, 33));
-
- for (i = 0; i < countof(bits); i++)
- {
- ck_assert(packer->read_bits(packer, &value, 1 + i/2));
- ck_assert_int_eq(value, bits[i]);
- }
- ck_assert(!packer->read_bits(packer, &value, 32));
-
- packer->destroy(packer);
-}
-END_TEST
-
-START_TEST(test_bliss_sign_bitpacker_fail)
-{
- bliss_bitpacker_t *packer;
- uint32_t value;
-
- packer = bliss_bitpacker_create(32);
- ck_assert(!packer->write_bits(packer, 0, 33));
- ck_assert( packer->write_bits(packer, 0x7f2a3b01, 31));
- ck_assert(!packer->write_bits(packer, 3, 2));
- packer->destroy(packer);
-
- packer = bliss_bitpacker_create_from_data(
- chunk_from_chars(0x7f, 0x2a, 0x3b, 0x01));
- ck_assert(!packer->read_bits(packer, &value, 33));
- ck_assert( packer->read_bits(packer, &value, 31));
- ck_assert(!packer->read_bits(packer, &value, 2));
- packer->destroy(packer);
-}
-END_TEST
-
-Suite *bliss_bitpacker_suite_create()
-{
- Suite *s;
- TCase *tc;
-
- s = suite_create("bliss_bitpacker");
-
- tc = tcase_create("bitpacker_write");
- tcase_add_test(tc, test_bliss_sign_bitpacker_write);
- suite_add_tcase(s, tc);
-
- tc = tcase_create("bitpacker_read");
- tcase_add_test(tc, test_bliss_sign_bitpacker_read);
- suite_add_tcase(s, tc);
-
- tc = tcase_create("bitpacker_fail");
- tcase_add_test(tc, test_bliss_sign_bitpacker_fail);
- suite_add_tcase(s, tc);
-
- return s;
-}
+++ /dev/null
-/*
- * Copyright (C) 2014 Andreas Steffen
- * HSR 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 <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * 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_suite.h"
-
-#include <bliss_fft.h>
-
-static bliss_fft_params_t *fft_params[] = {
- &bliss_fft_17_8,
- &bliss_fft_12289_512
-};
-
-START_TEST(test_bliss_fft_impulse)
-{
- bliss_fft_t *fft;
- uint16_t n = fft_params[_i]->n;
- uint32_t x[n], X[n];
- int i;
-
- for (i = 0; i < n; i++)
- {
- x[i] = 0;
- }
- x[0] = 1;
-
- fft = bliss_fft_create(fft_params[_i]);
- fft->transform(fft, x, X, FALSE);
-
- for (i = 0; i < n; i++)
- {
- ck_assert(X[i] == 1);
- }
- fft->transform(fft, X, x, TRUE);
-
- for (i = 0; i < n; i++)
- {
- ck_assert(x[i] == (i == 0));
- }
- fft->destroy(fft);
-}
-END_TEST
-
-START_TEST(test_bliss_fft_wrap)
-{
- bliss_fft_t *fft;
- uint16_t n = fft_params[_i]->n;
- uint16_t q = fft_params[_i]->q;
- uint32_t x[n],y[n], X[n], Y[n];
- int i, j;
-
- for (i = 0; i < n; i++)
- {
- x[i] = i;
- y[i] = 0;
- }
- fft = bliss_fft_create(fft_params[_i]);
- ck_assert(fft->get_size(fft) == n);
- ck_assert(fft->get_modulus(fft) == q);
- fft->transform(fft, x, X, FALSE);
-
- for (j = 0; j < n; j++)
- {
- y[j] = 1;
- fft->transform(fft, y, Y, FALSE);
-
- for (i = 0; i < n; i++)
- {
- Y[i] = (X[i] * Y[i]) % q;
- }
- fft->transform(fft, Y, Y, TRUE);
-
- for (i = 0; i < n; i++)
- {
- ck_assert(Y[i] == ( i < j ? q - n - i + j : i - j));
- }
- y[j] = 0;
- }
- fft->destroy(fft);
-}
-END_TEST
-
-Suite *bliss_fft_suite_create()
-{
- Suite *s;
- TCase *tc;
-
- s = suite_create("bliss_fft");
-
- tc = tcase_create("impulse");
- tcase_add_loop_test(tc, test_bliss_fft_impulse, 0, countof(fft_params));
- suite_add_tcase(s, tc);
-
- tc = tcase_create("negative_wrap");
- tcase_add_loop_test(tc, test_bliss_fft_wrap, 0, countof(fft_params));
- suite_add_tcase(s, tc);
-
- return s;
-}
+++ /dev/null
-/*
- * Copyright (C) 2014 Andreas Steffen
- * HSR 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 <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * 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_suite.h"
-
-#include <bliss_sampler.h>
-
-static u_int key_size[] = { 1, 3, 4};
-
-START_TEST(test_bliss_sampler_gaussian)
-{
- bliss_sampler_t *sampler;
- bliss_param_set_t *set;
- int i, k, count;
- uint32_t hist[8], sign[3];
- int32_t z;
- hash_algorithm_t alg;
- size_t seed_len;
- chunk_t seed;
-
- set = bliss_param_set_get_by_id(key_size[_i]);
- alg = HASH_SHA256;
- seed_len = 32;
- count = 10000000;
-
- seed = chunk_alloc(seed_len);
- memset(seed.ptr, 0xcc, seed_len);
-
- for (k = 0; k < 3; k++)
- {
- sign[k] = 0;
- }
- for (k = 0; k < 8; k++)
- {
- hist[k] = 0;
- }
-
- sampler = bliss_sampler_create(alg, seed, set);
- for (i = 0; i < count; i++)
- {
- ck_assert(sampler->gaussian(sampler, &z));
- if (z == 0)
- {
- sign[1]++;
- hist[0]++;
- }
- else if (z > 0)
- {
- sign[2]++;
- hist[z/256]++;
- }
- else
- {
- sign[0]++;
- hist[(-z)/256]++;
- }
- }
- sampler->destroy(sampler);
- free(seed.ptr);
-
- DBG1(DBG_LIB, "histogram");
- for (k = 0; k < 8; k++)
- {
- DBG1(DBG_LIB, "%d %7d", k, hist[k]);
- }
- DBG1(DBG_LIB, "- %7d", sign[0]);
- DBG1(DBG_LIB, "0 %7d", sign[1]);
- DBG1(DBG_LIB, "+ %7d", sign[2]);
-}
-END_TEST
-
-Suite *bliss_sampler_suite_create()
-{
- Suite *s;
- TCase *tc;
-
- s = suite_create("bliss_sampler");
-
- tc = tcase_create("sampler_gaussian");
- tcase_set_timeout(tc, 10);
- tcase_add_loop_test(tc, test_bliss_sampler_gaussian, 0, countof(key_size));
- suite_add_tcase(s, tc);
-
- return s;
-}
+++ /dev/null
-/*
- * Copyright (C) 2014 Andreas Steffen
- * HSR 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 <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * 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_suite.h"
-
-#include <bliss_private_key.h>
-#include <bliss_public_key.h>
-
-static u_int key_type[] = { 1, 3, 4 };
-
-START_TEST(test_bliss_sign_all)
-{
- private_key_t *privkey;
- public_key_t *pubkey;
- chunk_t msg, signature;
- int verify_count = 1000;
-
- msg = chunk_from_str("Hello Dolly!");
- privkey = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_BLISS,
- BUILD_KEY_SIZE, key_type[_i], BUILD_END);
- ck_assert(privkey);
-
- pubkey = privkey->get_public_key(privkey);
- ck_assert(pubkey);
-
- while (verify_count--)
- {
- ck_assert(privkey->sign(privkey, SIGN_BLISS_WITH_SHA512, msg,
- &signature));
- ck_assert(pubkey->verify(pubkey, SIGN_BLISS_WITH_SHA512, msg,
- signature));
- free(signature.ptr);
- }
- privkey->destroy(privkey);
- pubkey->destroy(pubkey);
-}
-END_TEST
-
-Suite *bliss_sign_suite_create()
-{
- Suite *s;
- TCase *tc;
-
- s = suite_create("bliss_sign");
-
- tc = tcase_create("all");
- test_case_set_timeout(tc, 30);
- tcase_add_loop_test(tc, test_bliss_sign_all, 0, countof(key_type));
- suite_add_tcase(s, tc);
-
- return s;
-}
--- /dev/null
+bliss_tests
--- /dev/null
+TESTS = bliss_tests
+
+check_PROGRAMS = $(TESTS)
+
+bliss_tests_SOURCES = \
+ suites/test_bliss_fft.c \
+ suites/test_bliss_bitpacker.c \
+ suites/test_bliss_sampler.c \
+ suites/test_bliss_sign.c \
+ bliss_tests.h bliss_tests.c
+
+bliss_tests_CFLAGS = \
+ -I$(top_srcdir)/src/libstrongswan \
+ -I$(top_srcdir)/src/libstrongswan/tests \
+ -I$(top_srcdir)/src/libstrongswan/plugins/bliss \
+ -DPLUGINDIR=\""$(abs_top_builddir)/src/libstrongswan/plugins\"" \
+ -DPLUGINS=\""${s_plugins}\"" \
+ @COVERAGE_CFLAGS@
+
+bliss_tests_LDFLAGS = @COVERAGE_LDFLAGS@
+bliss_tests_LDADD = \
+ $(top_builddir)/src/libstrongswan/libstrongswan.la \
+ $(top_builddir)/src/libstrongswan/tests/libtest.la \
+ ../libbliss.la
--- /dev/null
+/*
+ * Copyright (C) 2014 Andreas Steffen
+ * HSR 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 <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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_runner.h>
+
+#include <library.h>
+
+/* declare test suite constructors */
+#define TEST_SUITE(x) test_suite_t* x();
+#include "bliss_tests.h"
+#undef TEST_SUITE
+
+static test_configuration_t tests[] = {
+#define TEST_SUITE(x) \
+ { .suite = x, },
+#include "bliss_tests.h"
+ { .suite = NULL, }
+};
+
+static bool test_runner_init(bool init)
+{
+ if (init)
+ {
+ char *plugins, *plugindir;
+
+ plugins = lib->settings->get_str(lib->settings,
+ "tests.load", PLUGINS);
+ plugindir = lib->settings->get_str(lib->settings,
+ "tests.plugindir", PLUGINDIR);
+ plugin_loader_add_plugindirs(plugindir, plugins);
+ if (!lib->plugins->load(lib->plugins, plugins))
+ {
+ return FALSE;
+ }
+ }
+ else
+ {
+ lib->processor->set_threads(lib->processor, 0);
+ lib->processor->cancel(lib->processor);
+ lib->plugins->unload(lib->plugins);
+ }
+ return TRUE;
+}
+
+int main(int argc, char *argv[])
+{
+ return test_runner_run("bliss", tests, test_runner_init);
+}
--- /dev/null
+/*
+ * Copyright (C) 2014 Andreas Steffen
+ * HSR 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 <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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.
+ */
+
+TEST_SUITE(bliss_fft_suite_create)
+TEST_SUITE(bliss_bitpacker_suite_create)
+TEST_SUITE(bliss_sampler_suite_create)
+TEST_SUITE(bliss_sign_suite_create)
+
--- /dev/null
+/*
+ * Copyright (C) 2014 Andreas Steffen
+ * HSR 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 <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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_suite.h"
+
+#include <bliss_bitpacker.h>
+
+static uint32_t bits[] = { 0, 1, 2, 3, 4, 7, 1, 14, 2, 29, 3, 28, 67};
+
+static chunk_t packed_bits = chunk_from_chars(0x6e, 0x71, 0xe1, 0x74,
+ 0x37, 0x21, 0x80);
+
+START_TEST(test_bliss_sign_bitpacker_write)
+{
+ chunk_t buf;
+ bliss_bitpacker_t *packer;
+ int i;
+
+ packer = bliss_bitpacker_create(49);
+
+ ck_assert(!packer->write_bits(packer, 0, 33));
+
+ for (i = 0; i < countof(bits); i++)
+ {
+ ck_assert(packer->write_bits(packer, bits[i], 1 + i/2));
+ }
+ buf = packer->extract_buf(packer);
+ ck_assert_int_eq(packer->get_bits(packer), 49);
+ ck_assert_chunk_eq(buf, packed_bits);
+
+ packer->destroy(packer);
+ free(buf.ptr);
+}
+END_TEST
+
+START_TEST(test_bliss_sign_bitpacker_read)
+{
+ uint32_t value;
+ bliss_bitpacker_t *packer;
+ int i;
+
+ packer = bliss_bitpacker_create_from_data(packed_bits);
+
+ ck_assert(!packer->read_bits(packer, &value, 33));
+
+ for (i = 0; i < countof(bits); i++)
+ {
+ ck_assert(packer->read_bits(packer, &value, 1 + i/2));
+ ck_assert_int_eq(value, bits[i]);
+ }
+ ck_assert(!packer->read_bits(packer, &value, 32));
+
+ packer->destroy(packer);
+}
+END_TEST
+
+START_TEST(test_bliss_sign_bitpacker_fail)
+{
+ bliss_bitpacker_t *packer;
+ uint32_t value;
+
+ packer = bliss_bitpacker_create(32);
+ ck_assert(!packer->write_bits(packer, 0, 33));
+ ck_assert( packer->write_bits(packer, 0x7f2a3b01, 31));
+ ck_assert(!packer->write_bits(packer, 3, 2));
+ packer->destroy(packer);
+
+ packer = bliss_bitpacker_create_from_data(
+ chunk_from_chars(0x7f, 0x2a, 0x3b, 0x01));
+ ck_assert(!packer->read_bits(packer, &value, 33));
+ ck_assert( packer->read_bits(packer, &value, 31));
+ ck_assert(!packer->read_bits(packer, &value, 2));
+ packer->destroy(packer);
+}
+END_TEST
+
+Suite *bliss_bitpacker_suite_create()
+{
+ Suite *s;
+ TCase *tc;
+
+ s = suite_create("bliss_bitpacker");
+
+ tc = tcase_create("bitpacker_write");
+ tcase_add_test(tc, test_bliss_sign_bitpacker_write);
+ suite_add_tcase(s, tc);
+
+ tc = tcase_create("bitpacker_read");
+ tcase_add_test(tc, test_bliss_sign_bitpacker_read);
+ suite_add_tcase(s, tc);
+
+ tc = tcase_create("bitpacker_fail");
+ tcase_add_test(tc, test_bliss_sign_bitpacker_fail);
+ suite_add_tcase(s, tc);
+
+ return s;
+}
--- /dev/null
+/*
+ * Copyright (C) 2014 Andreas Steffen
+ * HSR 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 <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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_suite.h"
+
+#include <bliss_fft.h>
+
+static bliss_fft_params_t *fft_params[] = {
+ &bliss_fft_17_8,
+ &bliss_fft_12289_512
+};
+
+START_TEST(test_bliss_fft_impulse)
+{
+ bliss_fft_t *fft;
+ uint16_t n = fft_params[_i]->n;
+ uint32_t x[n], X[n];
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ x[i] = 0;
+ }
+ x[0] = 1;
+
+ fft = bliss_fft_create(fft_params[_i]);
+ fft->transform(fft, x, X, FALSE);
+
+ for (i = 0; i < n; i++)
+ {
+ ck_assert(X[i] == 1);
+ }
+ fft->transform(fft, X, x, TRUE);
+
+ for (i = 0; i < n; i++)
+ {
+ ck_assert(x[i] == (i == 0));
+ }
+ fft->destroy(fft);
+}
+END_TEST
+
+START_TEST(test_bliss_fft_wrap)
+{
+ bliss_fft_t *fft;
+ uint16_t n = fft_params[_i]->n;
+ uint16_t q = fft_params[_i]->q;
+ uint32_t x[n],y[n], X[n], Y[n];
+ int i, j;
+
+ for (i = 0; i < n; i++)
+ {
+ x[i] = i;
+ y[i] = 0;
+ }
+ fft = bliss_fft_create(fft_params[_i]);
+ ck_assert(fft->get_size(fft) == n);
+ ck_assert(fft->get_modulus(fft) == q);
+ fft->transform(fft, x, X, FALSE);
+
+ for (j = 0; j < n; j++)
+ {
+ y[j] = 1;
+ fft->transform(fft, y, Y, FALSE);
+
+ for (i = 0; i < n; i++)
+ {
+ Y[i] = (X[i] * Y[i]) % q;
+ }
+ fft->transform(fft, Y, Y, TRUE);
+
+ for (i = 0; i < n; i++)
+ {
+ ck_assert(Y[i] == ( i < j ? q - n - i + j : i - j));
+ }
+ y[j] = 0;
+ }
+ fft->destroy(fft);
+}
+END_TEST
+
+Suite *bliss_fft_suite_create()
+{
+ Suite *s;
+ TCase *tc;
+
+ s = suite_create("bliss_fft");
+
+ tc = tcase_create("impulse");
+ tcase_add_loop_test(tc, test_bliss_fft_impulse, 0, countof(fft_params));
+ suite_add_tcase(s, tc);
+
+ tc = tcase_create("negative_wrap");
+ tcase_add_loop_test(tc, test_bliss_fft_wrap, 0, countof(fft_params));
+ suite_add_tcase(s, tc);
+
+ return s;
+}
--- /dev/null
+/*
+ * Copyright (C) 2014 Andreas Steffen
+ * HSR 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 <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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_suite.h"
+
+#include <bliss_sampler.h>
+
+static u_int key_size[] = { 1, 3, 4};
+
+START_TEST(test_bliss_sampler_gaussian)
+{
+ bliss_sampler_t *sampler;
+ bliss_param_set_t *set;
+ int i, k, count;
+ uint32_t hist[8], sign[3];
+ int32_t z;
+ hash_algorithm_t alg;
+ size_t seed_len;
+ chunk_t seed;
+
+ set = bliss_param_set_get_by_id(key_size[_i]);
+ alg = HASH_SHA256;
+ seed_len = 32;
+ count = 10000000;
+
+ seed = chunk_alloc(seed_len);
+ memset(seed.ptr, 0xcc, seed_len);
+
+ for (k = 0; k < 3; k++)
+ {
+ sign[k] = 0;
+ }
+ for (k = 0; k < 8; k++)
+ {
+ hist[k] = 0;
+ }
+
+ sampler = bliss_sampler_create(alg, seed, set);
+ for (i = 0; i < count; i++)
+ {
+ ck_assert(sampler->gaussian(sampler, &z));
+ if (z == 0)
+ {
+ sign[1]++;
+ hist[0]++;
+ }
+ else if (z > 0)
+ {
+ sign[2]++;
+ hist[z/256]++;
+ }
+ else
+ {
+ sign[0]++;
+ hist[(-z)/256]++;
+ }
+ }
+ sampler->destroy(sampler);
+ free(seed.ptr);
+
+ DBG1(DBG_LIB, "histogram");
+ for (k = 0; k < 8; k++)
+ {
+ DBG1(DBG_LIB, "%d %7d", k, hist[k]);
+ }
+ DBG1(DBG_LIB, "- %7d", sign[0]);
+ DBG1(DBG_LIB, "0 %7d", sign[1]);
+ DBG1(DBG_LIB, "+ %7d", sign[2]);
+}
+END_TEST
+
+Suite *bliss_sampler_suite_create()
+{
+ Suite *s;
+ TCase *tc;
+
+ s = suite_create("bliss_sampler");
+
+ tc = tcase_create("sampler_gaussian");
+ tcase_set_timeout(tc, 10);
+ tcase_add_loop_test(tc, test_bliss_sampler_gaussian, 0, countof(key_size));
+ suite_add_tcase(s, tc);
+
+ return s;
+}
--- /dev/null
+/*
+ * Copyright (C) 2014 Andreas Steffen
+ * HSR 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 <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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_suite.h"
+
+#include <bliss_private_key.h>
+#include <bliss_public_key.h>
+
+static u_int key_type[] = { 1, 3, 4 };
+
+START_TEST(test_bliss_sign_all)
+{
+ private_key_t *privkey;
+ public_key_t *pubkey;
+ chunk_t msg, signature;
+ int verify_count = 1000;
+
+ msg = chunk_from_str("Hello Dolly!");
+ privkey = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_BLISS,
+ BUILD_KEY_SIZE, key_type[_i], BUILD_END);
+ ck_assert(privkey);
+
+ pubkey = privkey->get_public_key(privkey);
+ ck_assert(pubkey);
+
+ while (verify_count--)
+ {
+ ck_assert(privkey->sign(privkey, SIGN_BLISS_WITH_SHA512, msg,
+ &signature));
+ ck_assert(pubkey->verify(pubkey, SIGN_BLISS_WITH_SHA512, msg,
+ signature));
+ free(signature.ptr);
+ }
+ privkey->destroy(privkey);
+ pubkey->destroy(pubkey);
+}
+END_TEST
+
+Suite *bliss_sign_suite_create()
+{
+ Suite *s;
+ TCase *tc;
+
+ s = suite_create("bliss_sign");
+
+ tc = tcase_create("all");
+ test_case_set_timeout(tc, 30);
+ tcase_add_loop_test(tc, test_bliss_sign_all, 0, countof(key_type));
+ suite_add_tcase(s, tc);
+
+ return s;
+}