$(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);
}