Merge branch 'newhope'

This commit is contained in:
Andreas Steffen
2016-08-10 16:23:04 +02:00
137 changed files with 6560 additions and 926 deletions
+8
View File
@@ -136,6 +136,7 @@ ARG_DISBL_SET([gmp], [disable GNU MP (libgmp) based crypto implementa
ARG_DISBL_SET([hmac], [disable HMAC crypto implementation plugin.])
ARG_ENABL_SET([md4], [enable MD4 software implementation plugin.])
ARG_DISBL_SET([md5], [disable MD5 software implementation plugin.])
ARG_ENABL_SET([newhope], [enable New Hope crypto plugin.])
ARG_DISBL_SET([nonce], [disable nonce generation plugin.])
ARG_ENABL_SET([ntru], [enables the NTRU crypto plugin.])
ARG_ENABL_SET([openssl], [enables the OpenSSL crypto plugin.])
@@ -1358,6 +1359,7 @@ ADD_PLUGIN([ctr], [s charon scripts nm cmd])
ADD_PLUGIN([ccm], [s charon scripts nm cmd])
ADD_PLUGIN([gcm], [s charon scripts nm cmd])
ADD_PLUGIN([ntru], [s charon scripts nm cmd])
ADD_PLUGIN([newhope], [s charon scripts nm cmd])
ADD_PLUGIN([bliss], [s charon pki scripts nm cmd])
ADD_PLUGIN([curl], [s charon scepclient pki scripts nm cmd])
ADD_PLUGIN([files], [s charon scepclient pki scripts nm cmd])
@@ -1515,6 +1517,7 @@ AM_CONDITIONAL(USE_CCM, test x$ccm = xtrue)
AM_CONDITIONAL(USE_GCM, test x$gcm = xtrue)
AM_CONDITIONAL(USE_AF_ALG, test x$af_alg = xtrue)
AM_CONDITIONAL(USE_NTRU, test x$ntru = xtrue)
AM_CONDITIONAL(USE_NEWHOPE, test x$newhope = xtrue)
AM_CONDITIONAL(USE_BLISS, test x$bliss = xtrue)
# charon plugins
@@ -1630,6 +1633,7 @@ AM_CONDITIONAL(USE_CONFTEST, test x$conftest = xtrue)
AM_CONDITIONAL(USE_LIBSTRONGSWAN, test x$charon = xtrue -o x$pki = xtrue -o x$scepclient = xtrue -o x$conftest = xtrue -o x$fast = xtrue -o x$imcv = xtrue -o x$nm = xtrue -o x$tkm = xtrue -o x$cmd = xtrue -o x$tls = xtrue -o x$tnc_tnccs = xtrue -o x$aikgen = xtrue -o x$aikpub2 = xtrue -o x$svc = xtrue -o x$systemd = xtrue)
AM_CONDITIONAL(USE_LIBCHARON, test x$charon = xtrue -o x$conftest = xtrue -o x$nm = xtrue -o x$tkm = xtrue -o x$cmd = xtrue -o x$svc = xtrue -o x$systemd = xtrue)
AM_CONDITIONAL(USE_LIBIPSEC, test x$libipsec = xtrue)
AM_CONDITIONAL(USE_LIBNTTFFT, test x$bliss = xtrue -o x$newhope = xtrue)
AM_CONDITIONAL(USE_LIBTNCIF, test x$tnc_tnccs = xtrue -o x$imcv = xtrue)
AM_CONDITIONAL(USE_LIBTNCCS, test x$tnc_tnccs = xtrue)
AM_CONDITIONAL(USE_LIBPTTLS, test x$tnc_tnccs = xtrue)
@@ -1722,6 +1726,8 @@ AC_CONFIG_FILES([
src/Makefile
src/include/Makefile
src/libstrongswan/Makefile
src/libstrongswan/math/libnttfft/Makefile
src/libstrongswan/math/libnttfft/tests/Makefile
src/libstrongswan/plugins/aes/Makefile
src/libstrongswan/plugins/cmac/Makefile
src/libstrongswan/plugins/des/Makefile
@@ -1775,6 +1781,8 @@ AC_CONFIG_FILES([
src/libstrongswan/plugins/ntru/Makefile
src/libstrongswan/plugins/bliss/Makefile
src/libstrongswan/plugins/bliss/tests/Makefile
src/libstrongswan/plugins/newhope/Makefile
src/libstrongswan/plugins/newhope/tests/Makefile
src/libstrongswan/plugins/test_vectors/Makefile
src/libstrongswan/tests/Makefile
src/libipsec/Makefile
+5
View File
@@ -48,6 +48,11 @@ if USE_RADIUS
libs += $(DESTDIR)$(ipseclibdir)/libradius.so
endif
if USE_LIBNTTFFT
deps += $(top_builddir)/src/libstrongswan/math/libnttfft/libnttfft.la
libs += $(DESTDIR)$(ipseclibdir)/libnttfft.so
endif
if USE_LIBPTTLS
deps += $(top_builddir)/src/libpttls/libpttls.la
libs += $(DESTDIR)$(ipseclibdir)/libpttls.so
+1
View File
@@ -842,6 +842,7 @@ static bool proposal_add_supported_ike(private_proposal_t *this, bool aead)
case NTRU_128_BIT:
case NTRU_192_BIT:
case NTRU_256_BIT:
case NH_128_BIT:
add_algorithm(this, DIFFIE_HELLMAN_GROUP, group, 0);
break;
default:
@@ -844,6 +844,7 @@ static void list_algs(FILE *out)
integrity_algorithm_t integrity;
hash_algorithm_t hash;
pseudo_random_function_t prf;
ext_out_function_t xof;
diffie_hellman_group_t group;
rng_quality_t quality;
const char *plugin_name;
@@ -891,6 +892,14 @@ static void list_algs(FILE *out)
print_alg(out, &len, pseudo_random_function_names, prf, plugin_name);
}
enumerator->destroy(enumerator);
fprintf(out, "\n xof: ");
len = 13;
enumerator = lib->crypto->create_xof_enumerator(lib->crypto);
while (enumerator->enumerate(enumerator, &xof, &plugin_name))
{
print_alg(out, &len, ext_out_function_names, xof, plugin_name);
}
enumerator->destroy(enumerator);
fprintf(out, "\n dh-group: ");
len = 13;
enumerator = lib->crypto->create_dh_enumerator(lib->crypto);
+10
View File
@@ -1072,6 +1072,7 @@ CALLBACK(get_algorithms, vici_message_t*,
integrity_algorithm_t integrity;
hash_algorithm_t hash;
pseudo_random_function_t prf;
ext_out_function_t xof;
diffie_hellman_group_t group;
rng_quality_t quality;
const char *plugin_name;
@@ -1123,6 +1124,15 @@ CALLBACK(get_algorithms, vici_message_t*,
enumerator->destroy(enumerator);
b->end_section(b);
b->begin_section(b, "xof");
enumerator = lib->crypto->create_xof_enumerator(lib->crypto);
while (enumerator->enumerate(enumerator, &xof, &plugin_name))
{
add_algorithm(b, ext_out_function_names, xof, plugin_name);
}
enumerator->destroy(enumerator);
b->end_section(b);
b->begin_section(b, "dh");
enumerator = lib->crypto->create_dh_enumerator(lib->crypto);
while (enumerator->enumerate(enumerator, &group, &plugin_name))
+31 -4
View File
@@ -15,6 +15,7 @@ crypto/diffie_hellman.c crypto/aead.c crypto/transform.c \
crypto/iv/iv_gen.c crypto/iv/iv_gen_rand.c crypto/iv/iv_gen_seq.c \
crypto/iv/iv_gen_null.c \
crypto/mgf1/mgf1.c crypto/mgf1/mgf1_bitspender.c \
crypto/xofs/xof.h crypto/xofs/xof.c \
credentials/credential_factory.c credentials/builder.c \
credentials/cred_encoding.c credentials/keys/private_key.c \
credentials/keys/public_key.c credentials/keys/shared_key.c \
@@ -220,16 +221,22 @@ $(srcdir)/crypto/proposal/proposal_keywords_static.c: $(srcdir)/crypto/proposal/
$(GPERF) -N proposal_get_token_static -m 10 -C -G -c -t -D < \
$(srcdir)/crypto/proposal/proposal_keywords_static.txt > $@
# build plugins with their own Makefile
#######################################
if MONOLITHIC
SUBDIRS =
else
SUBDIRS = .
endif
# build libnttfft used by some plugins
######################################
if USE_LIBNTTFFT
SUBDIRS += math/libnttfft
endif
# build plugins with their own Makefile
#######################################
if USE_AF_ALG
SUBDIRS += plugins/af_alg
if MONOLITHIC
@@ -594,6 +601,13 @@ if MONOLITHIC
endif
endif
if USE_NEWHOPE
SUBDIRS += plugins/newhope
if MONOLITHIC
libstrongswan_la_LIBADD += plugins/newhope/libstrongswan-newhope.la
endif
endif
if USE_TEST_VECTORS
SUBDIRS += plugins/test_vectors
if MONOLITHIC
@@ -604,7 +618,20 @@ endif
if MONOLITHIC
SUBDIRS += .
endif
# build unit tests
##################
SUBDIRS += tests
if USE_LIBNTTFFT
SUBDIRS += math/libnttfft/tests
endif
if USE_BLISS
SUBDIRS += plugins/bliss/tests
endif
if USE_NEWHOPE
SUBDIRS += plugins/newhope/tests
endif
+109 -1
View File
@@ -1,7 +1,8 @@
/*
* Copyright (C) 2013-2014 Tobias Brunner
* Copyright (C) 2008 Martin Willi
* Hochschule fuer Technik Rapperswil
* Copyright (C) 2016 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
@@ -51,6 +52,7 @@ struct entry_t {
signer_constructor_t create_signer;
hasher_constructor_t create_hasher;
prf_constructor_t create_prf;
xof_constructor_t create_xof;
rng_constructor_t create_rng;
nonce_gen_constructor_t create_nonce_gen;
dh_constructor_t create_dh;
@@ -95,6 +97,11 @@ struct private_crypto_factory_t {
*/
linked_list_t *prfs;
/**
* registered xofs, as entry_t
*/
linked_list_t *xofs;
/**
* registered rngs, as entry_t
*/
@@ -303,6 +310,38 @@ METHOD(crypto_factory_t, create_prf, prf_t*,
return prf;
}
METHOD(crypto_factory_t, create_xof, xof_t*,
private_crypto_factory_t *this, ext_out_function_t algo)
{
enumerator_t *enumerator;
entry_t *entry;
xof_t *xof = NULL;
this->lock->read_lock(this->lock);
enumerator = this->xofs->create_enumerator(this->xofs);
while (enumerator->enumerate(enumerator, &entry))
{
if (entry->algo == algo)
{
if (this->test_on_create &&
!this->tester->test_xof(this->tester, algo,
entry->create_xof, NULL,
default_plugin_name))
{
continue;
}
xof = entry->create_xof(algo);
if (xof)
{
break;
}
}
}
enumerator->destroy(enumerator);
this->lock->unlock(this->lock);
return xof;
}
METHOD(crypto_factory_t, create_rng, rng_t*,
private_crypto_factory_t *this, rng_quality_t quality)
{
@@ -633,6 +672,43 @@ METHOD(crypto_factory_t, remove_prf, void,
this->lock->unlock(this->lock);
}
METHOD(crypto_factory_t, add_xof, bool,
private_crypto_factory_t *this, ext_out_function_t algo,
const char *plugin_name, xof_constructor_t create)
{
u_int speed = 0;
if (!this->test_on_add ||
this->tester->test_xof(this->tester, algo, create,
this->bench ? &speed : NULL, plugin_name))
{
add_entry(this, this->xofs, algo, plugin_name, speed, create);
return TRUE;
}
this->test_failures++;
return FALSE;
}
METHOD(crypto_factory_t, remove_xof, void,
private_crypto_factory_t *this, xof_constructor_t create)
{
entry_t *entry;
enumerator_t *enumerator;
this->lock->write_lock(this->lock);
enumerator = this->xofs->create_enumerator(this->xofs);
while (enumerator->enumerate(enumerator, &entry))
{
if (entry->create_xof == create)
{
this->xofs->remove_at(this->xofs, enumerator);
free(entry);
}
}
enumerator->destroy(enumerator);
this->lock->unlock(this->lock);
}
METHOD(crypto_factory_t, add_rng, bool,
private_crypto_factory_t *this, rng_quality_t quality,
const char *plugin_name, rng_constructor_t create)
@@ -845,6 +921,23 @@ METHOD(crypto_factory_t, create_prf_enumerator, enumerator_t*,
return create_enumerator(this, this->prfs, prf_filter);
}
/**
* Filter function to enumerate algorithm, not entry
*/
static bool xof_filter(void *n, entry_t **entry, ext_out_function_t *algo,
void *i2, const char **plugin_name)
{
*algo = (*entry)->algo;
*plugin_name = (*entry)->plugin_name;
return TRUE;
}
METHOD(crypto_factory_t, create_xof_enumerator, enumerator_t*,
private_crypto_factory_t *this)
{
return create_enumerator(this, this->xofs, xof_filter);
}
/**
* Filter function to enumerate group, not entry
*/
@@ -909,6 +1002,8 @@ METHOD(crypto_factory_t, add_test_vector, void,
return this->tester->add_hasher_vector(this->tester, vector);
case PSEUDO_RANDOM_FUNCTION:
return this->tester->add_prf_vector(this->tester, vector);
case EXTENDED_OUTPUT_FUNCTION:
return this->tester->add_xof_vector(this->tester, vector);
case RANDOM_NUMBER_GENERATOR:
return this->tester->add_rng_vector(this->tester, vector);
case DIFFIE_HELLMAN_GROUP:
@@ -961,6 +1056,10 @@ METHOD(enumerator_t, verify_enumerate, bool,
*valid = this->tester->test_prf(this->tester, entry->algo,
entry->create_prf, NULL, entry->plugin_name);
break;
case EXTENDED_OUTPUT_FUNCTION:
*valid = this->tester->test_xof(this->tester, entry->algo,
entry->create_xof, NULL, entry->plugin_name);
break;
case RANDOM_NUMBER_GENERATOR:
*valid = this->tester->test_rng(this->tester, entry->algo,
entry->create_rng, NULL, entry->plugin_name);
@@ -1009,6 +1108,9 @@ METHOD(crypto_factory_t, create_verify_enumerator, enumerator_t*,
case PSEUDO_RANDOM_FUNCTION:
inner = this->prfs->create_enumerator(this->prfs);
break;
case EXTENDED_OUTPUT_FUNCTION:
inner = this->xofs->create_enumerator(this->xofs);
break;
case RANDOM_NUMBER_GENERATOR:
inner = this->rngs->create_enumerator(this->rngs);
break;
@@ -1040,6 +1142,7 @@ METHOD(crypto_factory_t, destroy, void,
this->signers->destroy(this->signers);
this->hashers->destroy(this->hashers);
this->prfs->destroy(this->prfs);
this->xofs->destroy(this->xofs);
this->rngs->destroy(this->rngs);
this->nonce_gens->destroy(this->nonce_gens);
this->dhs->destroy(this->dhs);
@@ -1062,6 +1165,7 @@ crypto_factory_t *crypto_factory_create()
.create_signer = _create_signer,
.create_hasher = _create_hasher,
.create_prf = _create_prf,
.create_xof = _create_xof,
.create_rng = _create_rng,
.create_nonce_gen = _create_nonce_gen,
.create_dh = _create_dh,
@@ -1075,6 +1179,8 @@ crypto_factory_t *crypto_factory_create()
.remove_hasher = _remove_hasher,
.add_prf = _add_prf,
.remove_prf = _remove_prf,
.add_xof = _add_xof,
.remove_xof = _remove_xof,
.add_rng = _add_rng,
.remove_rng = _remove_rng,
.add_nonce_gen = _add_nonce_gen,
@@ -1086,6 +1192,7 @@ crypto_factory_t *crypto_factory_create()
.create_signer_enumerator = _create_signer_enumerator,
.create_hasher_enumerator = _create_hasher_enumerator,
.create_prf_enumerator = _create_prf_enumerator,
.create_xof_enumerator = _create_xof_enumerator,
.create_dh_enumerator = _create_dh_enumerator,
.create_rng_enumerator = _create_rng_enumerator,
.create_nonce_gen_enumerator = _create_nonce_gen_enumerator,
@@ -1098,6 +1205,7 @@ crypto_factory_t *crypto_factory_create()
.signers = linked_list_create(),
.hashers = linked_list_create(),
.prfs = linked_list_create(),
.xofs = linked_list_create(),
.rngs = linked_list_create(),
.nonce_gens = linked_list_create(),
.dhs = linked_list_create(),
+41 -1
View File
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2008 Martin Willi
* Hochschule fuer Technik Rapperswil
* Copyright (C) 2016 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
@@ -31,6 +32,7 @@ typedef struct crypto_factory_t crypto_factory_t;
#include <crypto/hashers/hasher.h>
#include <crypto/prfs/prf.h>
#include <crypto/rngs/rng.h>
#include <crypto/xofs/xof.h>
#include <crypto/nonce_gen.h>
#include <crypto/diffie_hellman.h>
#include <crypto/transform.h>
@@ -62,6 +64,11 @@ typedef hasher_t* (*hasher_constructor_t)(hash_algorithm_t algo);
*/
typedef prf_t* (*prf_constructor_t)(pseudo_random_function_t algo);
/**
* Constructor function for pseudo random functions
*/
typedef xof_t* (*xof_constructor_t)(ext_out_function_t algo);
/**
* Constructor function for source of randomness
*/
@@ -132,6 +139,14 @@ struct crypto_factory_t {
*/
prf_t* (*create_prf)(crypto_factory_t *this, pseudo_random_function_t algo);
/**
* Create an extended output function instance.
*
* @param algo XOF algorithm to use
* @return xof_t instance, NULL if not supported
*/
xof_t* (*create_xof)(crypto_factory_t *this, ext_out_function_t algo);
/**
* Create a source of randomness.
*
@@ -252,6 +267,24 @@ struct crypto_factory_t {
*/
void (*remove_prf)(crypto_factory_t *this, prf_constructor_t create);
/**
* Register an xof constructor.
*
* @param algo algorithm to constructor
* @param plugin_name plugin that registered this algorithm
* @param create constructor function for that algorithm
* @return TRUE if registered, FALSE if test vector failed
*/
bool (*add_xof)(crypto_factory_t *this, ext_out_function_t algo,
const char *plugin_name, xof_constructor_t create);
/**
* Unregister an xof constructor.
*
* @param create constructor function to unregister
*/
void (*remove_xof)(crypto_factory_t *this, xof_constructor_t create);
/**
* Register a source of randomness.
*
@@ -341,6 +374,13 @@ struct crypto_factory_t {
*/
enumerator_t* (*create_prf_enumerator)(crypto_factory_t *this);
/**
* Create an enumerator over all registered XOFs.
*
* @return enumerator over ext_out_function_t, plugin
*/
enumerator_t* (*create_xof_enumerator)(crypto_factory_t *this);
/**
* Create an enumerator over all registered diffie hellman groups.
*
+155
View File
@@ -62,6 +62,11 @@ struct private_crypto_tester_t {
*/
linked_list_t *prf;
/**
* List of XOF test vectors
*/
linked_list_t *xof;
/**
* List of RNG test vectors
*/
@@ -1034,6 +1039,146 @@ failure:
return !failed;
}
/**
* Benchmark an XOF
*/
static u_int bench_xof(private_crypto_tester_t *this,
ext_out_function_t alg, xof_constructor_t create)
{
xof_t *xof;
xof = create(alg);
if (xof)
{
char seed[xof->get_seed_size(xof)];
char bytes[xof->get_block_size(xof)];
struct timespec start;
u_int runs;
memset(seed, 0x56, xof->get_seed_size(xof));
if (!xof->set_seed(xof, chunk_create(seed, xof->get_seed_size(xof))))
{
xof->destroy(xof);
return 0;
}
runs = 0;
start_timing(&start);
while (end_timing(&start) < this->bench_time)
{
if (xof->get_bytes(xof, xof->get_block_size(xof), bytes))
{
runs++;
}
}
xof->destroy(xof);
return runs;
}
return 0;
}
METHOD(crypto_tester_t, test_xof, bool,
private_crypto_tester_t *this, ext_out_function_t alg,
xof_constructor_t create, u_int *speed, const char *plugin_name)
{
enumerator_t *enumerator;
xof_test_vector_t *vector;
bool failed = FALSE;
u_int tested = 0;
enumerator = this->xof->create_enumerator(this->xof);
while (enumerator->enumerate(enumerator, &vector))
{
xof_t *xof;
chunk_t seed, out = chunk_empty;
if (vector->alg != alg)
{
continue;
}
tested++;
failed = TRUE;
xof = create(alg);
if (!xof)
{
DBG1(DBG_LIB, "disabled %N[%s]: creating instance failed",
ext_out_function_names, alg, plugin_name);
break;
}
seed = chunk_create(vector->seed, vector->len);
if (!xof->set_seed(xof, seed))
{
goto failure;
}
/* allocated bytes */
if (!xof->allocate_bytes(xof, vector->out_len, &out))
{
goto failure;
}
if (out.len != vector->out_len)
{
goto failure;
}
if (!memeq(vector->out, out.ptr, out.len))
{
goto failure;
}
/* bytes to existing buffer */
memset(out.ptr, 0, out.len);
if (!xof->set_seed(xof, seed))
{
goto failure;
}
if (!xof->get_bytes(xof, vector->out_len, out.ptr))
{
goto failure;
}
if (!memeq(vector->out, out.ptr, vector->out_len))
{
goto failure;
}
/* bytes to existing buffer, using append mode */
/* TODO */
failed = FALSE;
failure:
xof->destroy(xof);
chunk_free(&out);
if (failed)
{
DBG1(DBG_LIB, "disabled %N[%s]: %s test vector failed",
ext_out_function_names, alg, plugin_name, get_name(vector));
break;
}
}
enumerator->destroy(enumerator);
if (!tested)
{
DBG1(DBG_LIB, "%s %N[%s]: no test vectors found",
this->required ? "disabled" : "enabled ",
ext_out_function_names, alg, plugin_name);
return !this->required;
}
if (!failed)
{
if (speed)
{
*speed = bench_xof(this, alg, create);
DBG1(DBG_LIB, "enabled %N[%s]: passed %u test vectors, %d points",
ext_out_function_names, alg, plugin_name, tested, *speed);
}
else
{
DBG1(DBG_LIB, "enabled %N[%s]: passed %u test vectors",
ext_out_function_names, alg, plugin_name, tested);
}
}
return !failed;
}
/**
* Benchmark a RNG
*/
@@ -1338,6 +1483,12 @@ METHOD(crypto_tester_t, add_prf_vector, void,
this->prf->insert_last(this->prf, vector);
}
METHOD(crypto_tester_t, add_xof_vector, void,
private_crypto_tester_t *this, xof_test_vector_t *vector)
{
this->xof->insert_last(this->xof, vector);
}
METHOD(crypto_tester_t, add_rng_vector, void,
private_crypto_tester_t *this, rng_test_vector_t *vector)
{
@@ -1358,6 +1509,7 @@ METHOD(crypto_tester_t, destroy, void,
this->signer->destroy(this->signer);
this->hasher->destroy(this->hasher);
this->prf->destroy(this->prf);
this->xof->destroy(this->xof);
this->rng->destroy(this->rng);
this->dh->destroy(this->dh);
free(this);
@@ -1377,6 +1529,7 @@ crypto_tester_t *crypto_tester_create()
.test_signer = _test_signer,
.test_hasher = _test_hasher,
.test_prf = _test_prf,
.test_xof = _test_xof,
.test_rng = _test_rng,
.test_dh = _test_dh,
.add_crypter_vector = _add_crypter_vector,
@@ -1384,6 +1537,7 @@ crypto_tester_t *crypto_tester_create()
.add_signer_vector = _add_signer_vector,
.add_hasher_vector = _add_hasher_vector,
.add_prf_vector = _add_prf_vector,
.add_xof_vector = _add_xof_vector,
.add_rng_vector = _add_rng_vector,
.add_dh_vector = _add_dh_vector,
.destroy = _destroy,
@@ -1393,6 +1547,7 @@ crypto_tester_t *crypto_tester_create()
.signer = linked_list_create(),
.hasher = linked_list_create(),
.prf = linked_list_create(),
.xof = linked_list_create(),
.rng = linked_list_create(),
.dh = linked_list_create(),
+32
View File
@@ -30,6 +30,7 @@ typedef struct aead_test_vector_t aead_test_vector_t;
typedef struct signer_test_vector_t signer_test_vector_t;
typedef struct hasher_test_vector_t hasher_test_vector_t;
typedef struct prf_test_vector_t prf_test_vector_t;
typedef struct xof_test_vector_t xof_test_vector_t;
typedef struct rng_test_vector_t rng_test_vector_t;
typedef struct dh_test_vector_t dh_test_vector_t;
@@ -114,6 +115,19 @@ struct prf_test_vector_t {
u_char *out;
};
struct xof_test_vector_t {
/** xof algorithm this test vector tests */
ext_out_function_t alg;
/** size of the seed data */
size_t len;
/** seed data */
u_char *seed;
/** size of the output */
size_t out_len;
/** expected output of size*/
u_char *out;
};
/**
* Test vector for a RNG.
*
@@ -216,6 +230,17 @@ struct crypto_tester_t {
bool (*test_prf)(crypto_tester_t *this, pseudo_random_function_t alg,
prf_constructor_t create,
u_int *speed, const char *plugin_name);
/**
* Test an XOF algorithm.
*
* @param alg algorithm to test
* @param create constructor function for the XOF
* @param speed speed test result, NULL to omit
* @return TRUE if test passed
*/
bool (*test_xof)(crypto_tester_t *this, ext_out_function_t alg,
xof_constructor_t create,
u_int *speed, const char *plugin_name);
/**
* Test a RNG implementation.
*
@@ -274,6 +299,13 @@ struct crypto_tester_t {
*/
void (*add_prf_vector)(crypto_tester_t *this, prf_test_vector_t *vector);
/**
* Add a test vector to test an XOF.
*
* @param vector pointer to test vector
*/
void (*add_xof_vector)(crypto_tester_t *this, xof_test_vector_t *vector);
/**
* Add a test vector to test a RNG.
*
+4 -1
View File
@@ -49,7 +49,9 @@ ENUM_NEXT(diffie_hellman_group_names, NTRU_112_BIT, NTRU_256_BIT, MODP_NULL,
"NTRU_128",
"NTRU_192",
"NTRU_256");
ENUM_NEXT(diffie_hellman_group_names, MODP_CUSTOM, MODP_CUSTOM, NTRU_256_BIT,
ENUM_NEXT(diffie_hellman_group_names, NH_128_BIT, NH_128_BIT, NTRU_256_BIT,
"NEWHOPE_128");
ENUM_NEXT(diffie_hellman_group_names, MODP_CUSTOM, MODP_CUSTOM, NH_128_BIT,
"MODP_CUSTOM");
ENUM_END(diffie_hellman_group_names, MODP_CUSTOM);
@@ -554,6 +556,7 @@ bool diffie_hellman_verify_value(diffie_hellman_group_t group, chunk_t value)
case NTRU_128_BIT:
case NTRU_192_BIT:
case NTRU_256_BIT:
case NH_128_BIT:
/* verification currently not supported, do in plugin */
valid = FALSE;
break;
@@ -68,6 +68,7 @@ enum diffie_hellman_group_t {
NTRU_128_BIT = 1031,
NTRU_192_BIT = 1032,
NTRU_256_BIT = 1033,
NH_128_BIT = 1040,
/** internally used DH group with additional parameters g and p, outside
* of PRIVATE USE (i.e. IKEv2 DH group range) so it can't be negotiated */
MODP_CUSTOM = 65536,
@@ -167,5 +167,6 @@ ntru112, DIFFIE_HELLMAN_GROUP, NTRU_112_BIT, 0
ntru128, DIFFIE_HELLMAN_GROUP, NTRU_128_BIT, 0
ntru192, DIFFIE_HELLMAN_GROUP, NTRU_192_BIT, 0
ntru256, DIFFIE_HELLMAN_GROUP, NTRU_256_BIT, 0
newhope128, DIFFIE_HELLMAN_GROUP, NH_128_BIT, 0
noesn, EXTENDED_SEQUENCE_NUMBERS, NO_EXT_SEQ_NUMBERS, 0
esn, EXTENDED_SEQUENCE_NUMBERS, EXT_SEQ_NUMBERS, 0
+7 -3
View File
@@ -17,13 +17,15 @@
#include <crypto/hashers/hasher.h>
#include <crypto/rngs/rng.h>
ENUM_BEGIN(transform_type_names, UNDEFINED_TRANSFORM_TYPE, COMPRESSION_ALGORITHM,
ENUM_BEGIN(transform_type_names, UNDEFINED_TRANSFORM_TYPE, EXTENDED_OUTPUT_FUNCTION,
"UNDEFINED_TRANSFORM_TYPE",
"HASH_ALGORITHM",
"RANDOM_NUMBER_GENERATOR",
"AEAD_ALGORITHM",
"COMPRESSION_ALGORITHM");
ENUM_NEXT(transform_type_names, ENCRYPTION_ALGORITHM, EXTENDED_SEQUENCE_NUMBERS, COMPRESSION_ALGORITHM,
"COMPRESSION_ALGORITHM",
"EXTENDED OUTPUT FUNCTION");
ENUM_NEXT(transform_type_names, ENCRYPTION_ALGORITHM, EXTENDED_SEQUENCE_NUMBERS,
EXTENDED_OUTPUT_FUNCTION,
"ENCRYPTION_ALGORITHM",
"PSEUDO_RANDOM_FUNCTION",
"INTEGRITY_ALGORITHM",
@@ -60,6 +62,8 @@ enum_name_t* transform_get_enum_names(transform_type_t type)
return diffie_hellman_group_names;
case EXTENDED_SEQUENCE_NUMBERS:
return extended_sequence_numbers_names;
case EXTENDED_OUTPUT_FUNCTION:
return ext_out_function_names;
case UNDEFINED_TRANSFORM_TYPE:
case COMPRESSION_ALGORITHM:
break;
+1
View File
@@ -34,6 +34,7 @@ enum transform_type_t {
RANDOM_NUMBER_GENERATOR = 243,
AEAD_ALGORITHM = 244,
COMPRESSION_ALGORITHM = 245,
EXTENDED_OUTPUT_FUNCTION = 246,
ENCRYPTION_ALGORITHM = 1,
PSEUDO_RANDOM_FUNCTION = 2,
INTEGRITY_ALGORITHM = 3,
+27
View File
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2016 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 "xof.h"
ENUM(ext_out_function_names, XOF_UNDEFINED, XOF_CHACHA20,
"XOF_UNDEFINED",
"XOF_SHAKE128",
"XOF_SHAKE256",
"XOF_MGF1_SHA1",
"XOF_MGF1_SHA256",
"XOF_MGF1_SHA512",
"XOF_CHACHA20"
);
+107
View File
@@ -0,0 +1,107 @@
/*
* Copyright (C) 2016 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.
*/
/**
* @defgroup xof xof
* @{ @ingroup crypto
*/
#ifndef XOF_H_
#define XOF_H_
typedef enum ext_out_function_t ext_out_function_t;
typedef struct xof_t xof_t;
#include <library.h>
/**
* Extendable Output Functions.
*/
enum ext_out_function_t {
XOF_UNDEFINED,
/** FIPS 202 */
XOF_SHAKE_128,
/** FIPS 202 */
XOF_SHAKE_256,
/** RFC 2437 PKCS#1 */
XOF_MGF1_SHA1,
/** RFC 2437 PKCS#1 */
XOF_MGF1_SHA256,
/** RFC 2437 PKCS#1 */
XOF_MGF1_SHA512,
/** RFC 7539 ChaCha20 */
XOF_CHACHA20,
};
/**
* enum name for ext_out_function_t.
*/
extern enum_name_t *ext_out_function_names;
/**
* Generic interface for pseudo-random-functions.
*/
struct xof_t {
/**
* Generates pseudo random bytes and writes them in the buffer.
*
* @param out_len number of output bytes requested
* @param buffer pointer where the generated bytes will be written
* @return TRUE if bytes generated successfully
*/
bool (*get_bytes)(xof_t *this, size_t out_len,
uint8_t *buffer) __attribute__((warn_unused_result));
/**
* Generates pseudo random bytes and allocate space for them.
*
* @param out_len number of output bytes requested
* @param chunk chunk which will hold generated bytes
* @return TRUE if bytes allocated and generated successfully
*/
bool (*allocate_bytes)(xof_t *this, size_t out_len,
chunk_t *chunk) __attribute__((warn_unused_result));
/**
* Get the output block size
*
* @return block size in bytes
*/
size_t (*get_block_size)(xof_t *this);
/**
* Get the recommended minimum seed size
*
* @return seed size in bytes
*/
size_t (*get_seed_size)(xof_t *this);
/**
* Set the key for this xof_t object.
*
* @param sed seed to set
* @return TRUE if XOF initialized with seed successfully
*/
bool (*set_seed)(xof_t *this,
chunk_t seed) __attribute__((warn_unused_result));
/**
* Destroys a xof object.
*/
void (*destroy)(xof_t *this);
};
#endif /** XOF_H_ @}*/
@@ -0,0 +1,15 @@
AM_CPPFLAGS = \
-I$(top_srcdir)/src/libstrongswan
AM_CFLAGS = \
@COVERAGE_CFLAGS@
AM_LDFLAGS = \
-no-undefined
ipseclib_LTLIBRARIES = libnttfft.la
libnttfft_la_SOURCES = \
ntt_fft_reduce.h ntt_fft.h ntt_fft.c \
ntt_fft_params.h ntt_fft_params.c
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014 Andreas Steffen
* Copyright (C) 2014-2016 Andreas Steffen
* HSR Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
@@ -13,34 +13,44 @@
* for more details.
*/
#include "bliss_fft.h"
typedef struct private_bliss_fft_t private_bliss_fft_t;
#include "ntt_fft.h"
#include "ntt_fft_reduce.h"
/**
* Private data structure for bliss_fft_t object
* Described in header.
*/
struct private_bliss_fft_t {
void libnttfft_init(void)
{
/* empty */
}
typedef struct private_ntt_fft_t private_ntt_fft_t;
/**
* Private data structure for ntt_fft_t object
*/
struct private_ntt_fft_t {
/**
* Public interface.
*/
bliss_fft_t public;
ntt_fft_t public;
/**
* FFT parameter set used as constants
*/
bliss_fft_params_t *p;
const ntt_fft_params_t *p;
};
METHOD(bliss_fft_t, get_size, uint16_t,
private_bliss_fft_t *this)
METHOD(ntt_fft_t, get_size, uint16_t,
private_ntt_fft_t *this)
{
return this->p->n;
}
METHOD(bliss_fft_t, get_modulus, uint16_t,
private_bliss_fft_t *this)
METHOD(ntt_fft_t, get_modulus, uint16_t,
private_ntt_fft_t *this)
{
return this->p->q;
}
@@ -54,8 +64,7 @@ METHOD(bliss_fft_t, get_modulus, uint16_t,
* x[i2] ---|-|--|*|-- x[i2]
*
*/
static void butterfly(private_bliss_fft_t *this, uint32_t *x, int i1,int i2,
int iw)
static void butterfly(private_ntt_fft_t *this, uint32_t *x, int i1,int i2, int iw)
{
uint32_t xp, xm;
@@ -65,14 +74,14 @@ static void butterfly(private_bliss_fft_t *this, uint32_t *x, int i1,int i2,
{
xp -= this->p->q;
}
x[i1] = xp;
x[i2] = (xm * this->p->w[iw]) % this->p->q;
x[i1] = xp;
x[i2] = ntt_fft_mreduce(xm * this->p->wr[iw], this->p);
}
/**
* Trivial butterfly operation of last FFT stage
*/
static void butterfly_last(private_bliss_fft_t *this, uint32_t *x, int i1)
static void butterfly_last(private_ntt_fft_t *this, uint32_t *x, int i1)
{
uint32_t xp, xm;
int i2 = i1 + 1;
@@ -91,23 +100,22 @@ static void butterfly_last(private_bliss_fft_t *this, uint32_t *x, int i1)
x[i2] = xm;
}
METHOD(bliss_fft_t, transform, void,
private_bliss_fft_t *this, uint32_t *a, uint32_t *b, bool inverse)
METHOD(ntt_fft_t, transform, void,
private_ntt_fft_t *this, uint32_t *a, uint32_t *b, bool inverse)
{
int stage, i, j, k, m, n, t, iw, i_rev;
uint16_t q;
int stage, i, j, k, m, n, s, t, iw, i_rev;
uint32_t tmp;
/* we are going to use the transform size n and the modulus q a lot */
/* we are going to use the transform size n a lot */
n = this->p->n;
q = this->p->q;
s = this->p->s;
if (!inverse)
{
/* apply linear phase needed for negative wrapped convolution */
for (i = 0; i < n; i++)
{
b[i] = (a[i] * this->p->w[i]) % q;
b[i] = ntt_fft_mreduce(a[i] * this->p->wf[s*i], this->p);
}
}
else if (a != b)
@@ -137,7 +145,7 @@ METHOD(bliss_fft_t, transform, void,
{
for (i = 0; i < m; i++)
{
iw = 2 * (inverse ? (n - i * k) : (i * k));
iw = s * (inverse ? (n - i * k) : (i * k));
butterfly(this, b, t + i, t + i + m, iw);
}
}
@@ -167,13 +175,13 @@ METHOD(bliss_fft_t, transform, void,
{
for (i = 0; i < n; i++)
{
b[i] = (((b[i] * this->p->w[2*n - i]) % q) * this->p->n_inv) % q;
b[i] = ntt_fft_mreduce(b[i] * this->p->wi[i], this->p);
}
}
}
METHOD(bliss_fft_t, destroy, void,
private_bliss_fft_t *this)
METHOD(ntt_fft_t, destroy, void,
private_ntt_fft_t *this)
{
free(this);
}
@@ -181,9 +189,9 @@ METHOD(bliss_fft_t, destroy, void,
/**
* See header.
*/
bliss_fft_t *bliss_fft_create(bliss_fft_params_t *params)
ntt_fft_t *ntt_fft_create(const ntt_fft_params_t *params)
{
private_bliss_fft_t *this;
private_ntt_fft_t *this;
INIT(this,
.public = {
@@ -14,37 +14,37 @@
*/
/**
* @defgroup bliss_fft bliss_fft
* @defgroup ntt_fft ntt_fft
* @{ @ingroup bliss_p
*/
#ifndef BLISS_FFT_H_
#define BLISS_FFT_H_
#ifndef NTT_FFT_H_
#define NTT_FFT_H_
#include "bliss_fft_params.h"
#include "ntt_fft_params.h"
#include <library.h>
typedef struct bliss_fft_t bliss_fft_t;
typedef struct ntt_fft_t ntt_fft_t;
/**
* Implements a Number Theoretic Transform (NTT) via the FFT algorithm
*/
struct bliss_fft_t {
struct ntt_fft_t {
/**
* Get the size of the Number Theoretic Transform
*
* @result Transform size
*/
uint16_t (*get_size)(bliss_fft_t *this);
uint16_t (*get_size)(ntt_fft_t *this);
/**
* Get the prime modulus of the Number Theoretic Transform
*
* @result Prime modulus
*/
uint16_t (*get_modulus)(bliss_fft_t *this);
uint16_t (*get_modulus)(ntt_fft_t *this);
/**
* Compute the [inverse] NTT of a polynomial
@@ -53,19 +53,25 @@ struct bliss_fft_t {
* @param b Coefficient of output polynomial
* @param inverse TRUE if the inverse NTT has to be computed
*/
void (*transform)(bliss_fft_t *this, uint32_t *a, uint32_t *b, bool inverse);
void (*transform)(ntt_fft_t *this, uint32_t *a, uint32_t *b, bool inverse);
/**
* Destroy bliss_fft_t object
* Destroy ntt_fft_t object
*/
void (*destroy)(bliss_fft_t *this);
void (*destroy)(ntt_fft_t *this);
};
/**
* Create a bliss_fft_t object for a given FFT parameter set
* Create a ntt_fft_t object for a given FFT parameter set
*
* @param params FFT parameters
*/
bliss_fft_t *bliss_fft_create(bliss_fft_params_t *params);
ntt_fft_t *ntt_fft_create(const ntt_fft_params_t *params);
#endif /** BLISS_FFT_H_ @}*/
/**
* Dummy libnttfft initialization function needed for integrity test
*/
void libnttfft_init(void);
#endif /** NTT_FFT_H_ @}*/
@@ -0,0 +1,652 @@
/*
* Copyright (C) 2014-2016 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 "ntt_fft_params.h"
/**
* FFT twiddle factors in Montgomery form for q = 12289 and n = 1024
*/
static const uint16_t wr_12289_1024[] = {
4075, 3051, 2031, 1207, 9987, 10092, 2948, 9273, 11973, 9094,
3202, 9430, 7377, 5092, 3728, 10626, 4536, 1062, 2882, 6039,
975, 10908, 6065, 2249, 11889, 4978, 10431, 7270, 12138, 4890,
6119, 4895, 6364, 4611, 4737, 10911, 6212, 9452, 8455, 8758,
11316, 1479, 11026, 11847, 2920, 7901, 6190, 8374, 4789, 1170,
8174, 7278, 241, 11809, 1058, 2686, 8724, 9650, 5868, 4885,
5874, 5179, 7991, 10600, 3262, 81, 3969, 10146, 5594, 3748,
11606, 3400, 6843, 3504, 11939, 7428, 7591, 3289, 1404, 7351,
3818, 2747, 11713, 8643, 5681, 8011, 11580, 2126, 5862, 4591,
3757, 12047, 431, 8830, 2555, 2305, 2344, 4255, 11871, 4096,
4080, 3296, 1747, 11869, 3998, 11567, 1489, 11516, 11279, 11955,
8212, 9140, 5456, 9275, 12071, 1607, 5009, 11950, 7967, 9424,
7083, 2975, 10596, 3066, 2766, 355, 5106, 4414, 7373, 4896,
6413, 7012, 11785, 12171, 6507, 11618, 3988, 11077, 2057, 2481,
10968, 9005, 11130, 4654, 6844, 3553, 2051, 2187, 8851, 3584,
3570, 2884, 6137, 5777, 426, 8585, 2839, 3932, 8333, 2780,
1041, 1853, 4774, 435, 9026, 12159, 5919, 7384, 5435, 8246,
10806, 1067, 3127, 5755, 11637, 4919, 7540, 790, 1843, 4284,
1003, 12280, 11848, 2969, 10302, 949, 9634, 5084, 3336, 3707,
9597, 3271, 522, 1000, 12133, 4645, 6403, 6522, 64, 3136,
6196, 8668, 6906, 6591, 3445, 9048, 948, 9585, 2683, 8577,
2447, 9302, 1105, 4989, 10970, 9103, 3643, 6461, 9364, 4143,
6383, 5542, 1200, 9644, 5574, 2768, 453, 9908, 6221, 9893,
5486, 10745, 10367, 4134, 5942, 8511, 11502, 10593, 2919, 7852,
3789, 1326, 3529, 875, 6008, 11745, 10211, 8779, 56, 2744,
11566, 1440, 9115, 4231, 10695, 7917, 6974, 9923, 6956, 9041,
605, 5067, 2503, 12046, 382, 6429, 7796, 1045, 2049, 2089,
4049, 1777, 1050, 2294, 1805, 2422, 8077, 2525, 835, 4048,
1728, 10938, 7535, 545, 2127, 5911, 6992, 10805, 1018, 726,
10996, 10377, 4624, 5374, 5257, 11813, 1254, 1, 49, 2401,
7048, 1260, 295, 2166, 7822, 2319, 3030, 1002, 12231, 9447,
8210, 9042, 654, 7468, 9551, 1017, 677, 8595, 3329, 3364,
5079, 3091, 3991, 11224, 9260, 11336, 2459, 9890, 5339, 3542,
1512, 354, 5057, 2013, 325, 3636, 6118, 4846, 3963, 9852,
3477, 10616, 4046, 1630, 6136, 5728, 10314, 1537, 1579, 3637,
6167, 7247, 11011, 11112, 3772, 493, 11868, 3949, 9166, 6730,
10256, 10984, 9789, 390, 6821, 2426, 8273, 12129, 4449, 9088,
2908, 7313, 1956, 9821, 1958, 9919, 6760, 11726, 9280, 27,
1323, 3382, 5961, 9442, 7965, 9326, 2281, 1168, 8076, 2476,
10723, 9289, 468, 10643, 5369, 5012, 12097, 2881, 5990, 10863,
3860, 4805, 1954, 9723, 9445, 8112, 4240, 11136, 4948, 8961,
8974, 9611, 3957, 9558, 1360, 5195, 8775, 12149, 5429, 7952,
8689, 7935, 7856, 3985, 10930, 7143, 5915, 7188, 8120, 4632,
5766, 12176, 6752, 11334, 2361, 5088, 3532, 1022, 922, 8311,
1702, 9664, 6554, 1632, 6234, 10530, 12121, 4057, 2169, 7969,
9522, 11885, 4782, 827, 3656, 7098, 3710, 9744, 10474, 9377,
4780, 729, 11143, 5291, 1190, 9154, 6142, 6022, 142, 6958,
9139, 5407, 6874, 5023, 347, 4714, 9784, 145, 7105, 4053,
1973, 10654, 5908, 6845, 3602, 4452, 9235, 10111, 3879, 5736,
10706, 8456, 8807, 1428, 8527, 12286, 12142, 5086, 3434, 8509,
11404, 5791, 1112, 5332, 3199, 9283, 174, 8526, 12237, 9741,
10327, 2174, 8214, 9238, 10258, 11082, 2302, 2197, 9341, 3016,
316, 3195, 9087, 2859, 4912, 7197, 8561, 1663, 7753, 11227,
9407, 6250, 11314, 1381, 6224, 10040, 400, 7311, 1858, 5019,
151, 7399, 6170, 7394, 5925, 7678, 7552, 1378, 6077, 2837,
3834, 3531, 973, 10810, 1263, 442, 9369, 4388, 6099, 3915,
7500, 11119, 4115, 5011, 12048, 480, 11231, 9603, 3565, 2639,
6421, 7404, 6415, 7110, 4298, 1689, 9027, 12208, 8320, 2143,
6695, 8541, 683, 8889, 5446, 8785, 350, 4861, 4698, 9000,
10885, 4938, 8471, 9542, 576, 3646, 6608, 4278, 709, 10163,
6427, 7698, 8532, 242, 11858, 3459, 9734, 9984, 9945, 8034,
418, 8193, 8209, 8993, 10542, 420, 8291, 722, 10800, 773,
1010, 334, 4077, 3149, 6833, 3014, 218, 10682, 7280, 339,
4322, 2865, 5206, 9314, 1693, 9223, 9523, 11934, 7183, 7875,
4916, 7393, 5876, 5277, 504, 118, 5782, 671, 8301, 1212,
10232, 9808, 1321, 3284, 1159, 7635, 5445, 8736, 10238, 10102,
3438, 8705, 8719, 9405, 6152, 6512, 11863, 3704, 9450, 8357,
3956, 9509, 11248, 10436, 7515, 11854, 3263, 130, 6370, 4905,
6854, 4043, 1483, 11222, 9162, 6534, 652, 7370, 4749, 11499,
10446, 8005, 11286, 9, 441, 9320, 1987, 11340, 2655, 7205,
8953, 8582, 2692, 9018, 11767, 11289, 156, 7644, 5886, 5767,
12225, 9153, 6093, 3621, 5383, 5698, 8844, 3241, 11341, 2704,
9606, 3712, 9842, 2987, 11184, 7300, 1319, 3186, 8646, 5828,
2925, 8146, 5906, 6747, 11089, 2645, 6715, 9521, 11836, 2381,
6068, 2396, 6803, 1544, 1922, 8155, 6347, 3778, 787, 1696,
9370, 4437, 8500, 10963, 8760, 11414, 6281, 544, 2078, 3510,
12233, 9545, 723, 10849, 3174, 8058, 1594, 4372, 5315, 2366,
5333, 3248, 11684, 7222, 9786, 243, 11907, 5860, 4493, 11244,
10240, 10200, 8240, 10512, 11239, 9995, 10484, 9867, 4212, 9764,
11454, 8241, 10561, 1351, 4754, 11744, 10162, 6378, 5297, 1484,
11271, 11563, 1293, 1912, 7665, 6915, 7032, 476, 11035, 12288,
12240, 9888, 5241, 11029, 11994, 10123, 4467, 9970, 9259, 11287,
58, 2842, 4079, 3247, 11635, 4821, 2738, 11272, 11612, 3694,
8960, 8925, 7210, 9198, 8298, 1065, 3029, 953, 9830, 2399,
6950, 8747, 10777, 11935, 7232, 10276, 11964, 8653, 6171, 7443,
8326, 2437, 8812, 1673, 8243, 10659, 6153, 6561, 1975, 10752,
10710, 8652, 6122, 5042, 1278, 1177, 8517, 11796, 421, 8340,
3123, 5559, 2033, 1305, 2500, 11899, 5468, 9863, 4016, 160,
7840, 3201, 9381, 4976, 10333, 2468, 10331, 2370, 5529, 563,
3009, 12262, 10966, 8907, 6328, 2847, 4324, 2963, 10008, 11121,
4213, 9813, 1566, 3000, 11821, 1646, 6920, 7277, 192, 9408,
6299, 1426, 8429, 7484, 10335, 2566, 2844, 4177, 8049, 1153,
7341, 3328, 3315, 2678, 8332, 2731, 10929, 7094, 3514, 140,
6860, 4337, 3600, 4354, 4433, 8304, 1359, 5146, 6374, 5101,
4169, 7657, 6523, 113, 5537, 955, 9928, 7201, 8757, 11267,
11367, 3978, 10587, 2625, 5735, 10657, 6055, 1759, 168, 8232,
10120, 4320, 2767, 404, 7507, 11462, 8633, 5191, 8579, 2545,
1815, 2912, 7509, 11560, 1146, 6998, 11099, 3135, 6147, 6267,
12147, 5331, 3150, 6882, 5415, 7266, 11942, 7575, 2505, 12144,
5184, 8236, 10316, 1635, 6381, 5444, 8687, 7837, 3054, 2178,
8410, 6553, 1583, 3833, 3482, 10861, 3762, 3, 147, 7203,
8855, 3780, 885, 6498, 11177, 6957, 9090, 3006, 12115, 3763,
52, 2548, 1962, 10115, 4075
};
/**
* FFT phase shift in forward transform for q = 12289 and n = 1024
*/
static const uint16_t wf_12289_1024[] = {
3186, 10013, 8646, 11366, 5828, 3929, 2925, 8186, 8146, 7866,
5906, 4475, 6747, 10362, 11089, 3889, 2645, 6226, 6715, 10138,
9521, 5202, 11836, 9118, 2381, 4378, 6068, 5609, 2396, 4483,
6803, 10754, 1544, 10808, 1922, 1165, 8155, 7929, 6347, 7562,
3778, 1868, 787, 5509, 1696, 11872, 9370, 4145, 4437, 6481,
8500, 10344, 10963, 3007, 8760, 12164, 11414, 6164, 6281, 7100,
544, 3808, 2078, 2257, 3510, 12281, 12233, 11897, 9545, 5370,
723, 5061, 10849, 2209, 3174, 9929, 8058, 7250, 1594, 11158,
4372, 6026, 5315, 338, 2366, 4273, 5333, 464, 3248, 10447,
11684, 8054, 7222, 1398, 9786, 7057, 243, 1701, 11907, 9615,
5860, 4153, 4493, 6873, 11244, 4974, 10240, 10235, 10200, 9955,
8240, 8524, 10512, 12139, 11239, 4939, 9995, 8520, 10484, 11943,
9867, 7624, 4212, 4906, 9764, 6903, 11454, 6444, 8241, 8531,
10561, 193, 1351, 9457, 4754, 8700, 11744, 8474, 10162, 9689,
6378, 7779, 5297, 212, 1484, 10388, 11271, 5163, 11563, 7207,
1293, 9051, 1912, 1095, 7665, 4499, 6915, 11538, 7032, 68,
476, 3332, 11035, 3511, 12288, 12282, 12240, 11946, 9888, 7771,
5241, 12109, 11029, 3469, 11994, 10224, 10123, 9416, 4467, 6691,
9970, 8345, 9259, 3368, 11287, 5275, 58, 406, 2842, 7605,
4079, 3975, 3247, 10440, 11635, 7711, 4821, 9169, 2738, 6877,
11272, 5170, 11612, 7550, 3694, 1280, 8960, 1275, 8925, 1030,
7210, 1314, 9198, 2941, 8298, 8930, 1065, 7455, 3029, 8914,
953, 6671, 9830, 7365, 2399, 4504, 6950, 11783, 8747, 12073,
10777, 1705, 11935, 9811, 7232, 1468, 10276, 10487, 11964, 10014,
8653, 11415, 6171, 6330, 7443, 2945, 8326, 9126, 2437, 4770,
8812, 239, 1673, 11711, 8243, 8545, 10659, 879, 6153, 6204,
6561, 9060, 1975, 1536, 10752, 1530, 10710, 1236, 8652, 11408,
6122, 5987, 5042, 10716, 1278, 8946, 1177, 8239, 8517, 10463,
11796, 8838, 421, 2947, 8340, 9224, 3123, 9572, 5559, 2046,
2033, 1942, 1305, 9135, 2500, 5211, 11899, 9559, 5468, 1409,
9863, 7596, 4016, 3534, 160, 1120, 7840, 5724, 3201, 10118,
9381, 4222, 4976, 10254, 10333, 10886, 2468, 4987, 10331, 10872,
2370, 4301, 5529, 1836, 563, 3941, 3009, 8774, 12262, 12100,
10966, 3028, 8907, 904, 6328, 7429, 2847, 7640, 4324, 5690,
2963, 8452, 10008, 8611, 11121, 4113, 4213, 4913, 9813, 7246,
1566, 10962, 3000, 8711, 11821, 9013, 1646, 11522, 6920, 11573,
7277, 1783, 192, 1344, 9408, 4411, 6299, 7226, 1426, 9982,
8429, 9847, 7484, 3232, 10335, 10900, 2566, 5673, 2844, 7619,
4177, 4661, 8049, 7187, 1153, 8071, 7341, 2231, 3328, 11007,
3315, 10916, 2678, 6457, 8332, 9168, 2731, 6828, 10929, 2769,
7094, 502, 3514, 20, 140, 980, 6860, 11153, 4337, 5781,
3600, 622, 4354, 5900, 4433, 6453, 8304, 8972, 1359, 9513,
5146, 11444, 6374, 7751, 5101, 11129, 4169, 4605, 7657, 4443,
6523, 8794, 113, 791, 5537, 1892, 955, 6685, 9928, 8051,
7201, 1251, 8757, 12143, 11267, 5135, 11367, 5835, 3978, 3268,
10587, 375, 2625, 6086, 5735, 3278, 10657, 865, 6055, 5518,
1759, 24, 168, 1176, 8232, 8468, 10120, 9395, 4320, 5662,
2767, 7080, 404, 2828, 7507, 3393, 11462, 6500, 8633, 11275,
5191, 11759, 8579, 10897, 2545, 5526, 1815, 416, 2912, 8095,
7509, 3407, 11560, 7186, 1146, 8022, 6998, 12119, 11099, 3959,
3135, 9656, 6147, 6162, 6267, 7002, 12147, 11295, 5331, 450,
3150, 9761, 6882, 11307, 5415, 1038, 7266, 1706, 11942, 9860,
7575, 3869, 2505, 5246, 12144, 11274, 5184, 11710, 8236, 8496,
10316, 10767, 1635, 11445, 6381, 7800, 5444, 1241, 8687, 11653,
7837, 5703, 3054, 9089, 2178, 2957, 8410, 9714, 6553, 9004,
1583, 11081, 3833, 2253, 3482, 12085, 10861, 2293, 3762, 1756,
3, 21, 147, 1029, 7203, 1265, 8855, 540, 3780, 1882,
885, 6195, 6498, 8619, 11177, 4505, 6957, 11832, 9090, 2185,
3006, 8753, 12115, 11071, 3763, 1763, 52, 364, 2548, 5547,
1962, 1445, 10115, 9360, 4075, 3947, 3051, 9068, 2031, 1928,
1207, 8449, 9987, 8464, 10092, 9199, 2948, 8347, 9273, 3466,
11973, 10077, 9094, 2213, 3202, 10125, 9430, 4565, 7377, 2483,
5092, 11066, 3728, 1518, 10626, 648, 4536, 7174, 1062, 7434,
2882, 7885, 6039, 5406, 975, 6825, 10908, 2622, 6065, 5588,
2249, 3454, 11889, 9489, 4978, 10268, 10431, 11572, 7270, 1734,
12138, 11232, 4890, 9652, 6119, 5966, 4895, 9687, 6364, 7681,
4611, 7699, 4737, 8581, 10911, 2643, 6212, 6617, 9452, 4719,
8455, 10029, 8758, 12150, 11316, 5478, 1479, 10353, 11026, 3448,
11847, 9195, 2920, 8151, 7901, 6151, 6190, 6463, 8374, 9462,
4789, 8945, 1170, 8190, 8174, 8062, 7278, 1790, 241, 1687,
11809, 8929, 1058, 7406, 2686, 6513, 8724, 11912, 9650, 6105,
5868, 4209, 4885, 9617, 5874, 4251, 5179, 11675, 7991, 6781,
10600, 466, 3262, 10545, 81, 567, 3969, 3205, 10146, 9577,
5594, 2291, 3748, 1658, 11606, 7508, 3400, 11511, 6843, 11034,
3504, 12239, 11939, 9839, 7428, 2840, 7591, 3981, 3289, 10734,
1404, 9828, 7351, 2301, 3818, 2148, 2747, 6940, 11713, 8257,
8643, 11345, 5681, 2900, 8011, 6921, 11580, 7326, 2126, 2593,
5862, 4167, 4591, 7559, 3757, 1721, 12047, 10595, 431, 3017,
8830, 365, 2555, 5596, 2305, 3846, 2344, 4119, 4255, 5207,
11871, 9363, 4096, 4094, 4080, 3982, 3296, 10783, 1747, 12229,
11869, 9349, 3998, 3408, 11567, 7235, 1489, 10423, 11516, 6878,
11279, 5219, 11955, 9951, 8212, 8328, 9140, 2535, 5456, 1325,
9275, 3480, 12071, 10763, 1607, 11249, 5009, 10485, 11950, 9916,
7967, 6613, 9424, 4523, 7083, 425, 2975, 8536, 10596, 438,
3066, 9173, 2766, 7073, 355, 2485, 5106, 11164, 4414, 6320,
7373, 2455, 4896, 9694, 6413, 8024, 7012, 12217, 11785, 8761,
12171, 11463, 6507, 8682, 11618, 7592, 3988, 3338, 11077, 3805,
2057, 2110, 2481, 5078, 10968, 3042, 9005, 1590, 11130, 4176,
4654, 8000, 6844, 11041, 3553, 293, 2051, 2068, 2187, 3020,
8851, 512, 3584, 510, 3570, 412, 2884, 7899, 6137, 6092,
5777, 3572, 426, 2982, 8585, 10939, 2839, 7584, 3932, 2946,
8333, 9175, 2780, 7171, 1041, 7287, 1853, 682, 4774, 8840,
435, 3045, 9026, 1737, 12159, 11379, 5919, 4566, 7384, 2532,
5435, 1178, 8246, 8566, 10806, 1908, 1067, 7469, 3127, 9600,
5755, 3418, 11637, 7725, 4919, 9855, 7540, 3624, 790, 5530,
1843, 612, 4284, 5410, 1003, 7021, 12280, 12226, 11848, 9202,
2969, 8494, 10302, 10669, 949, 6643, 9634, 5993, 5084, 11010,
3336, 11063, 3707, 1371, 9597, 5734, 3271, 10608, 522, 3654,
1000, 7000, 12133, 11197, 4645, 7937, 6403, 7954, 6522, 8787,
64, 448, 3136, 9663, 6196, 6505, 8668, 11520, 6906, 11475,
6591, 9270, 3445, 11826, 9048, 1891, 948, 6636, 9585, 5650,
2683, 6492, 8577, 10883, 2447, 4840, 9302, 3669, 1105, 7735,
4989, 10345, 10970, 3056
};
/**
* FFT phase shift and scaling inverse transform for q = 12289 and n = 1024
*/
static const uint16_t wi_12289_1024[] = {
12277, 5265, 9530, 3117, 5712, 816, 10650, 3277, 9246, 4832,
5957, 851, 10655, 10300, 3227, 461, 3577, 511, 73, 1766,
5519, 2544, 2119, 7325, 2802, 5667, 11343, 3376, 5749, 6088,
7892, 2883, 3923, 2316, 3842, 4060, 580, 3594, 2269, 9102,
6567, 9716, 1388, 5465, 7803, 8137, 2918, 3928, 9339, 10112,
11978, 10489, 3254, 3976, 568, 8859, 11799, 12219, 12279, 10532,
12038, 8742, 4760, 680, 8875, 4779, 7705, 8123, 2916, 10950,
6831, 4487, 641, 10625, 5029, 2474, 2109, 5568, 2551, 2120,
3814, 4056, 2335, 10867, 3308, 11006, 6839, 977, 10673, 8547,
1221, 1930, 7298, 11576, 8676, 2995, 3939, 7585, 11617, 12193,
5253, 2506, 358, 8829, 6528, 11466, 1638, 234, 1789, 10789,
6808, 11506, 8666, 1238, 3688, 4038, 4088, 584, 1839, 7285,
8063, 4663, 9444, 10127, 8469, 4721, 2430, 9125, 11837, 1691,
10775, 6806, 6239, 6158, 7902, 4640, 4174, 5863, 11371, 3380,
3994, 11104, 6853, 979, 3651, 11055, 6846, 978, 7162, 9801,
10178, 1454, 7230, 4544, 9427, 8369, 11729, 12209, 10522, 10281,
8491, 1213, 5440, 9555, 1365, 195, 3539, 11039, 1577, 5492,
11318, 5128, 11266, 3365, 7503, 4583, 7677, 8119, 4671, 5934,
7870, 6391, 913, 1886, 2025, 5556, 7816, 11650, 6931, 9768,
3151, 9228, 6585, 7963, 11671, 6934, 11524, 6913, 11521, 5157,
7759, 2864, 9187, 3068, 5705, 815, 1872, 2023, 289, 5308,
6025, 7883, 9904, 4926, 7726, 8126, 4672, 2423, 9124, 3059,
437, 1818, 7282, 6307, 901, 7151, 11555, 8673, 1239, 177,
5292, 756, 108, 1771, 253, 8814, 10037, 4945, 2462, 7374,
2809, 5668, 7832, 4630, 2417, 5612, 7824, 8140, 4674, 7690,
11632, 8684, 11774, 1682, 5507, 7809, 11649, 10442, 8514, 6483,
9704, 6653, 2706, 10920, 1560, 3734, 2289, 327, 7069, 4521,
4157, 4105, 2342, 10868, 12086, 12260, 3507, 501, 10605, 1515,
1972, 7304, 2799, 3911, 7581, 1083, 7177, 6292, 4410, 630,
90, 3524, 2259, 7345, 6316, 6169, 6148, 6145, 4389, 627,
10623, 12051, 12255, 8773, 6520, 2687, 3895, 2312, 5597, 11333,
1619, 5498, 2541, 363, 3563, 509, 7095, 11547, 12183, 3496,
2255, 9100, 1300, 7208, 8052, 6417, 7939, 9912, 1416, 5469,
6048, 864, 1879, 2024, 9067, 6562, 2693, 7407, 9836, 10183,
8477, 1211, 173, 7047, 8029, 1147, 3675, 525, 75, 7033,
8027, 8169, 1167, 7189, 1027, 7169, 9802, 6667, 2708, 3898,
4068, 9359, 1337, 191, 5294, 6023, 2616, 7396, 11590, 8678,
8262, 6447, 921, 10665, 12057, 3478, 4008, 11106, 12120, 3487,
9276, 10103, 6710, 11492, 8664, 8260, 1180, 10702, 5040, 720,
3614, 5783, 9604, 1372, 196, 28, 4, 10534, 5016, 11250,
10385, 12017, 8739, 3004, 9207, 6582, 6207, 7909, 4641, 663,
7117, 8039, 2904, 3926, 4072, 7604, 6353, 11441, 3390, 5751,
11355, 10400, 8508, 2971, 2180, 2067, 5562, 11328, 6885, 11517,
6912, 2743, 3903, 11091, 3340, 9255, 10100, 4954, 7730, 6371,
9688, 1384, 7220, 2787, 9176, 4822, 4200, 600, 7108, 2771,
3907, 9336, 8356, 8216, 8196, 4682, 4180, 9375, 6606, 7966,
1138, 10696, 1528, 5485, 11317, 8639, 10012, 6697, 7979, 4651,
2420, 7368, 11586, 10433, 3246, 7486, 2825, 10937, 3318, 474,
7090, 4524, 5913, 7867, 4635, 9440, 11882, 3453, 5760, 4334,
9397, 3098, 10976, 1568, 224, 32, 10538, 3261, 3977, 9346,
10113, 8467, 11743, 12211, 3500, 500, 1827, 261, 5304, 7780,
2867, 10943, 6830, 7998, 11676, 1668, 5505, 2542, 9141, 4817,
9466, 6619, 11479, 5151, 4247, 7629, 4601, 5924, 6113, 6140,
9655, 6646, 2705, 2142, 306, 7066, 2765, 395, 1812, 3770,
11072, 8604, 10007, 11963, 1709, 9022, 4800, 7708, 9879, 6678,
954, 5403, 4283, 4123, 589, 8862, 1266, 3692, 2283, 9104,
11834, 12224, 7013, 4513, 7667, 6362, 4420, 2387, 341, 7071,
9788, 6665, 9730, 1390, 10732, 10311, 1473, 1966, 3792, 7564,
11614, 10437, 1491, 213, 1786, 9033, 3046, 9213, 10094, 1442,
206, 1785, 255, 1792, 256, 10570, 1510, 7238, 1034, 7170,
6291, 7921, 11665, 3422, 4000, 2327, 2088, 5565, 795, 10647,
1521, 5484, 2539, 7385, 1055, 7173, 8047, 11683, 1669, 1994,
3796, 5809, 4341, 9398, 11876, 12230, 10525, 12037, 12253, 3506,
4012, 9351, 4847, 2448, 7372, 9831, 3160, 2207, 5582, 2553,
7387, 6322, 9681, 1383, 10731, 1533, 219, 5298, 4268, 7632,
6357, 9686, 8406, 4712, 9451, 10128, 4958, 5975, 11387, 8649,
11769, 6948, 11526, 12180, 1740, 10782, 6807, 2728, 7412, 4570,
4164, 4106, 11120, 12122, 8754, 11784, 3439, 5758, 11356, 6889,
9762, 11928, 1704, 1999, 10819, 12079, 12259, 7018, 11536, 1648,
1991, 2040, 2047, 2048, 10826, 12080, 8748, 8272, 8204, 1172,
1923, 7297, 2798, 7422, 6327, 4415, 7653, 6360, 11442, 12168,
7005, 8023, 9924, 8440, 8228, 2931, 7441, 1063, 3663, 5790,
9605, 10150, 1450, 8985, 11817, 10466, 10273, 12001, 3470, 7518,
1074, 1909, 7295, 9820, 4914, 702, 5367, 7789, 8135, 9940,
1420, 3714, 11064, 12114, 12264, 1752, 5517, 9566, 11900, 1700,
3754, 5803, 829, 1874, 7290, 2797, 10933, 5073, 7747, 8129,
6428, 6185, 11417, 1631, 233, 5300, 9535, 10140, 11982, 8734,
8270, 2937, 10953, 8587, 8249, 2934, 9197, 4825, 5956, 4362,
9401, 1343, 3703, 529, 10609, 12049, 6988, 6265, 895, 3639,
4031, 4087, 4095, 585, 10617, 8539, 4731, 4187, 9376, 3095,
9220, 10095, 10220, 1460, 10742, 12068, 1724, 5513, 11321, 6884,
2739, 5658, 6075, 4379, 11159, 10372, 8504, 4726, 9453, 3106,
7466, 11600, 10435, 8513, 9994, 8450, 9985, 3182, 10988, 8592,
2983, 9204, 4826, 2445, 5616, 6069, 867, 3635, 5786, 11360,
5134, 2489, 10889, 12089, 1727, 7269, 2794, 9177, 1311, 5454,
9557, 6632, 2703, 9164, 10087, 1441, 3717, 531, 3587, 2268,
324, 5313, 759, 1864, 5533, 2546, 7386, 9833, 8427, 4715,
11207, 1601, 7251, 4547, 11183, 12131, 1733, 10781, 10318, 1474,
10744, 5046, 4232, 11138, 10369, 6748, 964, 7160, 4534, 7670,
8118, 8182, 4680, 11202, 6867, 981, 8918, 1274, 182, 26,
7026, 8026, 11680, 12202, 10521, 1503, 7237, 4545, 5916, 9623,
8397, 11733, 10454, 3249, 9242, 6587, 941, 1890, 270, 10572,
6777, 9746, 6659, 6218, 6155, 6146, 878, 1881, 7291, 11575,
12187, 1741, 7271, 8061, 11685, 6936, 4502, 9421, 4857, 4205,
7623, 1089, 10689, 1527, 8996, 10063, 11971, 10488, 6765, 2722,
3900, 9335, 11867, 6962, 11528, 5158, 4248, 4118, 5855, 2592,
5637, 6072, 2623, 7397, 8079, 9932, 4930, 5971, 853, 3633,
519, 8852, 11798, 3441, 11025, 1575, 225, 8810, 11792, 12218,
3501, 9278, 3081, 9218, 4828, 7712, 8124, 11694, 12204, 3499,
4011, 573, 3593, 5780, 7848, 9899, 10192, 1456, 208, 7052,
2763, 7417, 11593, 10434, 12024, 8740, 11782, 10461, 3250, 5731,
7841, 9898, 1414, 202, 3540, 7528, 2831, 2160, 10842, 5060,
4234, 4116, 588, 84
};
/**
* Bit-reversed indices for n = 1024
*/
static const uint16_t rev_1024[] = {
0, 512, 256, 768, 128, 640, 384, 896, 64, 576,
320, 832, 192, 704, 448, 960, 32, 544, 288, 800,
160, 672, 416, 928, 96, 608, 352, 864, 224, 736,
480, 992, 16, 528, 272, 784, 144, 656, 400, 912,
80, 592, 336, 848, 208, 720, 464, 976, 48, 560,
304, 816, 176, 688, 432, 944, 112, 624, 368, 880,
240, 752, 496, 1008, 8, 520, 264, 776, 136, 648,
392, 904, 72, 584, 328, 840, 200, 712, 456, 968,
40, 552, 296, 808, 168, 680, 424, 936, 104, 616,
360, 872, 232, 744, 488, 1000, 24, 536, 280, 792,
152, 664, 408, 920, 88, 600, 344, 856, 216, 728,
472, 984, 56, 568, 312, 824, 184, 696, 440, 952,
120, 632, 376, 888, 248, 760, 504, 1016, 4, 516,
260, 772, 132, 644, 388, 900, 68, 580, 324, 836,
196, 708, 452, 964, 36, 548, 292, 804, 164, 676,
420, 932, 100, 612, 356, 868, 228, 740, 484, 996,
20, 532, 276, 788, 148, 660, 404, 916, 84, 596,
340, 852, 212, 724, 468, 980, 52, 564, 308, 820,
180, 692, 436, 948, 116, 628, 372, 884, 244, 756,
500, 1012, 12, 524, 268, 780, 140, 652, 396, 908,
76, 588, 332, 844, 204, 716, 460, 972, 44, 556,
300, 812, 172, 684, 428, 940, 108, 620, 364, 876,
236, 748, 492, 1004, 28, 540, 284, 796, 156, 668,
412, 924, 92, 604, 348, 860, 220, 732, 476, 988,
60, 572, 316, 828, 188, 700, 444, 956, 124, 636,
380, 892, 252, 764, 508, 1020, 2, 514, 258, 770,
130, 642, 386, 898, 66, 578, 322, 834, 194, 706,
450, 962, 34, 546, 290, 802, 162, 674, 418, 930,
98, 610, 354, 866, 226, 738, 482, 994, 18, 530,
274, 786, 146, 658, 402, 914, 82, 594, 338, 850,
210, 722, 466, 978, 50, 562, 306, 818, 178, 690,
434, 946, 114, 626, 370, 882, 242, 754, 498, 1010,
10, 522, 266, 778, 138, 650, 394, 906, 74, 586,
330, 842, 202, 714, 458, 970, 42, 554, 298, 810,
170, 682, 426, 938, 106, 618, 362, 874, 234, 746,
490, 1002, 26, 538, 282, 794, 154, 666, 410, 922,
90, 602, 346, 858, 218, 730, 474, 986, 58, 570,
314, 826, 186, 698, 442, 954, 122, 634, 378, 890,
250, 762, 506, 1018, 6, 518, 262, 774, 134, 646,
390, 902, 70, 582, 326, 838, 198, 710, 454, 966,
38, 550, 294, 806, 166, 678, 422, 934, 102, 614,
358, 870, 230, 742, 486, 998, 22, 534, 278, 790,
150, 662, 406, 918, 86, 598, 342, 854, 214, 726,
470, 982, 54, 566, 310, 822, 182, 694, 438, 950,
118, 630, 374, 886, 246, 758, 502, 1014, 14, 526,
270, 782, 142, 654, 398, 910, 78, 590, 334, 846,
206, 718, 462, 974, 46, 558, 302, 814, 174, 686,
430, 942, 110, 622, 366, 878, 238, 750, 494, 1006,
30, 542, 286, 798, 158, 670, 414, 926, 94, 606,
350, 862, 222, 734, 478, 990, 62, 574, 318, 830,
190, 702, 446, 958, 126, 638, 382, 894, 254, 766,
510, 1022, 1, 513, 257, 769, 129, 641, 385, 897,
65, 577, 321, 833, 193, 705, 449, 961, 33, 545,
289, 801, 161, 673, 417, 929, 97, 609, 353, 865,
225, 737, 481, 993, 17, 529, 273, 785, 145, 657,
401, 913, 81, 593, 337, 849, 209, 721, 465, 977,
49, 561, 305, 817, 177, 689, 433, 945, 113, 625,
369, 881, 241, 753, 497, 1009, 9, 521, 265, 777,
137, 649, 393, 905, 73, 585, 329, 841, 201, 713,
457, 969, 41, 553, 297, 809, 169, 681, 425, 937,
105, 617, 361, 873, 233, 745, 489, 1001, 25, 537,
281, 793, 153, 665, 409, 921, 89, 601, 345, 857,
217, 729, 473, 985, 57, 569, 313, 825, 185, 697,
441, 953, 121, 633, 377, 889, 249, 761, 505, 1017,
5, 517, 261, 773, 133, 645, 389, 901, 69, 581,
325, 837, 197, 709, 453, 965, 37, 549, 293, 805,
165, 677, 421, 933, 101, 613, 357, 869, 229, 741,
485, 997, 21, 533, 277, 789, 149, 661, 405, 917,
85, 597, 341, 853, 213, 725, 469, 981, 53, 565,
309, 821, 181, 693, 437, 949, 117, 629, 373, 885,
245, 757, 501, 1013, 13, 525, 269, 781, 141, 653,
397, 909, 77, 589, 333, 845, 205, 717, 461, 973,
45, 557, 301, 813, 173, 685, 429, 941, 109, 621,
365, 877, 237, 749, 493, 1005, 29, 541, 285, 797,
157, 669, 413, 925, 93, 605, 349, 861, 221, 733,
477, 989, 61, 573, 317, 829, 189, 701, 445, 957,
125, 637, 381, 893, 253, 765, 509, 1021, 3, 515,
259, 771, 131, 643, 387, 899, 67, 579, 323, 835,
195, 707, 451, 963, 35, 547, 291, 803, 163, 675,
419, 931, 99, 611, 355, 867, 227, 739, 483, 995,
19, 531, 275, 787, 147, 659, 403, 915, 83, 595,
339, 851, 211, 723, 467, 979, 51, 563, 307, 819,
179, 691, 435, 947, 115, 627, 371, 883, 243, 755,
499, 1011, 11, 523, 267, 779, 139, 651, 395, 907,
75, 587, 331, 843, 203, 715, 459, 971, 43, 555,
299, 811, 171, 683, 427, 939, 107, 619, 363, 875,
235, 747, 491, 1003, 27, 539, 283, 795, 155, 667,
411, 923, 91, 603, 347, 859, 219, 731, 475, 987,
59, 571, 315, 827, 187, 699, 443, 955, 123, 635,
379, 891, 251, 763, 507, 1019, 7, 519, 263, 775,
135, 647, 391, 903, 71, 583, 327, 839, 199, 711,
455, 967, 39, 551, 295, 807, 167, 679, 423, 935,
103, 615, 359, 871, 231, 743, 487, 999, 23, 535,
279, 791, 151, 663, 407, 919, 87, 599, 343, 855,
215, 727, 471, 983, 55, 567, 311, 823, 183, 695,
439, 951, 119, 631, 375, 887, 247, 759, 503, 1015,
15, 527, 271, 783, 143, 655, 399, 911, 79, 591,
335, 847, 207, 719, 463, 975, 47, 559, 303, 815,
175, 687, 431, 943, 111, 623, 367, 879, 239, 751,
495, 1007, 31, 543, 287, 799, 159, 671, 415, 927,
95, 607, 351, 863, 223, 735, 479, 991, 63, 575,
319, 831, 191, 703, 447, 959, 127, 639, 383, 895,
255, 767, 511, 1023
};
const ntt_fft_params_t ntt_fft_12289_1024 = {
12289, 12287, 18, 3186, (1<<18)-1, 1024, 12277, 10,
wr_12289_1024, wf_12289_1024, wi_12289_1024, 1, rev_1024
};
/**
* FFT phase shift and scaling inverse transform for q = 12289 and n = 512
*/
static const uint16_t wi_12289_512[] = {
12265, 6771, 11424, 9011, 6203, 11914, 9021, 6454, 7154, 146,
11038, 4238, 5604, 10397, 11498, 3495, 7846, 7684, 1160, 4538,
845, 2776, 3317, 5836, 6389, 11667, 6508, 1136, 11309, 12269,
11787, 9520, 5461, 3121, 5832, 1373, 1282, 10058, 4218, 5102,
7628, 4670, 6616, 1389, 9057, 2442, 2307, 5063, 7878, 10945,
10506, 716, 767, 3276, 3578, 1327, 5043, 7376, 8176, 3678,
3837, 6599, 4649, 4860, 11385, 9261, 189, 3515, 8348, 10453,
7988, 1417, 7302, 1403, 2035, 8067, 2171, 6565, 11169, 8755,
4693, 10880, 2730, 7078, 3154, 10347, 10243, 2717, 3065, 9342,
3451, 1826, 4050, 3343, 1573, 6302, 881, 11053, 10759, 10753,
3229, 6085, 11410, 3744, 578, 12050, 7519, 3163, 9344, 5959,
874, 2275, 1802, 10821, 2478, 10584, 216, 506, 7785, 4924,
5618, 3375, 4834, 3359, 9348, 10975, 11259, 11014, 11009, 4739,
7119, 5412, 3120, 4578, 1849, 8314, 4684, 11883, 7014, 8921,
3944, 5598, 2873, 2065, 8820, 180, 4518, 343, 7, 8778,
8957, 12221, 751, 7790, 11194, 3238, 5082, 7126, 1901, 12077,
4510, 2600, 3815, 3589, 2832, 12096, 3758, 5845, 5386, 7383,
4665, 346, 3769, 7350, 150, 3765, 2334, 2054, 7315, 5416,
8136, 2674, 10588, 5232, 10891, 4235, 1842, 11825, 8016, 11951,
6263, 1131, 5039, 2360, 10080, 7228, 6919, 392, 8, 10032,
8481, 5189, 6125, 125, 9282, 1945, 5808, 8144, 417, 6780,
10421, 4727, 4360, 11124, 1481, 1535, 7806, 6680, 7911, 3171,
7087, 2151, 6063, 8400, 1927, 7814, 4423, 4103, 8360, 923,
2276, 3056, 10345, 7735, 3669, 4840, 10883, 6492, 5650, 6636,
1891, 11826, 9270, 11475, 11520, 6505, 9663, 448, 8787, 7954,
7937, 11197, 7000, 3654, 10608, 5734, 1371, 11063, 11010, 5993,
6643, 10669, 8494, 9202, 12226, 7021, 5410, 612, 5530, 3624,
9855, 7725, 3418, 9600, 7469, 1908, 8566, 1178, 2532, 4566,
11379, 1737, 3045, 8840, 682, 7287, 7171, 9175, 2946, 7584,
10939, 2982, 3572, 6092, 7899, 412, 510, 512, 3020, 2068,
293, 11041, 8000, 4176, 1590, 3042, 5078, 2110, 3805, 3338,
7592, 8682, 11463, 8761, 12217, 8024, 9694, 2455, 6320, 11164,
2485, 7073, 9173, 438, 8536, 425, 4523, 6613, 9916, 10485,
11249, 10763, 3480, 1325, 2535, 8328, 9951, 5219, 6878, 10423,
7235, 3408, 9349, 12229, 10783, 3982, 4094, 9363, 5207, 4119,
3846, 5596, 365, 3017, 10595, 1721, 7559, 4167, 2593, 7326,
6921, 2900, 11345, 8257, 6940, 2148, 2301, 9828, 10734, 3981,
2840, 9839, 12239, 11034, 11511, 7508, 1658, 2291, 9577, 3205,
567, 10545, 466, 6781, 11675, 4251, 9617, 4209, 6105, 11912,
6513, 7406, 8929, 1687, 1790, 8062, 8190, 8945, 9462, 6463,
6151, 8151, 9195, 3448, 10353, 5478, 12150, 10029, 4719, 6617,
2643, 8581, 7699, 7681, 9687, 5966, 9652, 11232, 1734, 11572,
10268, 9489, 3454, 5588, 2622, 6825, 5406, 7885, 7434, 7174,
648, 1518, 11066, 2483, 4565, 10125, 2213, 10077, 3466, 8347,
9199, 8464, 8449, 1928, 9068, 3947, 9360, 1445, 5547, 364,
1763, 11071, 8753, 2185, 11832, 4505, 8619, 6195, 1882, 540,
1265, 1029, 21, 1756, 2293, 12085, 2253, 11081, 9004, 9714,
2957, 9089, 5703, 11653, 1241, 7800, 11445, 10767, 8496, 11710,
11274, 5246, 3869, 9860, 1706, 1038, 11307, 9761, 450, 11295,
7002, 6162, 9656, 3959, 12119, 8022, 7186, 3407, 8095, 416,
5526, 10897, 11759, 11275, 6500, 3393, 2828, 7080, 5662, 9395,
8468, 1176
};
/**
* Bit-reversed indices for n = 512
*/
static const uint16_t rev_512[] = {
0, 256, 128, 384, 64, 320, 192, 448, 32, 288,
160, 416, 96, 352, 224, 480, 16, 272, 144, 400,
80, 336, 208, 464, 48, 304, 176, 432, 112, 368,
240, 496, 8, 264, 136, 392, 72, 328, 200, 456,
40, 296, 168, 424, 104, 360, 232, 488, 24, 280,
152, 408, 88, 344, 216, 472, 56, 312, 184, 440,
120, 376, 248, 504, 4, 260, 132, 388, 68, 324,
196, 452, 36, 292, 164, 420, 100, 356, 228, 484,
20, 276, 148, 404, 84, 340, 212, 468, 52, 308,
180, 436, 116, 372, 244, 500, 12, 268, 140, 396,
76, 332, 204, 460, 44, 300, 172, 428, 108, 364,
236, 492, 28, 284, 156, 412, 92, 348, 220, 476,
60, 316, 188, 444, 124, 380, 252, 508, 2, 258,
130, 386, 66, 322, 194, 450, 34, 290, 162, 418,
98, 354, 226, 482, 18, 274, 146, 402, 82, 338,
210, 466, 50, 306, 178, 434, 114, 370, 242, 498,
10, 266, 138, 394, 74, 330, 202, 458, 42, 298,
170, 426, 106, 362, 234, 490, 26, 282, 154, 410,
90, 346, 218, 474, 58, 314, 186, 442, 122, 378,
250, 506, 6, 262, 134, 390, 70, 326, 198, 454,
38, 294, 166, 422, 102, 358, 230, 486, 22, 278,
150, 406, 86, 342, 214, 470, 54, 310, 182, 438,
118, 374, 246, 502, 14, 270, 142, 398, 78, 334,
206, 462, 46, 302, 174, 430, 110, 366, 238, 494,
30, 286, 158, 414, 94, 350, 222, 478, 62, 318,
190, 446, 126, 382, 254, 510, 1, 257, 129, 385,
65, 321, 193, 449, 33, 289, 161, 417, 97, 353,
225, 481, 17, 273, 145, 401, 81, 337, 209, 465,
49, 305, 177, 433, 113, 369, 241, 497, 9, 265,
137, 393, 73, 329, 201, 457, 41, 297, 169, 425,
105, 361, 233, 489, 25, 281, 153, 409, 89, 345,
217, 473, 57, 313, 185, 441, 121, 377, 249, 505,
5, 261, 133, 389, 69, 325, 197, 453, 37, 293,
165, 421, 101, 357, 229, 485, 21, 277, 149, 405,
85, 341, 213, 469, 53, 309, 181, 437, 117, 373,
245, 501, 13, 269, 141, 397, 77, 333, 205, 461,
45, 301, 173, 429, 109, 365, 237, 493, 29, 285,
157, 413, 93, 349, 221, 477, 61, 317, 189, 445,
125, 381, 253, 509, 3, 259, 131, 387, 67, 323,
195, 451, 35, 291, 163, 419, 99, 355, 227, 483,
19, 275, 147, 403, 83, 339, 211, 467, 51, 307,
179, 435, 115, 371, 243, 499, 11, 267, 139, 395,
75, 331, 203, 459, 43, 299, 171, 427, 107, 363,
235, 491, 27, 283, 155, 411, 91, 347, 219, 475,
59, 315, 187, 443, 123, 379, 251, 507, 7, 263,
135, 391, 71, 327, 199, 455, 39, 295, 167, 423,
103, 359, 231, 487, 23, 279, 151, 407, 87, 343,
215, 471, 55, 311, 183, 439, 119, 375, 247, 503,
15, 271, 143, 399, 79, 335, 207, 463, 47, 303,
175, 431, 111, 367, 239, 495, 31, 287, 159, 415,
95, 351, 223, 479, 63, 319, 191, 447, 127, 383,
255, 511
};
const ntt_fft_params_t ntt_fft_12289_512 = {
12289, 12287, 18, 3186, (1<<18)-1, 512, 12265, 9,
wr_12289_1024, wf_12289_1024, wi_12289_512, 2, rev_512
};
/**
* FFT twiddle factors in Montgomery form for q = 17 and n = 8
*/
static const uint16_t wr_17_8[] = { 15, 16, 8, 4, 2, 1, 9, 13, 15 };
/**
* FFT phase shift in forward transform for q = 17 and n = 8
*/
static const uint16_t wf_17_8[] = { 4, 12, 2, 6, 1, 3, 9, 10 };
/**
* FFT phase shift and scaling inverse transform for q = 17 and n = 8
*/
static const uint16_t wi_17_8[] = { 15, 5, 13, 10, 9, 3, 1, 6 };
/**
* Bit-reversed indices for n = 8
*/
static const uint16_t rev_8[] = { 0, 4, 2, 6, 1, 5, 3, 7 };
const ntt_fft_params_t ntt_fft_17_8 = {
17, 15, 5, 4, (1<<5)-1, 8, 15, 3, wr_17_8, wf_17_8, wi_17_8, 1, rev_8
};
@@ -0,0 +1,115 @@
/*
* Copyright (C) 2014-2016 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.
*/
/**
* @defgroup ntt_fft_params ntt_fft_params
* @{ @ingroup ntt_p
*/
#ifndef NTT_FFT_PARAMS_H_
#define NTT_FFT_PARAMS_H_
#include <library.h>
typedef struct ntt_fft_params_t ntt_fft_params_t;
/**
* Defines the parameters for an NTT computed via the FFT algorithm
*/
struct ntt_fft_params_t {
/**
* Prime modulus
*/
uint16_t q;
/**
* Inverse of Prime modulus (-q_inv * q mod r = 1)
*/
uint16_t q_inv;
/**
* Logarithm of Montgomery radix: log2(r)
*/
uint16_t rlog;
/**
* Square of Montgomery radix: r^2 mod q
*/
const uint32_t r2;
/**
* Montgomery radix mask: (1<<rlog) - 1
*/
const uint32_t rmask;
/**
* Size of the FFT with the condition k * n = q-1
*/
const uint16_t n;
/**
* Inverse of n mod q used for normalization of the FFT
*/
const uint16_t n_inv;
/**
* Number of FFT stages stages = log2(n)
*/
const uint16_t stages;
/**
* FFT twiddle factors (n-th roots of unity) in Montgomery form
*/
const uint16_t *wr;
/**
* FFT phase shift (2n-th roots of unity) in forward transform
*/
const uint16_t *wf;
/**
* FFT phase shift (2n-th roots of unity) and scaling in inverse transform
*/
const uint16_t *wi;
/**
* Subsampling of FFT twiddle factors table
*/
const uint16_t s;
/**
* FFT bit reversal
*/
const uint16_t *rev;
};
/**
* FFT parameters for q = 12289 and n = 1024
*/
extern const ntt_fft_params_t ntt_fft_12289_1024;
/**
* FFT parameters for q = 12289 and n = 512
*/
extern const ntt_fft_params_t ntt_fft_12289_512;
/**
* FFT parameters for q = 17 and n = 8
*/
extern const ntt_fft_params_t ntt_fft_17_8;
#endif /** NTT_FFT_PARAMS_H_ @}*/
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2016 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.
*/
/**
* @defgroup ntt_fft ntt_fft
* @{ @ingroup ntt_p
*/
#ifndef NTT_REDUCE_H_
#define NTT_REDUCE_H_
#include "ntt_fft_params.h"
/**
* Montgomery Reduction
*
* Montgomery, P. L. Modular multiplication without trial division.
* Mathematics of Computation 44, 170 (1985), 519521.
*/
static inline uint32_t ntt_fft_mreduce(uint32_t x, const ntt_fft_params_t *p)
{
uint32_t m, t;
m = (x * p->q_inv) & p->rmask;
t = (x + m * p->q) >> p->rlog;
return (t < p->q) ? t : t - p->q;
}
#endif /** NTT_REDUCE_H_ @}*/
@@ -0,0 +1 @@
ntt_fft_tests
@@ -0,0 +1,21 @@
TESTS = ntt_fft_tests
check_PROGRAMS = $(TESTS)
ntt_fft_tests_SOURCES = \
suites/test_ntt_fft.c \
ntt_fft_tests.h ntt_fft_tests.c
ntt_fft_tests_CFLAGS = \
-I$(top_srcdir)/src/libstrongswan \
-I$(top_srcdir)/src/libstrongswan/tests \
-I$(top_srcdir)/src/libstrongswan/math/libnttfft \
-DPLUGINDIR=\""$(abs_top_builddir)/src/libstrongswan/plugins\"" \
-DPLUGINS=\""${s_plugins}\"" \
@COVERAGE_CFLAGS@
ntt_fft_tests_LDFLAGS = @COVERAGE_LDFLAGS@
ntt_fft_tests_LDADD = \
$(top_builddir)/src/libstrongswan/libstrongswan.la \
$(top_builddir)/src/libstrongswan/tests/libtest.la \
../libnttfft.la
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2016 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 "ntt_fft_tests.h"
#undef TEST_SUITE
static test_configuration_t tests[] = {
#define TEST_SUITE(x) \
{ .suite = x, },
#include "ntt_fft_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("ntt_fft", tests, test_runner_init);
}
@@ -0,0 +1,17 @@
/*
* Copyright (C) 2016 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(ntt_fft_suite_create)
@@ -15,19 +15,22 @@
#include "test_suite.h"
#include <bliss_fft.h>
#include <ntt_fft.h>
#include <ntt_fft_reduce.h>
#include <time.h>
static bliss_fft_params_t *fft_params[] = {
&bliss_fft_17_8,
&bliss_fft_12289_512
static const ntt_fft_params_t *fft_params[] = {
&ntt_fft_17_8,
&ntt_fft_12289_512,
&ntt_fft_12289_1024
};
START_TEST(test_bliss_fft_impulse)
START_TEST(test_ntt_fft_impulse)
{
bliss_fft_t *fft;
ntt_fft_t *fft;
uint16_t n = fft_params[_i]->n;
uint32_t rq = (1 << fft_params[_i]->rlog) % fft_params[_i]->q;
uint32_t x[n], X[n];
int i;
@@ -37,12 +40,12 @@ START_TEST(test_bliss_fft_impulse)
}
x[0] = 1;
fft = bliss_fft_create(fft_params[_i]);
fft = ntt_fft_create(fft_params[_i]);
fft->transform(fft, x, X, FALSE);
for (i = 0; i < n; i++)
{
ck_assert(X[i] == 1);
ck_assert(X[i] == rq);
}
fft->transform(fft, X, x, TRUE);
@@ -54,9 +57,9 @@ START_TEST(test_bliss_fft_impulse)
}
END_TEST
START_TEST(test_bliss_fft_wrap)
START_TEST(test_ntt_fft_wrap)
{
bliss_fft_t *fft;
ntt_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];
@@ -67,7 +70,7 @@ START_TEST(test_bliss_fft_wrap)
x[i] = i;
y[i] = 0;
}
fft = bliss_fft_create(fft_params[_i]);
fft = ntt_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);
@@ -79,7 +82,7 @@ START_TEST(test_bliss_fft_wrap)
for (i = 0; i < n; i++)
{
Y[i] = (X[i] * Y[i]) % q;
Y[i] = ntt_fft_mreduce(X[i] * Y[i], fft_params[_i]);
}
fft->transform(fft, Y, Y, TRUE);
@@ -93,19 +96,19 @@ START_TEST(test_bliss_fft_wrap)
}
END_TEST
START_TEST(test_bliss_fft_speed)
START_TEST(test_ntt_fft_speed)
{
bliss_fft_t *fft;
ntt_fft_t *fft;
struct timespec start, stop;
uint16_t n = bliss_fft_12289_512.n;
uint32_t x[n], X[n];
int i, m, count = 10000;
int n = fft_params[_i]->n;
uint32_t x[n], X[n];
for (i = 0; i < n; i++)
{
x[i] = i;
}
fft = bliss_fft_create(&bliss_fft_12289_512);
fft = ntt_fft_create(fft_params[_i]);
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &start);
for (m = 0; m < count; m++)
@@ -115,7 +118,7 @@ START_TEST(test_bliss_fft_speed)
}
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &stop);
DBG0(DBG_LIB, "%d FFT loops in %d ms\n", count,
DBG0(DBG_LIB, "%d FFT-%d loops in %d ms\n", count, n,
(stop.tv_nsec - start.tv_nsec) / 1000000 +
(stop.tv_sec - start.tv_sec) * 1000);
@@ -127,24 +130,24 @@ START_TEST(test_bliss_fft_speed)
}
END_TEST
Suite *bliss_fft_suite_create()
Suite *ntt_fft_suite_create()
{
Suite *s;
TCase *tc;
s = suite_create("bliss_fft");
s = suite_create("ntt_fft");
tc = tcase_create("impulse");
tcase_add_loop_test(tc, test_bliss_fft_impulse, 0, countof(fft_params));
tcase_add_loop_test(tc, test_ntt_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));
tcase_add_loop_test(tc, test_ntt_fft_wrap, 0, countof(fft_params));
suite_add_tcase(s, tc);
tc = tcase_create("speed");
tcase_set_timeout(tc, 10);
tcase_add_test(tc, test_bliss_fft_speed);
tcase_add_loop_test(tc, test_ntt_fft_speed, 1, countof(fft_params));
suite_add_tcase(s, tc);
return s;
+15 -6
View File
@@ -1,5 +1,6 @@
AM_CPPFLAGS = \
-I$(top_srcdir)/src/libstrongswan
-I$(top_srcdir)/src/libstrongswan \
-I$(top_srcdir)/src/libstrongswan/math/libnttfft
AM_CFLAGS = \
$(PLUGIN_CFLAGS) \
@@ -7,9 +8,12 @@ AM_CFLAGS = \
# 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
bliss_param_set.h bliss_param_set.c
libbliss_params_la_LIBADD = \
$(top_builddir)/src/libstrongswan/math/libnttfft/libnttfft.la
# 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
@@ -20,12 +24,14 @@ libbliss_la_SOURCES = \
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_huffman_code.h bliss_huffman_code.c \
bliss_huffman_code_1.c bliss_huffman_code_3.c bliss_huffman_code_4.c \
bliss_huffman_coder.h bliss_huffman_coder.c \
bliss_sampler.h bliss_sampler.c
libbliss_la_LIBADD = libbliss-params.la
libbliss_la_LIBADD = \
$(top_builddir)/src/libstrongswan/math/libnttfft/libnttfft.la \
libbliss-params.la
if MONOLITHIC
noinst_LTLIBRARIES += libstrongswan-bliss.la
@@ -43,7 +49,10 @@ libstrongswan_bliss_la_LIBADD = libbliss.la
noinst_PROGRAMS = bliss_huffman
bliss_huffman_SOURCES = bliss_huffman.c
bliss_huffman_LDADD = -lm libbliss-params.la
bliss_huffman_LDADD = -lm \
$(top_builddir)/src/libstrongswan/math/libnttfft/libnttfft.la \
libbliss-params.la
recreate-bliss-huffman : bliss_huffman bliss_huffman_code.h
$(AM_V_GEN) \
@@ -1,215 +0,0 @@
/*
* 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 "bliss_fft_params.h"
/**
* FFT parameters for q = 12289 and 2n = 1024
*/
static uint16_t w_12289_1024[] = {
1, 49, 2401, 7048, 1260, 295, 2166, 7822, 2319, 3030,
1002, 12231, 9447, 8210, 9042, 654, 7468, 9551, 1017, 677,
8595, 3329, 3364, 5079, 3091, 3991, 11224, 9260, 11336, 2459,
9890, 5339, 3542, 1512, 354, 5057, 2013, 325, 3636, 6118,
4846, 3963, 9852, 3477, 10616, 4046, 1630, 6136, 5728, 10314,
1537, 1579, 3637, 6167, 7247, 11011, 11112, 3772, 493, 11868,
3949, 9166, 6730, 10256, 10984, 9789, 390, 6821, 2426, 8273,
12129, 4449, 9088, 2908, 7313, 1956, 9821, 1958, 9919, 6760,
11726, 9280, 27, 1323, 3382, 5961, 9442, 7965, 9326, 2281,
1168, 8076, 2476, 10723, 9289, 468, 10643, 5369, 5012, 12097,
2881, 5990, 10863, 3860, 4805, 1954, 9723, 9445, 8112, 4240,
11136, 4948, 8961, 8974, 9611, 3957, 9558, 1360, 5195, 8775,
12149, 5429, 7952, 8689, 7935, 7856, 3985, 10930, 7143, 5915,
7188, 8120, 4632, 5766, 12176, 6752, 11334, 2361, 5088, 3532,
1022, 922, 8311, 1702, 9664, 6554, 1632, 6234, 10530, 12121,
4057, 2169, 7969, 9522, 11885, 4782, 827, 3656, 7098, 3710,
9744, 10474, 9377, 4780, 729, 11143, 5291, 1190, 9154, 6142,
6022, 142, 6958, 9139, 5407, 6874, 5023, 347, 4714, 9784,
145, 7105, 4053, 1973, 10654, 5908, 6845, 3602, 4452, 9235,
10111, 3879, 5736, 10706, 8456, 8807, 1428, 8527, 12286, 12142,
5086, 3434, 8509, 11404, 5791, 1112, 5332, 3199, 9283, 174,
8526, 12237, 9741, 10327, 2174, 8214, 9238, 10258, 11082, 2302,
2197, 9341, 3016, 316, 3195, 9087, 2859, 4912, 7197, 8561,
1663, 7753, 11227, 9407, 6250, 11314, 1381, 6224, 10040, 400,
7311, 1858, 5019, 151, 7399, 6170, 7394, 5925, 7678, 7552,
1378, 6077, 2837, 3834, 3531, 973, 10810, 1263, 442, 9369,
4388, 6099, 3915, 7500, 11119, 4115, 5011, 12048, 480, 11231,
9603, 3565, 2639, 6421, 7404, 6415, 7110, 4298, 1689, 9027,
12208, 8320, 2143, 6695, 8541, 683, 8889, 5446, 8785, 350,
4861, 4698, 9000, 10885, 4938, 8471, 9542, 576, 3646, 6608,
4278, 709, 10163, 6427, 7698, 8532, 242, 11858, 3459, 9734,
9984, 9945, 8034, 418, 8193, 8209, 8993, 10542, 420, 8291,
722, 10800, 773, 1010, 334, 4077, 3149, 6833, 3014, 218,
10682, 7280, 339, 4322, 2865, 5206, 9314, 1693, 9223, 9523,
11934, 7183, 7875, 4916, 7393, 5876, 5277, 504, 118, 5782,
671, 8301, 1212, 10232, 9808, 1321, 3284, 1159, 7635, 5445,
8736, 10238, 10102, 3438, 8705, 8719, 9405, 6152, 6512, 11863,
3704, 9450, 8357, 3956, 9509, 11248, 10436, 7515, 11854, 3263,
130, 6370, 4905, 6854, 4043, 1483, 11222, 9162, 6534, 652,
7370, 4749, 11499, 10446, 8005, 11286, 9, 441, 9320, 1987,
11340, 2655, 7205, 8953, 8582, 2692, 9018, 11767, 11289, 156,
7644, 5886, 5767, 12225, 9153, 6093, 3621, 5383, 5698, 8844,
3241, 11341, 2704, 9606, 3712, 9842, 2987, 11184, 7300, 1319,
3186, 8646, 5828, 2925, 8146, 5906, 6747, 11089, 2645, 6715,
9521, 11836, 2381, 6068, 2396, 6803, 1544, 1922, 8155, 6347,
3778, 787, 1696, 9370, 4437, 8500, 10963, 8760, 11414, 6281,
544, 2078, 3510, 12233, 9545, 723, 10849, 3174, 8058, 1594,
4372, 5315, 2366, 5333, 3248, 11684, 7222, 9786, 243, 11907,
5860, 4493, 11244, 10240, 10200, 8240, 10512, 11239, 9995, 10484,
9867, 4212, 9764, 11454, 8241, 10561, 1351, 4754, 11744, 10162,
6378, 5297, 1484, 11271, 11563, 1293, 1912, 7665, 6915, 7032,
476, 11035, 12288, 12240, 9888, 5241, 11029, 11994, 10123, 4467,
9970, 9259, 11287, 58, 2842, 4079, 3247, 11635, 4821, 2738,
11272, 11612, 3694, 8960, 8925, 7210, 9198, 8298, 1065, 3029,
953, 9830, 2399, 6950, 8747, 10777, 11935, 7232, 10276, 11964,
8653, 6171, 7443, 8326, 2437, 8812, 1673, 8243, 10659, 6153,
6561, 1975, 10752, 10710, 8652, 6122, 5042, 1278, 1177, 8517,
11796, 421, 8340, 3123, 5559, 2033, 1305, 2500, 11899, 5468,
9863, 4016, 160, 7840, 3201, 9381, 4976, 10333, 2468, 10331,
2370, 5529, 563, 3009, 12262, 10966, 8907, 6328, 2847, 4324,
2963, 10008, 11121, 4213, 9813, 1566, 3000, 11821, 1646, 6920,
7277, 192, 9408, 6299, 1426, 8429, 7484, 10335, 2566, 2844,
4177, 8049, 1153, 7341, 3328, 3315, 2678, 8332, 2731, 10929,
7094, 3514, 140, 6860, 4337, 3600, 4354, 4433, 8304, 1359,
5146, 6374, 5101, 4169, 7657, 6523, 113, 5537, 955, 9928,
7201, 8757, 11267, 11367, 3978, 10587, 2625, 5735, 10657, 6055,
1759, 168, 8232, 10120, 4320, 2767, 404, 7507, 11462, 8633,
5191, 8579, 2545, 1815, 2912, 7509, 11560, 1146, 6998, 11099,
3135, 6147, 6267, 12147, 5331, 3150, 6882, 5415, 7266, 11942,
7575, 2505, 12144, 5184, 8236, 10316, 1635, 6381, 5444, 8687,
7837, 3054, 2178, 8410, 6553, 1583, 3833, 3482, 10861, 3762,
3, 147, 7203, 8855, 3780, 885, 6498, 11177, 6957, 9090,
3006, 12115, 3763, 52, 2548, 1962, 10115, 4075, 3051, 2031,
1207, 9987, 10092, 2948, 9273, 11973, 9094, 3202, 9430, 7377,
5092, 3728, 10626, 4536, 1062, 2882, 6039, 975, 10908, 6065,
2249, 11889, 4978, 10431, 7270, 12138, 4890, 6119, 4895, 6364,
4611, 4737, 10911, 6212, 9452, 8455, 8758, 11316, 1479, 11026,
11847, 2920, 7901, 6190, 8374, 4789, 1170, 8174, 7278, 241,
11809, 1058, 2686, 8724, 9650, 5868, 4885, 5874, 5179, 7991,
10600, 3262, 81, 3969, 10146, 5594, 3748, 11606, 3400, 6843,
3504, 11939, 7428, 7591, 3289, 1404, 7351, 3818, 2747, 11713,
8643, 5681, 8011, 11580, 2126, 5862, 4591, 3757, 12047, 431,
8830, 2555, 2305, 2344, 4255, 11871, 4096, 4080, 3296, 1747,
11869, 3998, 11567, 1489, 11516, 11279, 11955, 8212, 9140, 5456,
9275, 12071, 1607, 5009, 11950, 7967, 9424, 7083, 2975, 10596,
3066, 2766, 355, 5106, 4414, 7373, 4896, 6413, 7012, 11785,
12171, 6507, 11618, 3988, 11077, 2057, 2481, 10968, 9005, 11130,
4654, 6844, 3553, 2051, 2187, 8851, 3584, 3570, 2884, 6137,
5777, 426, 8585, 2839, 3932, 8333, 2780, 1041, 1853, 4774,
435, 9026, 12159, 5919, 7384, 5435, 8246, 10806, 1067, 3127,
5755, 11637, 4919, 7540, 790, 1843, 4284, 1003, 12280, 11848,
2969, 10302, 949, 9634, 5084, 3336, 3707, 9597, 3271, 522,
1000, 12133, 4645, 6403, 6522, 64, 3136, 6196, 8668, 6906,
6591, 3445, 9048, 948, 9585, 2683, 8577, 2447, 9302, 1105,
4989, 10970, 9103, 3643, 6461, 9364, 4143, 6383, 5542, 1200,
9644, 5574, 2768, 453, 9908, 6221, 9893, 5486, 10745, 10367,
4134, 5942, 8511, 11502, 10593, 2919, 7852, 3789, 1326, 3529,
875, 6008, 11745, 10211, 8779, 56, 2744, 11566, 1440, 9115,
4231, 10695, 7917, 6974, 9923, 6956, 9041, 605, 5067, 2503,
12046, 382, 6429, 7796, 1045, 2049, 2089, 4049, 1777, 1050,
2294, 1805, 2422, 8077, 2525, 835, 4048, 1728, 10938, 7535,
545, 2127, 5911, 6992, 10805, 1018, 726, 10996, 10377, 4624,
5374, 5257, 11813, 1254, 1
};
/**
* Bit-reversed indices for n = 512
*/
static uint16_t rev_512[] = {
0, 256, 128, 384, 64, 320, 192, 448, 32, 288,
160, 416, 96, 352, 224, 480, 16, 272, 144, 400,
80, 336, 208, 464, 48, 304, 176, 432, 112, 368,
240, 496, 8, 264, 136, 392, 72, 328, 200, 456,
40, 296, 168, 424, 104, 360, 232, 488, 24, 280,
152, 408, 88, 344, 216, 472, 56, 312, 184, 440,
120, 376, 248, 504, 4, 260, 132, 388, 68, 324,
196, 452, 36, 292, 164, 420, 100, 356, 228, 484,
20, 276, 148, 404, 84, 340, 212, 468, 52, 308,
180, 436, 116, 372, 244, 500, 12, 268, 140, 396,
76, 332, 204, 460, 44, 300, 172, 428, 108, 364,
236, 492, 28, 284, 156, 412, 92, 348, 220, 476,
60, 316, 188, 444, 124, 380, 252, 508, 2, 258,
130, 386, 66, 322, 194, 450, 34, 290, 162, 418,
98, 354, 226, 482, 18, 274, 146, 402, 82, 338,
210, 466, 50, 306, 178, 434, 114, 370, 242, 498,
10, 266, 138, 394, 74, 330, 202, 458, 42, 298,
170, 426, 106, 362, 234, 490, 26, 282, 154, 410,
90, 346, 218, 474, 58, 314, 186, 442, 122, 378,
250, 506, 6, 262, 134, 390, 70, 326, 198, 454,
38, 294, 166, 422, 102, 358, 230, 486, 22, 278,
150, 406, 86, 342, 214, 470, 54, 310, 182, 438,
118, 374, 246, 502, 14, 270, 142, 398, 78, 334,
206, 462, 46, 302, 174, 430, 110, 366, 238, 494,
30, 286, 158, 414, 94, 350, 222, 478, 62, 318,
190, 446, 126, 382, 254, 510, 1, 257, 129, 385,
65, 321, 193, 449, 33, 289, 161, 417, 97, 353,
225, 481, 17, 273, 145, 401, 81, 337, 209, 465,
49, 305, 177, 433, 113, 369, 241, 497, 9, 265,
137, 393, 73, 329, 201, 457, 41, 297, 169, 425,
105, 361, 233, 489, 25, 281, 153, 409, 89, 345,
217, 473, 57, 313, 185, 441, 121, 377, 249, 505,
5, 261, 133, 389, 69, 325, 197, 453, 37, 293,
165, 421, 101, 357, 229, 485, 21, 277, 149, 405,
85, 341, 213, 469, 53, 309, 181, 437, 117, 373,
245, 501, 13, 269, 141, 397, 77, 333, 205, 461,
45, 301, 173, 429, 109, 365, 237, 493, 29, 285,
157, 413, 93, 349, 221, 477, 61, 317, 189, 445,
125, 381, 253, 509, 3, 259, 131, 387, 67, 323,
195, 451, 35, 291, 163, 419, 99, 355, 227, 483,
19, 275, 147, 403, 83, 339, 211, 467, 51, 307,
179, 435, 115, 371, 243, 499, 11, 267, 139, 395,
75, 331, 203, 459, 43, 299, 171, 427, 107, 363,
235, 491, 27, 283, 155, 411, 91, 347, 219, 475,
59, 315, 187, 443, 123, 379, 251, 507, 7, 263,
135, 391, 71, 327, 199, 455, 39, 295, 167, 423,
103, 359, 231, 487, 23, 279, 151, 407, 87, 343,
215, 471, 55, 311, 183, 439, 119, 375, 247, 503,
15, 271, 143, 399, 79, 335, 207, 463, 47, 303,
175, 431, 111, 367, 239, 495, 31, 287, 159, 415,
95, 351, 223, 479, 63, 319, 191, 447, 127, 383,
255, 511
};
bliss_fft_params_t bliss_fft_12289_512 = {
12289, 512, 12265, 9, w_12289_1024, rev_512
};
/**
* FFT parameters for q = 17 and n = 16
*/
static uint16_t w_17_16[] = {
1, 3, 9, 10, 13, 5, 15, 11, 16, 14, 8, 7, 4, 12, 2, 6, 1 };
/**
* Bit-reversed indices for n = 8
*/
static uint16_t rev_8[] = { 0, 4, 2, 6, 1, 5, 3, 7 };
bliss_fft_params_t bliss_fft_17_8 = { 17, 8, 15, 3, w_17_16, rev_8 };
@@ -1,75 +0,0 @@
/*
* 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.
*/
/**
* @defgroup bliss_fft_params bliss_fft_params
* @{ @ingroup bliss_p
*/
#ifndef BLISS_FFT_PARAMS_H_
#define BLISS_FFT_PARAMS_H_
#include <library.h>
typedef struct bliss_fft_params_t bliss_fft_params_t;
/**
* Defines the parameters for an NTT computed via the FFT algorithm
*/
struct bliss_fft_params_t {
/**
* Prime modulus
*/
uint16_t q;
/**
* Size of the FFT with the condition k * n = q-1
*/
uint16_t n;
/**
* Inverse of n mod q used for normalization of the FFT
*/
uint16_t n_inv;
/**
* Number of FFT stages stages = log2(n)
*/
uint16_t stages;
/**
* FFT twiddle factors (n-th roots of unity)
*/
uint16_t *w;
/**
* FFT bit reversal
*/
uint16_t *rev;
};
/**
* FFT parameters for q = 12289 and n = 512
*/
extern bliss_fft_params_t bliss_fft_12289_512;
/**
* FFT parameters for q = 17 and n = 8
*/
extern bliss_fft_params_t bliss_fft_17_8;
#endif /** BLISS_FFT_PARAMS_H_ @}*/
@@ -209,7 +209,7 @@ static void remove_node(node_t *list, node_t **last, node_t *node)
*/
int main(int argc, char *argv[])
{
bliss_param_set_t *set;
const 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;
@@ -33,7 +33,7 @@ ENUM(bliss_param_set_id_names, BLISS_I, BLISS_B_IV,
*
* c[i] = exp(-2^i/f), i = 0..20, with f = k_sigma^2 / ln 2 = 93'076.9
*/
static uint8_t c_bliss_i[] = {
static const uint8_t c_bliss_i[] = {
255, 255, 75, 191, 247, 94, 30, 51, 147, 246, 89, 59, 99, 248, 26, 128,
255, 254, 151, 128, 109, 166, 88, 143, 30, 175, 149, 20, 240, 81, 138, 111,
255, 253, 47, 2, 214, 243, 188, 76, 236, 235, 40, 62, 54, 35, 33, 205,
@@ -62,7 +62,7 @@ static uint8_t c_bliss_i[] = {
*
* c[i] = exp(-2^i/f), i = 0..20, with f = k_sigma^2 / ln 2 = 125'550.5
*/
static uint8_t c_bliss_iii[] = {
static const uint8_t c_bliss_iii[] = {
255, 255, 122, 95, 16, 128, 14, 195, 60, 90, 166, 191, 205, 26, 144, 204,
255, 254, 244, 190, 102, 192, 187, 141, 169, 92, 33, 30, 170, 141, 184, 56,
255, 253, 233, 125, 228, 131, 93, 148, 121, 92, 52, 122, 149, 96, 29, 66,
@@ -91,7 +91,7 @@ static uint8_t c_bliss_iii[] = {
*
* c[i] = exp(-2^i/f), i = 0..21, with f = k_sigma^2 / ln 2 = 147'732.0
*/
static uint8_t c_bliss_iv[] = {
static const uint8_t c_bliss_iv[] = {
255, 255, 142, 111, 102, 2, 141, 87, 150, 42, 18, 70, 6, 224, 18, 70,
255, 255, 28, 222, 254, 102, 20, 78, 133, 78, 189, 107, 29, 7, 23, 193,
255, 254, 57, 190, 198, 79, 181, 181, 108, 75, 142, 145, 45, 238, 193, 29,
@@ -119,7 +119,7 @@ static uint8_t c_bliss_iv[] = {
/**
* BLISS signature parameter set definitions
*/
static bliss_param_set_t bliss_param_sets[] = {
static const bliss_param_set_t bliss_param_sets[] = {
/* BLISS-I scheme */
{
@@ -131,7 +131,7 @@ static bliss_param_set_t bliss_param_sets[] = {
.q2_inv = 6145,
.n = 512,
.n_bits = 9,
.fft_params = &bliss_fft_12289_512,
.fft_params = &ntt_fft_12289_512,
.non_zero1 = 154,
.non_zero2 = 0,
.kappa = 23,
@@ -161,7 +161,7 @@ static bliss_param_set_t bliss_param_sets[] = {
.q2_inv = 6145,
.n = 512,
.n_bits = 9,
.fft_params = &bliss_fft_12289_512,
.fft_params = &ntt_fft_12289_512,
.non_zero1 = 216,
.non_zero2 = 16,
.kappa = 30,
@@ -191,7 +191,7 @@ static bliss_param_set_t bliss_param_sets[] = {
.q2_inv = 6145,
.n = 512,
.n_bits = 9,
.fft_params = &bliss_fft_12289_512,
.fft_params = &ntt_fft_12289_512,
.non_zero1 = 231,
.non_zero2 = 31,
.kappa = 39,
@@ -221,7 +221,7 @@ static bliss_param_set_t bliss_param_sets[] = {
.q2_inv = 6145,
.n = 512,
.n_bits = 9,
.fft_params = &bliss_fft_12289_512,
.fft_params = &ntt_fft_12289_512,
.non_zero1 = 154,
.non_zero2 = 0,
.kappa = 23,
@@ -251,7 +251,7 @@ static bliss_param_set_t bliss_param_sets[] = {
.q2_inv = 6145,
.n = 512,
.n_bits = 9,
.fft_params = &bliss_fft_12289_512,
.fft_params = &ntt_fft_12289_512,
.non_zero1 = 216,
.non_zero2 = 16,
.kappa = 30,
@@ -281,7 +281,7 @@ static bliss_param_set_t bliss_param_sets[] = {
.q2_inv = 6145,
.n = 512,
.n_bits = 9,
.fft_params = &bliss_fft_12289_512,
.fft_params = &ntt_fft_12289_512,
.non_zero1 = 231,
.non_zero2 = 31,
.kappa = 39,
@@ -306,7 +306,7 @@ static bliss_param_set_t bliss_param_sets[] = {
/**
* See header.
*/
bliss_param_set_t* bliss_param_set_get_by_id(bliss_param_set_id_t id)
const bliss_param_set_t* bliss_param_set_get_by_id(bliss_param_set_id_t id)
{
int i;
@@ -324,7 +324,7 @@ bliss_param_set_t* bliss_param_set_get_by_id(bliss_param_set_id_t id)
/**
* See header.
*/
bliss_param_set_t* bliss_param_set_get_by_oid(int oid)
const bliss_param_set_t* bliss_param_set_get_by_oid(int oid)
{
int i;
@@ -24,7 +24,7 @@
typedef enum bliss_param_set_id_t bliss_param_set_id_t;
typedef struct bliss_param_set_t bliss_param_set_t;
#include "bliss_fft_params.h"
#include "ntt_fft_params.h"
#include "bliss_huffman_code.h"
#include <library.h>
@@ -53,132 +53,132 @@ struct bliss_param_set_t {
/**
* BLISS parameter set ID
*/
bliss_param_set_id_t id;
const bliss_param_set_id_t id;
/**
* BLISS parameter set OID
*/
int oid;
const int oid;
/**
* Security strength in bits
*/
uint16_t strength;
const uint16_t strength;
/**
* Prime modulus
*/
uint16_t q;
const uint16_t q;
/**
* Number of bits in q
*/
uint16_t q_bits;
const uint16_t q_bits;
/**
* Inverse of (q + 2) mod 2q
*/
uint16_t q2_inv;
const uint16_t q2_inv;
/**
* Ring dimension equal to the number of polynomial coefficients
*/
uint16_t n;
const uint16_t n;
/**
* Number of bits in n
*/
uint16_t n_bits;
const uint16_t n_bits;
/**
* FFT parameters
*/
bliss_fft_params_t *fft_params;
const ntt_fft_params_t *fft_params;
/**
* Number of [-1, +1] secret key coefficients
*/
uint16_t non_zero1;
const uint16_t non_zero1;
/**
* Number of [-2, +2] secret key coefficients
*/
uint16_t non_zero2;
const uint16_t non_zero2;
/**
* Number of secret key terms that go into Nk(S) norm
*/
uint16_t kappa;
const uint16_t kappa;
/**
* Maximum Nk(S) tolerable NK(S) norm (BLISS only)
*/
uint32_t nks_max;
const uint32_t nks_max;
/**
* Maximum value Pmax for ||Sc'||^2 norm (BLISS-B only)
*/
uint32_t p_max;
const uint32_t p_max;
/**
* Standard deviation sigma
*/
uint16_t sigma;
const uint16_t sigma;
/**
* k_sigma = ceiling[ sqrt(2*ln 2) * sigma ]
*/
uint16_t k_sigma;
const uint16_t k_sigma;
/**
* Number of bits in k_sigma
*/
uint16_t k_sigma_bits;
const uint16_t k_sigma_bits;
/**
* Coefficients for Bernoulli sampling with exponential biases
*/
uint8_t *c;
const uint8_t *c;
/**
* Number of columns in Bernoulli coefficient table
*/
size_t c_cols;
const size_t c_cols;
/**
* Number of rows in Bernoulli coefficient table
*/
size_t c_rows;
const size_t c_rows;
/**
* Number of bits in z1
*/
uint16_t z1_bits;
const uint16_t z1_bits;
/**
* Number of z2 bits to be dropped after rounding
*/
uint16_t d;
const uint16_t d;
/**
* Modulus p = floor(2q / 2^d) applied after bit dropping
*/
uint16_t p;
const uint16_t p;
/**
* M = sigma^2 / alpha_rejection^2
*/
uint32_t M;
const uint32_t M;
/**
* B_infinity bound
*/
uint16_t B_inf;
const uint16_t B_inf;
/**
* B_verify bound
*/
uint32_t B_l2;
const uint32_t B_l2;
};
@@ -188,7 +188,7 @@ struct bliss_param_set_t {
* @param id BLISS parameter set ID
* @return BLISS parameter set
*/
bliss_param_set_t* bliss_param_set_get_by_id(bliss_param_set_id_t id);
const bliss_param_set_t* bliss_param_set_get_by_id(bliss_param_set_id_t id);
/**
* Get BLISS signature parameter set by BLISS parameter set OID
@@ -196,6 +196,6 @@ bliss_param_set_t* bliss_param_set_get_by_id(bliss_param_set_id_t id);
* @param oid BLISS parameter set OID
* @return BLISS parameter set
*/
bliss_param_set_t* bliss_param_set_get_by_oid(int oid);
const bliss_param_set_t* bliss_param_set_get_by_oid(int oid);
#endif /** BLISS_PARAM_SET_H_ @}*/
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014-2015 Andreas Steffen
* Copyright (C) 2014-2016 Andreas Steffen
* HSR Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
@@ -20,7 +20,8 @@
#include "bliss_sampler.h"
#include "bliss_signature.h"
#include "bliss_bitpacker.h"
#include "bliss_fft.h"
#include "ntt_fft.h"
#include "ntt_fft_reduce.h"
#include <crypto/mgf1/mgf1_bitspender.h>
#include <asn1/asn1.h>
@@ -46,7 +47,7 @@ struct private_bliss_private_key_t {
/**
* BLISS signature parameter set
*/
bliss_param_set_t *set;
const bliss_param_set_t *set;
/**
* BLISS secret key S1 (coefficients of polynomial f)
@@ -63,6 +64,11 @@ struct private_bliss_private_key_t {
*/
uint32_t *A;
/**
* NTT of BLISS public key in Montgomery representation Ar = rA mod
*/
uint32_t *Ar;
/**
* reference count
*/
@@ -163,7 +169,7 @@ static void greedy_sc(int8_t *s1, int8_t *s2, int n, uint16_t *c_indices,
static bool sign_bliss(private_bliss_private_key_t *this, hash_algorithm_t alg,
chunk_t data, chunk_t *signature)
{
bliss_fft_t *fft;
ntt_fft_t *fft;
bliss_signature_t *sig;
bliss_sampler_t *sampler = NULL;
rng_t *rng;
@@ -241,7 +247,7 @@ static bool sign_bliss(private_bliss_private_key_t *this, hash_algorithm_t alg,
y2 = z2;
ud = z2d;
fft = bliss_fft_create(this->set->fft_params);
fft = ntt_fft_create(this->set->fft_params);
/* Use of the enhanced BLISS-B signature algorithm? */
switch (this->set->id)
@@ -337,7 +343,7 @@ static bool sign_bliss(private_bliss_private_key_t *this, hash_algorithm_t alg,
for (i = 0; i < n; i++)
{
ay[i] = (this->A[i] * ay[i]) % q;
ay[i] = ntt_fft_mreduce(this->Ar[i] * ay[i], this->set->fft_params);
}
fft->transform(fft, ay, ay, TRUE);
@@ -668,6 +674,7 @@ METHOD(private_key_t, destroy, void,
free(this->s2);
}
free(this->A);
free(this->Ar);
free(this);
}
}
@@ -795,13 +802,13 @@ static uint32_t nks_norm(int8_t *s1, int8_t *s2, int n, uint16_t kappa)
/**
* Compute the inverse x1 of x modulo q as x^(-1) = x^(q-2) mod q
*/
static uint32_t invert(uint32_t x, uint16_t q)
static uint32_t invert(private_bliss_private_key_t *this, uint32_t x)
{
uint32_t x1, x2;
uint16_t q2;
int i, i_max;
q2 = q - 2;
q2 = this->set->q - 2;
x1 = (q2 & 1) ? x : 1;
x2 = x;
i_max = 15;
@@ -812,11 +819,11 @@ static uint32_t invert(uint32_t x, uint16_t q)
}
for (i = 1; i <= i_max; i++)
{
x2 = (x2 * x2) % q;
x2 = ntt_fft_mreduce(x2 * x2, this->set->fft_params);
if (q2 & (1 << i))
{
x1 = (x1 * x2) % q;
x1 = ntt_fft_mreduce(x1 * x2, this->set->fft_params);
}
}
@@ -1000,8 +1007,8 @@ bliss_private_key_t *bliss_private_key_gen(key_type_t type, va_list args)
uint32_t *S1, *S2, *a;
uint16_t q;
bool success = FALSE;
bliss_param_set_t *set;
bliss_fft_t *fft;
const bliss_param_set_t *set;
ntt_fft_t *fft;
rng_t *rng;
while (TRUE)
@@ -1062,13 +1069,14 @@ bliss_private_key_t *bliss_private_key_gen(key_type_t type, va_list args)
this->set = set;
/* We derive the public key from the private key using the FFT */
fft = bliss_fft_create(set->fft_params);
fft = ntt_fft_create(set->fft_params);
/* Some vectors needed to derive the publi key */
S1 = malloc(n * sizeof(uint32_t));
S2 = malloc(n * sizeof(uint32_t));
a = malloc(n * sizeof(uint32_t));
this->A = malloc(n * sizeof(uint32_t));
this->A = malloc(n * sizeof(uint32_t));
this->Ar = malloc(n * sizeof(uint32_t));
/* Instantiate a true random generator */
rng = lib->crypto->create_rng(lib->crypto, RNG_TRUE);
@@ -1091,6 +1099,7 @@ bliss_private_key_t *bliss_private_key_gen(key_type_t type, va_list args)
fft->transform(fft, S2, S2, FALSE);
success = TRUE;
for (i = 0; i < n; i++)
{
if (S1[i] == 0)
@@ -1103,8 +1112,9 @@ bliss_private_key_t *bliss_private_key_gen(key_type_t type, va_list args)
success = FALSE;
break;
}
this->A[i] = invert(S1[i], q);
this->A[i] = (S2[i] * this->A[i]) % q;
this->Ar[i] = invert(this, S1[i]);
this->Ar[i] = ntt_fft_mreduce(S2[i] * this->Ar[i], set->fft_params);
this->A[i] = ntt_fft_mreduce(this->Ar[i], set->fft_params);
}
}
while (!success && trials < SECRET_KEY_TRIALS_MAX);
@@ -1114,13 +1124,15 @@ bliss_private_key_t *bliss_private_key_gen(key_type_t type, va_list args)
if (success)
{
fft->transform(fft, this->A, a, TRUE);
fft->transform(fft, this->Ar, a, TRUE);
DBG4(DBG_LIB, " i f g a F G A");
for (i = 0; i < n; i++)
{
DBG4(DBG_LIB, "%4d %3d %3d %5u %5u %5u %5u",
i, this->s1[i], this->s2[i], a[i], S1[i], S2[i], this->A[i]);
i, this->s1[i], this->s2[i],
ntt_fft_mreduce(a[i], set->fft_params),
S1[i], S2[i], this->A[i]);
}
}
else
@@ -1167,7 +1179,7 @@ bliss_private_key_t *bliss_private_key_load(key_type_t type, va_list args)
asn1_parser_t *parser;
size_t s_bits = 0;
int8_t s, s_min = 0, s_max = 0;
uint32_t s_sign = 0x02, s_mask = 0xfffffffc, value;
uint32_t s_sign = 0x02, s_mask = 0xfffffffc, value, r2;
bool success = FALSE;
int objectID, oid, i;
@@ -1248,6 +1260,14 @@ bliss_private_key_t *bliss_private_key_load(key_type_t type, va_list args)
{
goto end;
}
this->Ar = malloc(this->set->n * sizeof(uint32_t));
r2 = this->set->fft_params->r2;
for (i = 0; i < this->set->n; i++)
{
this->Ar[i] = ntt_fft_mreduce(this->A[i] * r2,
this->set->fft_params);
}
break;
case PRIV_KEY_SECRET1:
if (object.len != 1 + (s_bits * this->set->n + 7)/8)
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014 Andreas Steffen
* Copyright (C) 2014-2016 Andreas Steffen
* HSR Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
@@ -16,7 +16,8 @@
#include "bliss_public_key.h"
#include "bliss_signature.h"
#include "bliss_bitpacker.h"
#include "bliss_fft.h"
#include "ntt_fft.h"
#include "ntt_fft_reduce.h"
#include "bliss_utils.h"
#include <asn1/asn1.h>
@@ -37,13 +38,18 @@ struct private_bliss_public_key_t {
/**
* BLISS signature parameter set
*/
bliss_param_set_t *set;
const bliss_param_set_t *set;
/**
* NTT of BLISS public key a (coefficients of polynomial (2g + 1)/f)
*/
uint32_t *A;
/**
* NTT of BLISS public key in Montgomery representation Ar = rA mod
*/
uint32_t *Ar;
/**
* reference counter
*/
@@ -71,7 +77,7 @@ static bool verify_bliss(private_bliss_public_key_t *this, hash_algorithm_t alg,
chunk_t data_hash;
hasher_t *hasher;
hash_algorithm_t oracle_alg;
bliss_fft_t *fft;
ntt_fft_t *fft;
bliss_signature_t *sig;
bool success = FALSE;
@@ -120,12 +126,12 @@ static bool verify_bliss(private_bliss_public_key_t *this, hash_algorithm_t alg,
{
az[i] = z1[i] < 0 ? q + z1[i] : z1[i];
}
fft = bliss_fft_create(this->set->fft_params);
fft = ntt_fft_create(this->set->fft_params);
fft->transform(fft, az, az, FALSE);
for (i = 0; i < n; i++)
{
az[i] = (this->A[i] * az[i]) % q;
az[i] = ntt_fft_mreduce(this->Ar[i] * az[i], this->set->fft_params);
}
fft->transform(fft, az, az, TRUE);
@@ -279,6 +285,7 @@ METHOD(public_key_t, destroy, void,
{
lib->encoding->clear_cache(lib->encoding, this);
free(this->A);
free(this->Ar);
free(this);
}
}
@@ -304,7 +311,8 @@ bliss_public_key_t *bliss_public_key_load(key_type_t type, va_list args)
chunk_t blob = chunk_empty, object, param;
asn1_parser_t *parser;
bool success = FALSE;
int objectID, oid;
int objectID, oid, i;
uint32_t r2;
while (TRUE)
{
@@ -380,6 +388,14 @@ bliss_public_key_t *bliss_public_key_load(key_type_t type, va_list args)
{
goto end;
}
this->Ar = malloc(this->set->n * sizeof(uint32_t));
r2 = this->set->fft_params->r2;
for (i = 0; i < this->set->n; i++)
{
this->Ar[i] = ntt_fft_mreduce(this->A[i] * r2,
this->set->fft_params);
}
break;
}
}
@@ -399,7 +415,7 @@ end:
/**
* See header.
*/
bool bliss_public_key_from_asn1(chunk_t object, bliss_param_set_t *set,
bool bliss_public_key_from_asn1(chunk_t object, const bliss_param_set_t *set,
uint32_t **pubkey)
{
bliss_bitpacker_t *packer;
@@ -438,7 +454,7 @@ bool bliss_public_key_from_asn1(chunk_t object, bliss_param_set_t *set,
/**
* See header.
*/
chunk_t bliss_public_key_encode(uint32_t *pubkey, bliss_param_set_t *set)
chunk_t bliss_public_key_encode(uint32_t *pubkey, const bliss_param_set_t *set)
{
bliss_bitpacker_t *packer;
chunk_t encoding;
@@ -460,7 +476,7 @@ chunk_t bliss_public_key_encode(uint32_t *pubkey, bliss_param_set_t *set)
* See header.
*/
chunk_t bliss_public_key_info_encode(int oid, uint32_t *pubkey,
bliss_param_set_t *set)
const bliss_param_set_t *set)
{
chunk_t encoding, pubkey_encoding;
@@ -479,7 +495,7 @@ chunk_t bliss_public_key_info_encode(int oid, uint32_t *pubkey,
* See header.
*/
bool bliss_public_key_fingerprint(int oid, uint32_t *pubkey,
bliss_param_set_t *set,
const bliss_param_set_t *set,
cred_encoding_type_t type, chunk_t *fp)
{
hasher_t *hasher;
@@ -61,7 +61,7 @@ bliss_public_key_t *bliss_public_key_load(key_type_t type, va_list args);
* @param pubkey coefficients of public key vector
* @return TRUE if parsing successful
*/
bool bliss_public_key_from_asn1(chunk_t object, bliss_param_set_t *set,
bool bliss_public_key_from_asn1(chunk_t object, const bliss_param_set_t *set,
uint32_t **pubkey);
/**
@@ -71,7 +71,7 @@ bool bliss_public_key_from_asn1(chunk_t object, bliss_param_set_t *set,
* @param set BLISS parameter set for the public key vector
* @result ASN.1 encoded subjectPublicKey
*/
chunk_t bliss_public_key_encode(uint32_t *pubkey, bliss_param_set_t *set);
chunk_t bliss_public_key_encode(uint32_t *pubkey, const bliss_param_set_t *set);
/**
* Encode a BLISS subjectPublicKeyInfo record in ASN.1 DER format
@@ -82,7 +82,7 @@ chunk_t bliss_public_key_encode(uint32_t *pubkey, bliss_param_set_t *set);
* @result ASN.1 encoded subjectPublicKeyInfo record
*/
chunk_t bliss_public_key_info_encode(int oid, uint32_t *pubkey,
bliss_param_set_t *set);
const bliss_param_set_t *set);
/**
* Generate a BLISS public key fingerprint
@@ -95,7 +95,7 @@ chunk_t bliss_public_key_info_encode(int oid, uint32_t *pubkey,
* @result TRUE if generation was successful
*/
bool bliss_public_key_fingerprint(int oid, uint32_t *pubkey,
bliss_param_set_t *set,
const bliss_param_set_t *set,
cred_encoding_type_t type, chunk_t *fp);
#endif /** BLISS_PUBLIC_KEY_H_ @}*/
@@ -32,7 +32,7 @@ struct private_bliss_sampler_t {
/**
* BLISS parameter the rejection sampling is to be based on
*/
bliss_param_set_t *set;
const bliss_param_set_t *set;
/**
* Bitspender used for random rejection sampling
@@ -45,7 +45,8 @@ METHOD(bliss_sampler_t, bernoulli_exp, bool,
private_bliss_sampler_t *this, uint32_t x, bool *accepted)
{
uint32_t x_mask;
uint8_t *c, u;
uint8_t u;
const uint8_t *c;
int i;
x_mask = 1 << (this->set->c_rows - 1);
@@ -222,7 +223,7 @@ METHOD(bliss_sampler_t, destroy, void,
* See header.
*/
bliss_sampler_t *bliss_sampler_create(hash_algorithm_t alg, chunk_t seed,
bliss_param_set_t *set)
const bliss_param_set_t *set)
{
private_bliss_sampler_t *this;
mgf1_bitspender_t *bitspender;
@@ -89,6 +89,6 @@ struct bliss_sampler_t {
* @param set BLISS parameter set to be used
*/
bliss_sampler_t *bliss_sampler_create(hash_algorithm_t alg, chunk_t seed,
bliss_param_set_t *set);
const bliss_param_set_t *set);
#endif /** BLISS_SAMPLER_H_ @}*/
@@ -32,7 +32,7 @@ struct private_bliss_signature_t {
/**
* BLISS signature parameter set
*/
bliss_param_set_t *set;
const bliss_param_set_t *set;
/**
* BLISS signature vector z1 of size n
@@ -134,7 +134,7 @@ METHOD(bliss_signature_t, destroy, void,
/**
* See header.
*/
bliss_signature_t *bliss_signature_create(bliss_param_set_t *set)
bliss_signature_t *bliss_signature_create(const bliss_param_set_t *set)
{
private_bliss_signature_t *this;
@@ -156,7 +156,7 @@ bliss_signature_t *bliss_signature_create(bliss_param_set_t *set)
/**
* See header.
*/
bliss_signature_t *bliss_signature_create_from_data(bliss_param_set_t *set,
bliss_signature_t *bliss_signature_create_from_data(const bliss_param_set_t *set,
chunk_t encoding)
{
private_bliss_signature_t *this;
@@ -61,7 +61,7 @@ struct bliss_signature_t {
*
* @param set BLISS parameter set
*/
bliss_signature_t *bliss_signature_create(bliss_param_set_t *set);
bliss_signature_t *bliss_signature_create(const bliss_param_set_t *set);
/**
* Create a BLISS signature object from encoding.
@@ -69,7 +69,7 @@ bliss_signature_t *bliss_signature_create(bliss_param_set_t *set);
* @param set BLISS parameter set
* @param encoding binary signature encoding
*/
bliss_signature_t *bliss_signature_create_from_data(bliss_param_set_t *set,
bliss_signature_t *bliss_signature_create_from_data(const bliss_param_set_t *set,
chunk_t encoding);
#endif /** BLISS_SIGNATURE_H_ @}*/
@@ -39,7 +39,8 @@ int32_t bliss_utils_scalar_product(int32_t *x, int32_t *y, int n)
/**
* See header.
*/
void bliss_utils_round_and_drop(bliss_param_set_t *set, int32_t *x, int16_t *xd)
void bliss_utils_round_and_drop(const bliss_param_set_t *set,
int32_t *x, int16_t *xd)
{
int32_t factor;
int i;
@@ -56,7 +57,7 @@ void bliss_utils_round_and_drop(bliss_param_set_t *set, int32_t *x, int16_t *xd)
* See header.
*/
bool bliss_utils_generate_c(hash_algorithm_t alg, chunk_t data_hash,
uint16_t *ud, bliss_param_set_t *set,
uint16_t *ud, const bliss_param_set_t *set,
uint16_t *c_indices)
{
int i, index_trials = 0, index_found = 0;
@@ -117,7 +118,8 @@ bool bliss_utils_generate_c(hash_algorithm_t alg, chunk_t data_hash,
/**
* See header.
*/
bool bliss_utils_check_norms(bliss_param_set_t *set, int32_t *z1, int16_t *z2d)
bool bliss_utils_check_norms(const bliss_param_set_t *set,
int32_t *z1, int16_t *z2d)
{
int32_t z2ds[set->n];
int32_t z1_min, z1_max, norm;
@@ -42,7 +42,8 @@ int32_t bliss_utils_scalar_product(int32_t *x, int32_t *y, int n);
* @param x input vector x of size n
* @param xd rounded vector x with d bits dropped
*/
void bliss_utils_round_and_drop(bliss_param_set_t *set, int32_t *x, int16_t *xd);
void bliss_utils_round_and_drop(const bliss_param_set_t *set,
int32_t *x, int16_t *xd);
/**
* Generate the binary challenge vector c as an array of kappa indices
@@ -54,7 +55,7 @@ void bliss_utils_round_and_drop(bliss_param_set_t *set, int32_t *x, int16_t *xd)
* @param c_indices indexes of non-zero challenge coefficients
*/
bool bliss_utils_generate_c(hash_algorithm_t alg, chunk_t data_hash,
uint16_t *ud, bliss_param_set_t *set,
uint16_t *ud, const bliss_param_set_t *set,
uint16_t *c_indices);
/**
@@ -65,6 +66,7 @@ bool bliss_utils_generate_c(hash_algorithm_t alg, chunk_t data_hash,
* @param z2d input vector
* @result TRUE if infinite and l2 norms do not exceed boundaries
*/
bool bliss_utils_check_norms(bliss_param_set_t *set, int32_t *z1, int16_t *z2d);
bool bliss_utils_check_norms(const bliss_param_set_t *set,
int32_t *z1, int16_t *z2d);
#endif /** BLISS_UTILS_H_ @}*/
@@ -3,7 +3,6 @@ TESTS = bliss_tests
check_PROGRAMS = $(TESTS)
bliss_tests_SOURCES = \
suites/test_bliss_fft.c \
suites/test_bliss_bitpacker.c \
suites/test_bliss_huffman.c \
suites/test_bliss_keys.c \
@@ -15,6 +14,7 @@ bliss_tests_SOURCES = \
bliss_tests_CFLAGS = \
-I$(top_srcdir)/src/libstrongswan \
-I$(top_srcdir)/src/libstrongswan/tests \
-I$(top_srcdir)/src/libstrongswan/math/libnttfft \
-I$(top_srcdir)/src/libstrongswan/plugins/bliss \
-DPLUGINDIR=\""$(abs_top_builddir)/src/libstrongswan/plugins\"" \
-DPLUGINS=\""${s_plugins}\"" \
@@ -24,4 +24,5 @@ bliss_tests_LDFLAGS = @COVERAGE_LDFLAGS@
bliss_tests_LDADD = \
$(top_builddir)/src/libstrongswan/libstrongswan.la \
$(top_builddir)/src/libstrongswan/tests/libtest.la \
$(top_builddir)/src/libstrongswan/math/libnttfft/libnttfft.la \
../libbliss.la
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014-2015 Andreas Steffen
* Copyright (C) 2014-2016 Andreas Steffen
* HSR Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
@@ -13,7 +13,6 @@
* for more details.
*/
TEST_SUITE(bliss_fft_suite_create)
TEST_SUITE(bliss_bitpacker_suite_create)
TEST_SUITE(bliss_huffman_suite_create)
TEST_SUITE(bliss_keys_suite_create)
@@ -22,7 +22,7 @@ static u_int key_size[] = { 1, 3, 4};
START_TEST(test_bliss_sampler_gaussian)
{
bliss_sampler_t *sampler;
bliss_param_set_t *set;
const bliss_param_set_t *set;
int i, k, count;
uint32_t hist[8], sign[3];
int32_t z;
@@ -95,8 +95,8 @@ static chunk_t data = chunk_from_chars(
START_TEST(test_bliss_signature_fail)
{
bliss_param_set_t set2 = { .id = BLISS_B_II };
bliss_param_set_t *set;
const bliss_param_set_t set2 = { .id = BLISS_B_II };
const bliss_param_set_t *set;
bliss_signature_t *signature;
chunk_t encoding;
int k;
@@ -15,7 +15,8 @@ libstrongswan_chapoly_la_SOURCES = \
chapoly_plugin.h chapoly_plugin.c \
chapoly_drv.h chapoly_drv.c \
chapoly_drv_portable.h chapoly_drv_portable.c \
chapoly_aead.h chapoly_aead.c
chapoly_aead.h chapoly_aead.c \
chapoly_xof.h chapoly_xof.c
noinst_LTLIBRARIES += libchapoly-drv-ssse3.la
libchapoly_drv_ssse3_la_SOURCES = chapoly_drv_ssse3.h chapoly_drv_ssse3.c
@@ -15,6 +15,7 @@
#include "chapoly_plugin.h"
#include "chapoly_aead.h"
#include "chapoly_xof.h"
#include <library.h>
@@ -43,6 +44,8 @@ METHOD(plugin_t, get_features, int,
static plugin_feature_t f[] = {
PLUGIN_REGISTER(AEAD, chapoly_aead_create),
PLUGIN_PROVIDE(AEAD, ENCR_CHACHA20_POLY1305, 32),
PLUGIN_REGISTER(XOF, chapoly_xof_create),
PLUGIN_PROVIDE(XOF, XOF_CHACHA20),
};
*features = f;
return countof(f);
@@ -0,0 +1,166 @@
/*
* Copyright (C) 2016 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 "chapoly_xof.h"
#include "chapoly_drv.h"
typedef struct private_chapoly_xof_t private_chapoly_xof_t;
/**
* Private data of an chapoly_xof_t object.
*/
struct private_chapoly_xof_t {
/**
* Public chapoly_xof_t interface.
*/
chapoly_xof_t public;
/**
* Latest block of the ChaCha20 stream.
*/
uint8_t stream[CHACHA_BLOCK_SIZE];
/**
* Index pointing to the current position in the stream
*/
u_int stream_index;
/**
* Driver backend
*/
chapoly_drv_t *drv;
};
METHOD(xof_t, get_bytes, bool,
private_chapoly_xof_t *this, size_t out_len, uint8_t *buffer)
{
size_t index = 0, len, blocks;
/* empty the stream buffer first */
len = min(out_len, CHACHA_BLOCK_SIZE - this->stream_index);
if (len)
{
memcpy(buffer + index, this->stream + this->stream_index, len);
index += len;
this->stream_index += len;
}
/* copy whole stream blocks directly to output buffer */
blocks = (out_len - index) / CHACHA_BLOCK_SIZE;
while (blocks--)
{
if (!this->drv->chacha(this->drv, buffer + index))
{
return FALSE;
}
index += CHACHA_BLOCK_SIZE;
}
/* refill the stream buffer if some more output bytes are needed */
len = out_len - index;
if (len)
{
if (!this->drv->chacha(this->drv, this->stream))
{
return FALSE;
}
memcpy(buffer + index, this->stream, len);
this->stream_index = len;
}
return TRUE;
}
METHOD(xof_t, allocate_bytes, bool,
private_chapoly_xof_t *this, size_t out_len, chunk_t *chunk)
{
*chunk = chunk_alloc(out_len);
if (!get_bytes(this, out_len, chunk->ptr))
{
chunk_free(chunk);
return FALSE;
}
return TRUE;
}
METHOD(xof_t, get_block_size, size_t,
private_chapoly_xof_t *this)
{
return CHACHA_BLOCK_SIZE;
}
METHOD(xof_t, get_seed_size, size_t,
private_chapoly_xof_t *this)
{
return CHACHA_KEY_SIZE + CHACHA_SALT_SIZE + CHACHA_IV_SIZE;
}
METHOD(xof_t, set_seed, bool,
private_chapoly_xof_t *this, chunk_t seed)
{
this->stream_index = CHACHA_BLOCK_SIZE;
return seed.len == get_seed_size(this) &&
this->drv->set_key(this->drv, "expand 32-byte k",
seed.ptr, seed.ptr + CHACHA_KEY_SIZE) &&
this->drv->init(this->drv,
seed.ptr + CHACHA_KEY_SIZE + CHACHA_SALT_SIZE);
}
METHOD(xof_t, destroy, void,
private_chapoly_xof_t *this)
{
this->drv->destroy(this->drv);
free(this);
}
/**
* See header
*/
chapoly_xof_t *chapoly_xof_create(ext_out_function_t algorithm)
{
private_chapoly_xof_t *this;
chapoly_drv_t *drv;
if (algorithm != XOF_CHACHA20)
{
return NULL;
}
drv = chapoly_drv_probe();
if (!drv)
{
return NULL;
}
INIT(this,
.public = {
.xof_interface = {
.get_bytes = _get_bytes,
.allocate_bytes = _allocate_bytes,
.get_block_size = _get_block_size,
.get_seed_size = _get_seed_size,
.set_seed = _set_seed,
.destroy = _destroy,
},
},
.drv = drv,
);
return &this->public;
}
@@ -0,0 +1,49 @@
/*
* Copyright (C) 2016 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.
*/
/**
* @defgroup chapoly_xof chapoly_xof
* @{ @ingroup chapoly
*/
#ifndef CHAPOLY_XOF_H_
#define CHAPOLY_XOF_H_
#include <crypto/aead.h>
typedef struct chapoly_xof_t chapoly_xof_t;
/**
* ChaCha20 XOF implementation
*
* Based on RFC 7539 ChaCha20 stream initialized with block counter = 1
*/
struct chapoly_xof_t {
/**
* Generic xof_t interface for this Extended Output Function (XOF).
*/
xof_t xof_interface;
};
/**
* Create a chapoly_xof instance.
*
* @param algorithm XOF_CHACHA20
* @return chapoly_xof_t object, NULL if not supported
*/
chapoly_xof_t *chapoly_xof_create(ext_out_function_t algorithm);
#endif /** CHAPOLY_XOF_H_ @}*/
@@ -0,0 +1,33 @@
AM_CPPFLAGS = \
-I$(top_srcdir)/src/libstrongswan \
-I$(top_srcdir)/src/libstrongswan/math/libnttfft
AM_CFLAGS = \
$(PLUGIN_CFLAGS) \
@COVERAGE_CFLAGS@
# 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 = libnewhope.la
libnewhope_la_SOURCES = \
newhope_ke.h newhope_ke.c \
newhope_noise.h newhope_noise.c \
newhope_reconciliation.h newhope_reconciliation.c
libnewhope_la_LIBADD = \
$(top_builddir)/src/libstrongswan/math/libnttfft/libnttfft.la
if MONOLITHIC
noinst_LTLIBRARIES += libstrongswan-newhope.la
else
plugin_LTLIBRARIES = libstrongswan-newhope.la
endif
libstrongswan_newhope_la_SOURCES = \
newhope_plugin.h newhope_plugin.c
libstrongswan_newhope_la_LDFLAGS = -module -avoid-version
libstrongswan_newhope_la_LIBADD = libnewhope.la
@@ -0,0 +1,622 @@
/*
* Copyright (C) 2016 Andreas Steffen
* HSR Hochschule fuer Technik Rapperswil
*
* Based on public domain code by Erdem Alkim, Léo Ducas, Thomas Pöppelmann,
* and Peter Schwabe.
*
* 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 "newhope_ke.h"
#include "newhope_noise.h"
#include "newhope_reconciliation.h"
#include <ntt_fft.h>
#include <ntt_fft_reduce.h>
#include <crypto/diffie_hellman.h>
#include <utils/debug.h>
static const int seed_len = 32; /* 256 bits */
static const int poly_len = 1792; /* size of 1024 packed 14-bit coefficients */
static const int rec_len = 256; /* size of 1024 packed 2-bit coefficients */
typedef struct private_newhope_ke_t private_newhope_ke_t;
/**
* Private data of an newhope_ke_t object.
*/
struct private_newhope_ke_t {
/**
* Public newhope_ke_t interface.
*/
newhope_ke_t public;
/**
* FFT parameter set
*/
const ntt_fft_params_t *params;
/**
* Secret noise polynomial s
*/
uint32_t *s;
/**
* Output polynomial u = a * NTT(s') + NTT(e')
*/
uint32_t *u;
/**
* Error reconciliation help bits
*/
uint8_t *r;
/**
* Shared secret
*/
chunk_t shared_secret;
};
/**
* Derive 14-bit coefficients of polynomial a from 256 bit random seed
* using the SHAKE128 extended output function
*/
static uint32_t* derive_a_poly(private_newhope_ke_t *this, chunk_t seed)
{
uint32_t *a;
uint8_t x[2];
int i = 0;
xof_t *xof;
xof = lib->crypto->create_xof(lib->crypto, XOF_SHAKE_128);
if (!xof)
{
DBG1(DBG_LIB, "could not instantiate SHAKE128 XOF");
return NULL;
}
if (!xof->set_seed(xof, seed))
{
DBG1(DBG_LIB, "could not set seed of SHAKE128 XOF");
xof->destroy(xof);
return NULL;
}
/* allocate dynamic memory for polynomial a */
a = (uint32_t*)malloc(this->params->n * sizeof(uint32_t));
while (i < this->params->n)
{
if (!xof->get_bytes(xof, sizeof(x), x))
{
DBG1(DBG_LIB, "could not get bytes from SHAKE128 XOF");
xof->destroy(xof);
free(a);
return NULL;
}
/*
* Treat x as a 16 bit unsigned little endian integer
* and truncate to 14 bits
*/
a[i] = uletoh16(x) & 0x3fff;
if (a[i] < this->params->q)
{
i++;
}
}
xof->destroy(xof);
return a;
}
/**
* Pack four 14-bit coefficients into seven consecutive bytes
*
* 1 2 3
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* |L 0 0 0 0 0 0 0|L 1 H 0 0 0 0 0|M 1 1 1 1 1 1 1|L 2 2 2 H 1 1 1|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* |M 2 2 2 2 2 2 2|L 3 3 3 3 3 H 2|H 3 3 3 3 3 3 3|L 0 0 0 0 0 0 0|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
static void pack_poly(private_newhope_ke_t *this, uint8_t *x, uint32_t *p)
{
int i;
for (i = 0; i < this->params->n; i += 4)
{
*x++ = (p[i] & 0xff );
*x++ = (p[i] >> 8) | (p[i+1] << 6);
*x++ = (p[i+1] >> 2);
*x++ = (p[i+1] >> 10) | (p[i+2] << 4);
*x++ = (p[i+2] >> 4);
*x++ = (p[i+2] >> 12) | (p[i+3] << 2);
*x++ = (p[i+3] >> 6);
}
}
/**
* Unpack seven consecutive bytes into four 14-bit coefficients
*/
static uint32_t* unpack_poly(private_newhope_ke_t * this, uint8_t *x)
{
uint32_t *p;
int i;
p = (uint32_t*)malloc(this->params->n * sizeof(uint32_t));
for (i = 0; i < this->params->n; i += 4)
{
p[i] = x[0] | (((uint32_t)x[1] & 0x3f) << 8);
p[i+1] = (x[1] >> 6) | (((uint32_t)x[2]) << 2)
| (((uint32_t)x[3] & 0x0f) << 10);
p[i+2] = (x[3] >> 4) | (((uint32_t)x[4]) << 4)
| (((uint32_t)x[5] & 0x03) << 12);
p[i+3] = (x[5] >> 2) | (((uint32_t)x[6]) << 6);
x += 7;
}
for (i = 0; i < this->params->n; i++)
{
if (p[i] >= this->params->q)
{
DBG1(DBG_LIB, "polynomial coefficient must be smaller than %u",
this->params->q);
free(p);
return NULL;
}
}
return p;
}
/**
* Multiply and add polynomials in the frequency domain
*/
static uint32_t* multiply_add_poly(private_newhope_ke_t *this,
uint32_t *a, uint32_t *e)
{
ntt_fft_t *fft;
uint32_t *b, t;
int i;
/* transform s and h to frequency domain */
fft = ntt_fft_create(this->params);
fft->transform(fft, this->s, this->s, FALSE);
fft->transform(fft, e, e, FALSE);
fft->destroy(fft);
b = (uint32_t*)malloc(this->params->n * sizeof(uint32_t));
/* compute b = a * s + e in the frequency domain */
for (i = 0; i < this->params->n; i++)
{
/* convert a[i] to Montgomery domain */
t = ntt_fft_mreduce(a[i] * this->params->r2, this->params);
/* compute b[i] = a[i] * s[i] + e[i] in Montgomery domain */
t = ntt_fft_mreduce(t * this->s[i], this->params) + e[i];
/* exit Montgomery domain before transmitting polynomial b */
b[i] = ntt_fft_mreduce(t, this->params);
}
memwipe(e, this->params->n * sizeof(uint32_t));
return b;
}
/**
* Multiply polynomials in the frequency domain and return to time domain
*/
static uint32_t* multiply_ntt_inv_poly(private_newhope_ke_t *this, uint32_t *b)
{
ntt_fft_t *fft;
uint32_t *v, t;
int i;
v = (uint32_t*)malloc(this->params->n * sizeof(uint32_t));
for (i = 0; i < this->params->n; i++)
{
/* convert b[i] to Montgomery domain */
t = ntt_fft_mreduce(b[i] * this->params->r2, this->params);
/* compute v[i] = b[i] * s[i] in Montgomery domain */
v[i] = ntt_fft_mreduce(t * this->s[i], this->params);
}
/* transform v back to time domain */
fft = ntt_fft_create(this->params);
fft->transform(fft, v, v, TRUE);
fft->destroy(fft);
return v;
}
/**
* Pack four 2-bit coefficents into one byte
*/
static void pack_rec(private_newhope_ke_t *this, uint8_t *x, uint8_t *r)
{
int i;
for (i = 0; i < this->params->n; i += 4)
{
*x++ = r[i] | r[i+1] << 2 | r[i+2] << 4 | r[i+3] << 6;
}
}
static uint8_t* unpack_rec(private_newhope_ke_t *this, uint8_t *x)
{
uint8_t *r;
int i;
r = (uint8_t*)malloc(this->params->n);
for (i = 0; i < this->params->n; i += 4)
{
r[i] = (*x) & 0x03;
r[i+1] = (*x >> 2) & 0x03;
r[i+2] = (*x >> 4) & 0x03;
r[i+3] = (*x >> 6) & 0x03;
x++;
}
return r;
}
METHOD(diffie_hellman_t, get_my_public_value, bool,
private_newhope_ke_t *this, chunk_t *value)
{
uint16_t n, q;
int i;
/* Define some often-used constants */
n = this->params->n;
q = this->params->q;
/* are we the initiator? */
if (this->u == NULL)
{
rng_t *rng;
uint32_t *a = NULL, *b = NULL, *e = NULL;
uint8_t noise_seed_buf[seed_len];
chunk_t noise_seed = { noise_seed_buf, seed_len};
chunk_t a_seed;
newhope_noise_t *noise = NULL;
bool success = FALSE;
/* allocate space for public output value */
*value = chunk_alloc(poly_len + seed_len);
a_seed = chunk_create(value->ptr + poly_len, seed_len);
/* create polynomial a from 256 bit random seed */
rng = lib->crypto->create_rng(lib->crypto, RNG_STRONG);
if (!rng)
{
DBG1(DBG_LIB, "could not instatiate random source");
return FALSE;
}
if (!rng->get_bytes(rng, seed_len, a_seed.ptr))
{
DBG1(DBG_LIB, "could not generate seed for polynomial a");
goto end;
}
a = derive_a_poly(this, a_seed);
if (a == NULL)
{
goto end;
}
/* generate random seed for the derivation of noise polynomials */
if (!rng->get_bytes(rng, seed_len, noise_seed.ptr))
{
DBG1(DBG_LIB, "could not generate seed for noise polynomials");
goto end;
}
/* create noise polynomial generator */
noise = newhope_noise_create(noise_seed);
if (!noise)
{
goto end;
}
/* create noise polynomial s from seed with nonce = 0x00 */
this->s = noise->get_binomial_words(noise, 0x00, n, q);
if (this->s == NULL)
{
goto end;
}
/* create noise polynomial e from seed with nonce = 0x01 */
e = noise->get_binomial_words(noise, 0x01, n, q);
if (e == NULL)
{
goto end;
}
/* compute b = a * NTT(s) + NTT(e) */
b = multiply_add_poly(this, a, e);
DBG3(DBG_LIB, " i a[i] b[i]");
for (i = 0; i < n; i++)
{
DBG3(DBG_LIB, "%4d %5u %5u", i, a[i], b[i]);
}
/* pack coefficients of polynomial b */
pack_poly(this, value->ptr, b);
success = TRUE;
end:
rng->destroy(rng);
DESTROY_IF(noise);
free(a);
free(b);
free(e);
if (!success)
{
chunk_free(value);
}
return success;
}
else
{
DBG3(DBG_LIB, " i u[i] r[i]");
for (i = 0; i < n; i++)
{
DBG3(DBG_LIB, "%4d %5u %5u", i, this->u[i], this->r[i]);
}
/* allocate space for public output value */
*value = chunk_alloc(poly_len + rec_len);
/* pack coefficients of polynomial u */
pack_poly(this, value->ptr, this->u);
/* pack coefficients of polynomial r */
pack_rec(this, value->ptr + poly_len, this->r);
return TRUE;
}
}
METHOD(diffie_hellman_t, get_shared_secret, bool,
private_newhope_ke_t *this, chunk_t *secret)
{
if (this->shared_secret.len == 0)
{
*secret = chunk_empty;
return FALSE;
}
*secret = chunk_clone(this->shared_secret);
return TRUE;
}
METHOD(diffie_hellman_t, set_other_public_value, bool,
private_newhope_ke_t *this, chunk_t value)
{
newhope_reconciliation_t * rec;
uint16_t n, q;
int i;
/* Define some often-used constants */
n = this->params->n;
q = this->params->q;
/* are we the responder? */
if (this->s == NULL)
{
uint32_t *a = NULL, *b = NULL, *e1 = NULL, *e2 = NULL, *v = NULL, t;
uint8_t *rbits = NULL;
uint8_t noise_seed_buf[seed_len];
chunk_t noise_seed = { noise_seed_buf, seed_len };
chunk_t a_seed;
newhope_noise_t *noise = NULL;
rng_t *rng = NULL;
bool success = FALSE;
if (value.len != poly_len + seed_len)
{
DBG1(DBG_LIB, "received %N KE payload of incorrect size",
diffie_hellman_group_names, NH_128_BIT);
return FALSE;
}
a_seed = chunk_create(value.ptr + poly_len, seed_len);
a = derive_a_poly(this, a_seed);
if (a == NULL)
{
return FALSE;
}
b = unpack_poly(this, value.ptr);
if (b == NULL)
{
goto end;
}
/* debug output of polynomials a and b */
DBG3(DBG_LIB, " i a[i] b[i]");
for (i = 0; i < n; i++)
{
DBG3(DBG_LIB, "%4d %5u %5u", i, a[i], b[i]);
}
/* generate random seed for the derivation of noise polynomials */
rng = lib->crypto->create_rng(lib->crypto, RNG_STRONG);
if (!rng)
{
DBG1(DBG_LIB, "could not instatiate random source");
return FALSE;
}
if (!rng->get_bytes(rng, seed_len, noise_seed.ptr))
{
DBG1(DBG_LIB, "could not generate seed for noise polynomials");
goto end;
}
/* create noise polynomial generator */
noise = newhope_noise_create(noise_seed);
if (!noise)
{
goto end;
}
/* create noise polynomial s' from seed with nonce = 0x00 */
this->s = noise->get_binomial_words(noise, 0x00, n, q);
if (this->s == NULL)
{
goto end;
}
/* create noise polynomial e' from seed with nonce = 0x01 */
e1 = noise->get_binomial_words(noise, 0x01, n, q);
if (e1 == NULL)
{
goto end;
}
/* create noise polynomial e'' from seed with nonce = 0x02 */
e2 = noise->get_binomial_words(noise, 0x02, n, q);
if (e2 == NULL)
{
goto end;
}
/* compute u = a * NTT(s') + NTT(e') */
this->u = multiply_add_poly(this, a, e1);
/* compute v = NTT_inv( b * NTT(s') ) */
v = multiply_ntt_inv_poly(this, b);
/* compute v = v + e'' */
for (i = 0; i < n; i++)
{
t = v[i] + e2[i];
v[i] = (t < q) ? t : t - q;
}
memwipe(e2, n * sizeof(uint32_t));
/* create uniform noise bytes from seed with nonce = 0x02 */
rbits = noise->get_uniform_bytes(noise, 0x03, n/(4*8));
rec = newhope_reconciliation_create(n, q);
this->r = rec->help_reconcile(rec, v, rbits);
free(rbits);
this->shared_secret = rec->reconcile(rec, v, this->r);
rec->destroy(rec);
DBG4(DBG_LIB, "key: %B", &this->shared_secret);
success = TRUE;
end:
DESTROY_IF(rng);
DESTROY_IF(noise);
free(a);
free(b);
free(e1);
free(e2);
free(v);
return success;
}
else
{
uint32_t *v;
if (value.len != poly_len + rec_len)
{
DBG1(DBG_LIB, "received %N KE payload of incorrect size",
diffie_hellman_group_names, NH_128_BIT);
return FALSE;
}
this->u = unpack_poly(this, value.ptr);
if (this->u == NULL)
{
return FALSE;
}
this->r = unpack_rec(this, value.ptr + poly_len);
if (this->r == NULL)
{
return FALSE;
}
DBG3(DBG_LIB, " i u[i] r[i]");
for (i = 0; i < n; i++)
{
DBG3(DBG_LIB, "%4d %5u %5u", i, this->u[i], this->r[i]);
}
/* compute v' = NTT_inv( u * NTT(s) ) */
v = multiply_ntt_inv_poly(this, this->u);
rec = newhope_reconciliation_create(n, q);
this->shared_secret = rec->reconcile(rec, v, this->r);
free(v);
rec->destroy(rec);
DBG4(DBG_LIB, "key: %B", &this->shared_secret);
return TRUE;
}
}
METHOD(diffie_hellman_t, get_dh_group, diffie_hellman_group_t,
private_newhope_ke_t *this)
{
return NH_128_BIT;
}
METHOD(diffie_hellman_t, destroy, void,
private_newhope_ke_t *this)
{
chunk_clear(&this->shared_secret);
memwipe(this->s, this->params->n * sizeof(uint32_t));
free(this->s);
free(this->u);
free(this->r);
free(this);
}
/*
* Described in header.
*/
newhope_ke_t *newhope_ke_create(diffie_hellman_group_t group, chunk_t g, chunk_t p)
{
private_newhope_ke_t *this;
INIT(this,
.public = {
.dh = {
.get_shared_secret = _get_shared_secret,
.set_other_public_value = _set_other_public_value,
.get_my_public_value = _get_my_public_value,
.get_dh_group = _get_dh_group,
.destroy = _destroy,
},
},
.params = &ntt_fft_12289_1024,
);
return &this->public;
}
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2016 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.
*/
/**
* @defgroup newhope_ke newhope_ke
* @{ @ingroup newhope_p
*/
#ifndef NEWHOPE_KE_H_
#define NEWHOPE_KE_H_
typedef struct newhope_ke_t newhope_ke_t;
#include <library.h>
/**
* Implementation of a key exchange algorithm using the New Hope algorithm
*/
struct newhope_ke_t {
/**
* Implements diffie_hellman_t interface.
*/
diffie_hellman_t dh;
};
/**
* Creates a new newhope_ke_t object.
*
* @param group New Hope DH group number
* @param g not used
* @param p not used
* @return newhope_ke_t object, NULL if not supported
*/
newhope_ke_t *newhope_ke_create(diffie_hellman_group_t group, chunk_t g, chunk_t p);
#endif /** NEWHOPE_KE_H_ @}*/
@@ -0,0 +1,160 @@
/*
* Copyright (C) 2016 Andreas Steffen
* HSR Hochschule fuer Technik Rapperswil
*
* Based on public domain code by Erdem Alkim, Léo Ducas, Thomas Pöppelmann,
* and Peter Schwabe.
*
* 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 "newhope_noise.h"
typedef struct private_newhope_noise_t private_newhope_noise_t;
static const int seed_len = 32; /* 256 bits */
static const int nonce_len = 12; /* 96 bits */
/**
* Private data of an newhope_noise_t object.
*/
struct private_newhope_noise_t {
/**
* Public newhope_noise_t interface.
*/
newhope_noise_t public;
/**
* 256 bit seed and 96 bit nonce (44 bytes)
*/
chunk_t seed;
/**
* ChaCha20 stream
*/
xof_t *xof;
};
METHOD(newhope_noise_t, get_uniform_bytes, uint8_t*,
private_newhope_noise_t *this, uint8_t nonce, uint16_t n)
{
uint8_t *bytes;
this->seed.ptr[seed_len] = nonce;
if (!this->xof->set_seed(this->xof, this->seed))
{
DBG1(DBG_LIB, "could not set seed of CHACHA20 XOF");
return NULL;
}
/* allocate dynamic memory for the noise polynomial */
bytes = (uint8_t*)malloc(n);
if (!this->xof->get_bytes(this->xof, n, bytes))
{
DBG1(DBG_LIB, "could not get bytes from SHAKE128 XOF");
free(bytes);
return NULL;
}
return bytes;
}
METHOD(newhope_noise_t, get_binomial_words, uint32_t*,
private_newhope_noise_t *this, uint8_t nonce, uint16_t n, uint16_t q)
{
uint32_t *np, a, b, d, t;
uint8_t x[4];
int i = 0, j;
this->seed.ptr[seed_len] = nonce;
if (!this->xof->set_seed(this->xof, this->seed))
{
DBG1(DBG_LIB, "could not set seed of CHACHA20 XOF");
return NULL;
}
/* allocate dynamic memory for the noise polynomial */
np = (uint32_t*)malloc(n * sizeof(uint32_t));
for (i = 0; i < n; i++)
{
if (!this->xof->get_bytes(this->xof, sizeof(x), x))
{
DBG1(DBG_LIB, "could not get bytes from SHAKE128 XOF");
free(np);
return NULL;
}
/* Treat x as a 32 bit unsigned little endian integer */
t = uletoh32(x);
/* Compute Psi_16 distribution */
d = 0;
for (j = 0; j < 8; j++)
{
d += (t >> j) & 0x01010101;
}
a = ((d >> 8) & 0xff) + (d & 0xff);
b = ((d >> 16) & 0xff) + (d >> 24);
np[i] = (a >= b) ? a - b : a + q - b;
}
return np;
}
METHOD(newhope_noise_t, destroy, void,
private_newhope_noise_t *this)
{
this->xof->destroy(this->xof);
chunk_free(&this->seed);
free(this);
}
/*
* Described in header.
*/
newhope_noise_t *newhope_noise_create(chunk_t seed)
{
private_newhope_noise_t *this;
xof_t *xof;
if (seed.len != seed_len)
{
DBG1(DBG_LIB, "seed for ChaCha20 stream must be 256 bits");
return NULL;
}
xof = lib->crypto->create_xof(lib->crypto, XOF_CHACHA20);
if (!xof)
{
DBG1(DBG_LIB, "could not instantiate ChaCha20 stream");
return NULL;
}
INIT(this,
.public = {
.get_uniform_bytes = _get_uniform_bytes,
.get_binomial_words = _get_binomial_words,
.destroy = _destroy,
},
.xof = xof,
.seed = chunk_alloc(seed_len + nonce_len),
);
/* initialize seed for ChaCha 20 stream */
memcpy(this->seed.ptr, seed.ptr, seed_len);
memset(this->seed.ptr + seed_len, 0x00, nonce_len);
return &this->public;
}
@@ -0,0 +1,70 @@
/*
* Copyright (C) 2016 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.
*/
/**
* @defgroup newhope_noise newhope_noise
* @{ @ingroup newhope_p
*/
#ifndef NEWHOPE_NOISE_H_
#define NEWHOPE_NOISE_H_
typedef struct newhope_noise_t newhope_noise_t;
#include <library.h>
/**
* Generate pseudo random noise using a ChaCha20 stream
* initialized with a 256 bit seed and an 8 bit nonce
*/
struct newhope_noise_t {
/**
* Return n pseudo random bytes with a uniform distribution
*
* @param nonce Nonce determining the pseudo random stream
* @param n Number of pseudo random bytes to be returned
* @return Return array with n peudo random bytes
*/
uint8_t* (*get_uniform_bytes)(newhope_noise_t *this, uint8_t nonce,
uint16_t n);
/**
* Return n pseudo random 32-bit words with a Psi16 binomial distribution
*
* @param nonce Nonce determining the pseudo random stream
* @param n Number of pseudo random Psi16 words to be returned
* @param q Prime number q determining the ring
* @return Return array with n pseudo random 32 bit words
*/
uint32_t* (*get_binomial_words)(newhope_noise_t *this, uint8_t nonce,
uint16_t n, uint16_t q);
/**
* Destroy a newhope_noise_t object
*/
void (*destroy)(newhope_noise_t *this);
};
/**
* Creates a new newhope_noise_t object.
*
* @param seed 256 bit seed (32 byte chunk)
* @return newhope_noise_t object, NULL if not supported
*/
newhope_noise_t *newhope_noise_create(chunk_t seed);
#endif /** NEWHOPE_NOISE_H_ @}*/
@@ -0,0 +1,78 @@
/*
* Copyright (C) 2016 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 "newhope_plugin.h"
#include "newhope_ke.h"
#include <library.h>
typedef struct private_newhope_plugin_t private_newhope_plugin_t;
/**
* private data of newhope_plugin
*/
struct private_newhope_plugin_t {
/**
* public functions
*/
newhope_plugin_t public;
};
METHOD(plugin_t, get_name, char*,
private_newhope_plugin_t *this)
{
return "newhope";
}
METHOD(plugin_t, get_features, int,
private_newhope_plugin_t *this, plugin_feature_t *features[])
{
static plugin_feature_t f[] = {
PLUGIN_REGISTER(DH, newhope_ke_create),
PLUGIN_PROVIDE(DH, NH_128_BIT),
PLUGIN_DEPENDS(XOF, XOF_SHAKE_128),
PLUGIN_DEPENDS(XOF, XOF_CHACHA20),
};
*features = f;
return countof(f);
}
METHOD(plugin_t, destroy, void,
private_newhope_plugin_t *this)
{
free(this);
}
/*
* see header file
*/
plugin_t *newhope_plugin_create()
{
private_newhope_plugin_t *this;
INIT(this,
.public = {
.plugin = {
.get_name = _get_name,
.get_features = _get_features,
.destroy = _destroy,
},
},
);
return &this->public.plugin;
}
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2016 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.
*/
/**
* @defgroup newhope_p ntru
* @ingroup plugins
*
* @defgroup newhope_plugin newhope_plugin
* @{ @ingroup newhope_p
*/
#ifndef NEWHOPE_PLUGIN_H_
#define NEWHOPE_PLUGIN_H_
#include <plugins/plugin.h>
typedef struct newhope_plugin_t newhope_plugin_t;
/**
* Plugin implementing New Hope-based key exchange
*/
struct newhope_plugin_t {
/**
* implements plugin interface
*/
plugin_t plugin;
};
#endif /** NEWHOPE_PLUGIN_H_ @}*/
@@ -0,0 +1,217 @@
/*
* Copyright (C) 2016 Andreas Steffen
* HSR Hochschule fuer Technik Rapperswil
*
* Based on public domain code by Erdem Alkim, Léo Ducas, Thomas Pöppelmann,
* and Peter Schwabe.
*
* 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 "newhope_reconciliation.h"
typedef struct private_newhope_reconciliation_t private_newhope_reconciliation_t;
/**
* Private data of an newhope_reconciliation_t object.
*/
struct private_newhope_reconciliation_t {
/**
* Public newhope_reconciliation_t interface.
*/
newhope_reconciliation_t public;
/**
* Array sizes
*/
int n, n4;
/**
* Multiples of modulus q
*/
int32_t q, q2, q4, q8, q16;
};
static inline int32_t rec_abs(int32_t v)
{
int32_t mask = v >> 31;
return (v ^ mask) - mask;
}
/**
* Auxiliary function used by help_reconcile() method
*/
static int32_t rec_f(private_newhope_reconciliation_t *this,
int32_t v, uint8_t r, int32_t *v0, int32_t *v1)
{
int32_t x, xit, t, b;
x = 8 * v + 2 * r;
/* compute t = x/q */
b = x * 2730;
t = b >> 25;
b = x - t * this->q;
b = this->q - 1 - b;
b >>= 31;
t -= b;
r = t & 0x01;
xit = (t >> 1);
*v0 = xit + r ; /* v0 = round(x/(2q)) */
t -= 1;
r = t & 0x01;
*v1 = ( t>> 1) + r;
return rec_abs(x - (*v0) * this->q2);
}
/**
* Auxiliary function used by reconcile() method
*/
static int32_t rec_g(private_newhope_reconciliation_t *this, int32_t x)
{
int32_t t, r, b;
/* t = x/(4*q) */
b = x * 2730;
t = b >> 27;
b = x - t * this->q4;
b = this->q4 - 1 - b;
b >>= 31;
t -= b;
r = t & 0x01;
t = (t >> 1) + r; /* t = round(x/(8q)) */
t *= this->q8;
return abs(t - x);
}
METHOD(newhope_reconciliation_t, help_reconcile, uint8_t*,
private_newhope_reconciliation_t *this, uint32_t *v, uint8_t *rbits)
{
int32_t v0[4], v1[4], v_tmp[4], k;
int i, i0, i1, i2, i3, j;
uint8_t *r, rbit;
/* allocate output vector */
r = (uint8_t*)malloc(this->n);
for (i = 0; i < this->n4/8; i++)
{
for (j = 0; j < 8; j++)
{
i0 = 8*i + j;
i1 = i0 + this->n4;
i2 = i1 + this->n4;
i3 = i2 + this->n4;
/* iterate through all 256 random bits */
rbit = (rbits[i] >> j) & 0x01;
k = rec_f(this, v[i0], rbit, &v0[0], &v1[0]);
k += rec_f(this, v[i1], rbit, &v0[1], &v1[1]);
k += rec_f(this, v[i2], rbit, &v0[2], &v1[2]);
k += rec_f(this, v[i3], rbit, &v0[3], &v1[3]);
k = (this->q2 - 1 - k) >> 31;
v_tmp[0] = ((~k) & v0[0]) ^ (k & v1[0]);
v_tmp[1] = ((~k) & v0[1]) ^ (k & v1[1]);
v_tmp[2] = ((~k) & v0[2]) ^ (k & v1[2]);
v_tmp[3] = ((~k) & v0[3]) ^ (k & v1[3]);
r[i0] = (v_tmp[0] - v_tmp[3]) & 0x03;
r[i1] = (v_tmp[1] - v_tmp[3]) & 0x03;
r[i2] = (v_tmp[2] - v_tmp[3]) & 0x03;
r[i3] = (v_tmp[3] - k + v_tmp[3]) & 0x03;
}
}
return r;
}
METHOD(newhope_reconciliation_t, reconcile, chunk_t,
private_newhope_reconciliation_t *this, uint32_t *v, uint8_t *r)
{
size_t key_len;
uint8_t *key;
int32_t tmp[4], t;
int i, i0, i1, i2, i3, j;
key_len = this->n4 / 8;
key = (uint8_t*)malloc(key_len);
memset(key, 0x00, key_len);
for (i = 0; i < key_len; i++)
{
for (j = 0; j < 8; j++)
{
i0 = 8*i + j;
i1 = i0 + this->n4;
i2 = i1 + this->n4;
i3 = i2 + this->n4;
tmp[0] = this->q16 + 8 * (int32_t)v[i0] -
this->q * (2*r[i0] + r[i3]);
tmp[1] = this->q16 + 8 * (int32_t)v[i1] -
this->q * (2*r[i1] + r[i3]);
tmp[2] = this->q16 + 8 * (int32_t)v[i2] -
this->q * (2*r[i2] + r[i3]);
tmp[3] = this->q16 + 8 * (int32_t)v[i3] -
this->q * ( r[i3]);
t = rec_g(this, tmp[0]) + rec_g(this, tmp[1]) +
rec_g(this, tmp[2]) + rec_g(this, tmp[3]) - this->q8;
key[i] |= ((t >> 31) & 0x01) << j;
}
}
return chunk_create(key, key_len);
}
METHOD(newhope_reconciliation_t, destroy, void,
private_newhope_reconciliation_t *this)
{
free(this);
}
/*
* Described in header.
*/
newhope_reconciliation_t *newhope_reconciliation_create(int n, int32_t q)
{
private_newhope_reconciliation_t *this;
INIT(this,
.public = {
.help_reconcile = _help_reconcile,
.reconcile = _reconcile,
.destroy = _destroy,
},
.n = n,
.n4 = n / 4,
.q = q,
.q2 = 2 * q,
.q4 = 4 * q,
.q8 = 8 * q,
.q16 = 16 * q,
);
return &this->public;
}
@@ -0,0 +1,70 @@
/*
* Copyright (C) 2016 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.
*/
/**
* @defgroup newhope_reconciliation newhope_reconciliation
* @{ @ingroup newhope_p
*/
#ifndef NEWHOPE_RECONCILIATION_H_
#define NEWHOPE_RECONCILIATION_H_
typedef struct newhope_reconciliation_t newhope_reconciliation_t;
#include <library.h>
/**
* Class assisting the error reconciliation
* resulting in a key exchange error rate < 2^(-60)
*/
struct newhope_reconciliation_t {
/**
* Generate reconciliation polynomial
*
* @param v polynomial v
* @param rbits pseudo random bit array
* @return return array with reconciliation polynomial
*/
uint8_t* (*help_reconcile)(newhope_reconciliation_t *this,
uint32_t *v, uint8_t *rbits);
/**
* Use reconciliation polynomial r to derive shared secret
*
* @param v polynomial v or v'
* @param r reconciliation polynomial r
* @return Return shared secret
*/
chunk_t (*reconcile)(newhope_reconciliation_t *this,
uint32_t *v, uint8_t *r);
/**
* Destroy a newhope_reconciliation_t object
*/
void (*destroy)(newhope_reconciliation_t *this);
};
/**
* Creates a new newhope_reconciliation_t object.
*
* @param n array size
* @param q prime modulus
* @return newhope_reconciliation_t object
*/
newhope_reconciliation_t *newhope_reconciliation_create(int n, int32_t q);
#endif /** NEWHOPE_RECONCILIATION_H_ @}*/
@@ -0,0 +1 @@
newhope_tests
@@ -0,0 +1,25 @@
TESTS = newhope_tests
check_PROGRAMS = $(TESTS)
newhope_tests_SOURCES = \
suites/test_newhope_ke.c \
suites/test_newhope_noise.c \
suites/test_newhope_reconciliation.c \
newhope_tests.h newhope_tests.c
newhope_tests_CFLAGS = \
-I$(top_srcdir)/src/libstrongswan \
-I$(top_srcdir)/src/libstrongswan/tests \
-I$(top_srcdir)/src/libstrongswan/math/libnttfft \
-I$(top_srcdir)/src/libstrongswan/plugins/newhope \
-DPLUGINDIR=\""$(abs_top_builddir)/src/libstrongswan/plugins\"" \
-DPLUGINS=\""${s_plugins}\"" \
@COVERAGE_CFLAGS@
newhope_tests_LDFLAGS = @COVERAGE_LDFLAGS@
newhope_tests_LDADD = \
$(top_builddir)/src/libstrongswan/libstrongswan.la \
$(top_builddir)/src/libstrongswan/tests/libtest.la \
$(top_builddir)/src/libstrongswan/math/libnttfft/libnttfft.la \
../libnewhope.la
@@ -0,0 +1,60 @@
/*
* 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 "newhope_tests.h"
#undef TEST_SUITE
static test_configuration_t tests[] = {
#define TEST_SUITE(x) \
{ .suite = x, },
#include "newhope_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("newhope", tests, test_runner_init);
}
@@ -0,0 +1,18 @@
/*
* Copyright (C) 2016 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(newhope_ke_suite_create)
TEST_SUITE(newhope_noise_suite_create)
TEST_SUITE(newhope_reconciliation_suite_create)
@@ -0,0 +1,193 @@
/*
* Copyright (C) 2016 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 <newhope_ke.h>
#include <library.h>
#include <time.h>
const int count = 1000;
START_TEST(test_newhope_ke_good)
{
chunk_t i_msg, r_msg, i_shared_secret, r_shared_secret;
diffie_hellman_t *i_nh, *r_nh;
struct timespec start, stop;
int i;
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &start);
for (i = 0; i < count; i++)
{
i_nh = lib->crypto->create_dh(lib->crypto, NH_128_BIT);
ck_assert(i_nh != NULL);
ck_assert(i_nh->get_dh_group(i_nh) == NH_128_BIT);
ck_assert(i_nh->get_my_public_value(i_nh, &i_msg));
ck_assert(i_msg.len = 1824);
r_nh = lib->crypto->create_dh(lib->crypto, NH_128_BIT);
ck_assert(r_nh != NULL);
ck_assert(r_nh->set_other_public_value(r_nh, i_msg));
ck_assert(r_nh->get_my_public_value(r_nh, &r_msg));
ck_assert(r_msg.len == 2048);
ck_assert(r_nh->get_shared_secret(r_nh, &r_shared_secret));
ck_assert(r_shared_secret.len == 32);
ck_assert(i_nh->set_other_public_value(i_nh, r_msg));
ck_assert(i_nh->get_shared_secret(i_nh, &i_shared_secret));
ck_assert(i_shared_secret.len == 32);
ck_assert(chunk_equals(i_shared_secret, r_shared_secret));
/* cleanup */
chunk_clear(&i_shared_secret);
chunk_clear(&r_shared_secret);
chunk_free(&i_msg);
chunk_free(&r_msg);
i_nh->destroy(i_nh);
r_nh->destroy(r_nh);
}
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &stop);
DBG0(DBG_LIB, "%d Newhope DH loops in %d ms\n", count,
(stop.tv_nsec - start.tv_nsec) / 1000000 +
(stop.tv_sec - start.tv_sec) * 1000);
}
END_TEST
START_TEST(test_newhope_ke_wrong)
{
chunk_t i_msg, r_msg, i_shared_secret, r_shared_secret;
diffie_hellman_t *i_nh, *r_nh;
i_nh = lib->crypto->create_dh(lib->crypto, NH_128_BIT);
ck_assert(i_nh != NULL);
ck_assert(i_nh->get_my_public_value(i_nh, &i_msg));
r_nh = lib->crypto->create_dh(lib->crypto, NH_128_BIT);
ck_assert(r_nh != NULL);
ck_assert(r_nh->set_other_public_value(r_nh, i_msg));
ck_assert(r_nh->get_my_public_value(r_nh, &r_msg));
/* destroy 1st instance of i_nh */
i_nh->destroy(i_nh);
chunk_free(&i_msg);
/* create 2nd instance of i_nh */
i_nh = lib->crypto->create_dh(lib->crypto, NH_128_BIT);
ck_assert(i_nh != NULL);
ck_assert(i_nh->get_my_public_value(i_nh, &i_msg));
ck_assert(i_nh->set_other_public_value(i_nh, r_msg));
ck_assert(r_nh->get_shared_secret(r_nh, &r_shared_secret));
ck_assert(i_nh->get_shared_secret(i_nh, &i_shared_secret));
ck_assert(!chunk_equals(i_shared_secret, r_shared_secret));
/* cleanup */
chunk_clear(&i_shared_secret);
chunk_clear(&r_shared_secret);
chunk_free(&i_msg);
chunk_free(&r_msg);
i_nh->destroy(i_nh);
r_nh->destroy(r_nh);
}
END_TEST
START_TEST(test_newhope_ke_fail_i)
{
diffie_hellman_t *i_nh;
char buf_ff[2048];
int i;
chunk_t i_msg;
chunk_t r_msg[] = {
chunk_empty,
chunk_from_chars(0x00),
chunk_create(buf_ff, 2047),
chunk_create(buf_ff, 2048),
};
memset(buf_ff, 0xff, sizeof(buf_ff));
for (i = 0; i < countof(r_msg); i++)
{
i_nh = lib->crypto->create_dh(lib->crypto, NH_128_BIT);
ck_assert(i_nh != NULL);
ck_assert(i_nh->get_my_public_value(i_nh, &i_msg));
ck_assert(!i_nh->set_other_public_value(i_nh, r_msg[i]));
chunk_free(&i_msg);
i_nh->destroy(i_nh);
}
}
END_TEST
START_TEST(test_newhope_ke_fail_r)
{
diffie_hellman_t *r_nh;
char buf_ff[1824];
int i;
chunk_t i_msg[] = {
chunk_empty,
chunk_from_chars(0x00),
chunk_create(buf_ff, 1823),
chunk_create(buf_ff, 1824),
};
memset(buf_ff, 0xff, sizeof(buf_ff));
for (i = 0; i < countof(i_msg); i++)
{
r_nh = lib->crypto->create_dh(lib->crypto, NH_128_BIT);
ck_assert(r_nh != NULL);
ck_assert(!r_nh->set_other_public_value(r_nh, i_msg[i]));
r_nh->destroy(r_nh);
}
}
END_TEST
Suite *newhope_ke_suite_create()
{
Suite *s;
TCase *tc;
s = suite_create("newhope_ke");
tc = tcase_create("ke_good");
test_case_set_timeout(tc, 30);
tcase_add_test(tc, test_newhope_ke_good);
suite_add_tcase(s, tc);
tc = tcase_create("ke_wrong");
tcase_add_test(tc, test_newhope_ke_wrong);
suite_add_tcase(s, tc);
tc = tcase_create("ke_fail_i");
tcase_add_test(tc, test_newhope_ke_fail_i);
suite_add_tcase(s, tc);
tc = tcase_create("ke_fail_r");
tcase_add_test(tc, test_newhope_ke_fail_r);
suite_add_tcase(s, tc);
return s;
}
@@ -0,0 +1,676 @@
/*
* Copyright (C) 2016 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 <newhope_noise.h>
#include <library.h>
static const uint16_t n = 1024;
static const uint16_t q = 12289;
static const size_t seed_len = 32;
typedef struct {
uint8_t key;
uint8_t nonce;
uint8_t uniform[64];
uint32_t poly[1024];
} noise_t;
static noise_t noises[] = {
{ 0x00, 0x00, /* polynomial s */
{ 0x9f, 0x07, 0xe7, 0xbe, 0x55, 0x51, 0x38, 0x7a, 0x98, 0xba,
0x97, 0x7c, 0x73, 0x2d, 0x08, 0x0d, 0xcb, 0x0f, 0x29, 0xa0,
0x48, 0xe3, 0x65, 0x69, 0x12, 0xc6, 0x53, 0x3e, 0x32, 0xee,
0x7a, 0xed, 0x29, 0xb7, 0x21, 0x76, 0x9c, 0xe6, 0x4e, 0x43,
0xd5, 0x71, 0x33, 0xb0, 0x74, 0xd8, 0x39, 0xd5, 0x31, 0xed,
0x1f, 0x28, 0x51, 0x0a, 0xfb, 0x45, 0xac, 0xe1, 0x0a, 0x1f,
0x4b, 0x79, 0x4d, 0x6f },
{ 12286, 12288, 12287, 5, 4, 12288, 12286, 12287, 2, 2,
2, 12288, 2, 12284, 1, 12288, 12288, 12288, 6, 12288,
0, 4, 1, 12285, 12286, 2, 12284, 12287, 1, 5,
5, 12286, 12288, 2, 12286, 0, 3, 1, 0, 2,
0, 0, 4, 12283, 12284, 4, 0, 12288, 3, 12288,
0, 4, 1, 12288, 12286, 0, 3, 1, 12286, 12287,
12285, 3, 2, 3, 12286, 0, 6, 6, 12288, 12284,
0, 12282, 1, 0, 4, 1, 0, 3, 2, 2,
3, 3, 2, 12288, 3, 1, 12287, 12285, 0, 12288,
0, 0, 12288, 12287, 12284, 12286, 0, 12288, 4, 4,
12288, 5, 12286, 2, 12288, 5, 1, 12283, 1, 12288,
1, 12288, 12287, 12285, 2, 2, 12285, 12284, 0, 12285,
12287, 0, 1, 0, 2, 12288, 12288, 12287, 0, 4,
12288, 12285, 12288, 0, 2, 1, 12287, 3, 1, 3,
5, 12286, 1, 0, 12286, 0, 4, 0, 12288, 1,
12288, 4, 5, 12283, 12288, 1, 3, 12283, 12286, 5,
1, 12286, 12287, 12286, 0, 12287, 12285, 1, 0, 0,
1, 3, 0, 0, 0, 12284, 12286, 2, 4, 12288,
6, 1, 2, 12288, 1, 12287, 12286, 12284, 12287, 1,
3, 12284, 0, 0, 6, 12286, 7, 5, 2, 3,
12285, 12287, 12285, 2, 3, 12283, 2, 12284, 12288, 3,
12288, 1, 4, 12287, 2, 12288, 12288, 1, 12286, 12284,
2, 1, 5, 12286, 0, 12288, 0, 0, 0, 12287,
1, 0, 3, 0, 0, 6, 2, 12283, 1, 3,
3, 12284, 3, 1, 12286, 2, 12288, 0, 6, 1,
1, 12285, 12287, 12288, 4, 2, 12288, 3, 12286, 12288,
12287, 3, 3, 2, 7, 4, 12287, 12286, 12287, 2,
2, 12287, 1, 12288, 1, 12287, 12283, 12287, 12288, 1,
12283, 0, 12286, 12288, 4, 12287, 12286, 12286, 2, 2,
12287, 5, 12288, 4, 0, 12287, 1, 3, 12286, 2,
1, 1, 12288, 12287, 5, 12288, 0, 0, 1, 0,
12286, 6, 2, 1, 2, 5, 12286, 6, 12286, 12288,
0, 12286, 3, 12283, 12288, 12284, 0, 7, 2, 6,
1, 12288, 12285, 12284, 1, 0, 0, 2, 12288, 12288,
12288, 3, 3, 1, 3, 12286, 4, 3, 12284, 4,
1, 12287, 12287, 12285, 0, 12287, 12287, 12287, 12286, 12288,
1, 12287, 1, 0, 12288, 2, 0, 4, 0, 12287,
12285, 12285, 5, 3, 12282, 0, 12287, 5, 12287, 1,
12283, 12288, 12288, 3, 1, 1, 3, 12288, 12283, 5,
12288, 12288, 5, 5, 1, 12286, 12286, 12288, 1, 2,
1, 3, 12287, 12288, 12284, 12287, 1, 12287, 0, 12286,
12285, 1, 12287, 12282, 12286, 12287, 0, 12285, 4, 2,
1, 12282, 0, 1, 12288, 12285, 12284, 12286, 12286, 12287,
12288, 1, 12288, 4, 12287, 4, 12287, 12287, 0, 1,
12287, 3, 1, 12286, 12286, 4, 6, 12288, 1, 12285,
12286, 12287, 0, 12287, 12287, 1, 12286, 5, 0, 2,
12283, 12284, 1, 12286, 0, 12287, 12286, 12288, 1, 4,
4, 12283, 2, 6, 1, 12288, 12286, 2, 7, 2,
1, 12288, 5, 12284, 12288, 12288, 1, 7, 3, 12283,
1, 12286, 2, 12288, 12287, 1, 12286, 1, 12286, 12288,
12287, 3, 2, 2, 0, 12284, 12287, 1, 1, 12284,
12286, 1, 2, 1, 0, 12285, 1, 0, 1, 2,
2, 4, 12288, 1, 12288, 5, 0, 12287, 12288, 2,
0, 12288, 12287, 0, 12288, 12288, 0, 0, 12285, 4,
2, 12288, 0, 2, 0, 12288, 1, 3, 12287, 12288,
12288, 12288, 12286, 0, 12285, 12286, 12287, 3, 0, 12286,
2, 1, 12285, 2, 12288, 0, 5, 0, 1, 12288,
12288, 4, 3, 3, 12286, 2, 12288, 4, 12288, 6,
2, 12286, 4, 12287, 2, 12287, 0, 12284, 12288, 0,
12286, 12288, 3, 4, 12286, 12288, 1, 3, 12286, 3,
4, 1, 1, 6, 3, 1, 1, 0, 12288, 4,
0, 12288, 0, 0, 0, 12288, 2, 4, 2, 12287,
0, 0, 3, 2, 3, 4, 0, 3, 2, 12288,
2, 4, 6, 12286, 12284, 12287, 1, 0, 0, 4,
1, 3, 12282, 1, 2, 2, 0, 3, 12282, 2,
12287, 2, 12288, 4, 12288, 3, 3, 12283, 12288, 12288,
12286, 12287, 5, 4, 3, 3, 12288, 12284, 2, 2,
0, 12288, 1, 3, 3, 4, 12284, 12288, 0, 1,
12284, 0, 12286, 12287, 0, 0, 12287, 0, 1, 6,
12288, 1, 12284, 12287, 12282, 12288, 4, 12287, 1, 12286,
1, 12286, 12286, 1, 4, 0, 12288, 1, 12288, 1,
12285, 3, 1, 0, 1, 0, 12288, 12287, 2, 2,
0, 12288, 3, 12284, 2, 12288, 12288, 12288, 12287, 3,
3, 0, 12286, 12286, 1, 2, 12286, 12287, 0, 1,
12288, 12287, 12287, 12288, 12288, 1, 9, 1, 12288, 12287,
2, 1, 1, 0, 12287, 12287, 2, 2, 12288, 12285,
1, 12287, 4, 0, 2, 1, 1, 3, 12284, 12286,
1, 2, 12288, 12287, 4, 1, 12285, 0, 1, 2,
12288, 1, 3, 0, 12286, 0, 12288, 12286, 12287, 12286,
1, 12284, 1, 2, 2, 12288, 0, 12288, 1, 12284,
2, 3, 12287, 1, 12285, 12288, 0, 1, 12284, 2,
12288, 12286, 12286, 3, 12288, 12282, 3, 12287, 12288, 12287,
4, 12287, 1, 2, 9, 12283, 12286, 12286, 0, 4,
12288, 12288, 4, 0, 1, 1, 2, 12284, 1, 1,
0, 12288, 1, 0, 12287, 1, 1, 5, 2, 1,
12288, 3, 12287, 5, 4, 1, 4, 12287, 12285, 3,
12286, 1, 3, 0, 12287, 0, 12286, 12287, 12287, 12287,
3, 2, 12286, 12284, 2, 12288, 1, 1, 12288, 3,
1, 3, 12284, 3, 12282, 12288, 3, 0, 2, 12288,
0, 5, 0, 2, 0, 12281, 12285, 4, 3, 4,
2, 12284, 0, 0, 2, 2, 12287, 12284, 2, 12286,
1, 12288, 1, 12286, 12286, 12287, 4, 0, 6, 3,
0, 3, 12288, 12288, 12288, 12287, 3, 1, 1, 1,
2, 12287, 12284, 3, 12286, 12280, 3, 12284, 12287, 12288,
5, 12288, 12284, 2, 12285, 4, 3, 12286, 6, 2,
1, 12287, 0, 1, 2, 12286, 1, 0, 12287, 0,
1, 1, 12286, 2, 12285, 0, 1, 12288, 0, 1,
12288, 1, 12288, 12287, 12287, 12285, 12282, 12288, 2, 12288,
2, 12284, 1, 12284, 12287, 12286, 12288, 0, 12288, 1,
12283, 12286, 5, 3, 0, 12286, 12286, 3, 1, 0,
1, 12288, 12288, 4, 1, 12286, 12287, 12285, 2, 0,
2, 12287, 1, 12285, 12288, 12286, 12288, 2, 2, 12285,
3, 12286, 12285, 12287 }
},
{ 0x00, 0x01, /* polynomial e */
{ 0x46, 0xf0, 0xf6, 0xef, 0xee, 0x15, 0xc8, 0xf1, 0xb1, 0x98,
0xcb, 0x49, 0xd9, 0x2b, 0x99, 0x08, 0x67, 0x90, 0x51, 0x59,
0x44, 0x0c, 0xc7, 0x23, 0x91, 0x6d, 0xc0, 0x01, 0x28, 0x26,
0x98, 0x10, 0x39, 0xce, 0x17, 0x66, 0xaa, 0x25, 0x42, 0xb0,
0x5d, 0xb3, 0xbd, 0x80, 0x9a, 0xb1, 0x42, 0x48, 0x9d, 0x5d,
0xbf, 0xe1, 0x27, 0x3e, 0x73, 0x99, 0x63, 0x7b, 0x4b, 0x32,
0x13, 0x76, 0x8a, 0xaa },
{ 12283, 1, 12288, 4, 0, 12285, 5, 1, 1, 2,
3, 4, 12288, 0, 3, 1, 1, 0, 12286, 6,
1, 0, 1, 0, 4, 2, 12288, 3, 0, 5,
1, 5, 2, 12285, 4, 12288, 3, 2, 12288, 2,
12288, 12285, 12287, 6, 12282, 1, 12286, 7, 12287, 4,
2, 2, 12288, 12285, 0, 2, 0, 12288, 1, 12287,
12287, 2, 1, 2, 1, 12285, 12288, 12286, 1, 2,
12287, 12288, 12288, 1, 0, 12287, 0, 4, 2, 6,
12287, 12285, 12283, 12285, 5, 12283, 12286, 1, 12283, 2,
3, 12286, 12285, 2, 5, 12286, 3, 0, 3, 12286,
5, 12285, 12287, 12288, 1, 5, 3, 5, 1, 1,
1, 12288, 5, 0, 12288, 3, 2, 12288, 12285, 12288,
5, 6, 0, 2, 1, 12287, 12288, 12287, 3, 12284,
2, 0, 3, 0, 0, 12288, 0, 2, 2, 2,
0, 1, 2, 2, 0, 0, 12287, 12285, 0, 4,
1, 12283, 3, 5, 12288, 12286, 12287, 6, 2, 0,
0, 12287, 2, 2, 12288, 0, 2, 12288, 12287, 12288,
12288, 1, 12288, 1, 12288, 2, 4, 2, 1, 1,
0, 12287, 3, 2, 6, 2, 1, 12288, 12285, 6,
0, 1, 12284, 12287, 12287, 12286, 5, 4, 0, 5,
12287, 12286, 12288, 12286, 0, 3, 1, 12287, 12287, 12288,
12288, 12286, 1, 0, 3, 12287, 3, 1, 12283, 1,
12288, 5, 1, 4, 12286, 12287, 2, 0, 0, 0,
12281, 12286, 0, 8, 5, 0, 4, 0, 12287, 5,
1, 3, 2, 12286, 12286, 12288, 12285, 12285, 12287, 0,
12284, 12287, 1, 0, 2, 1, 12286, 12288, 2, 12285,
0, 0, 0, 1, 0, 6, 1, 12288, 12287, 12287,
0, 3, 12288, 12288, 12287, 0, 12287, 1, 3, 0,
0, 12286, 12286, 4, 4, 12287, 1, 3, 4, 12287,
12284, 2, 12288, 12286, 12283, 12285, 1, 3, 1, 12288,
0, 3, 3, 12284, 12285, 5, 3, 12288, 3, 4,
3, 1, 12288, 0, 12288, 1, 0, 0, 3, 0,
3, 2, 12287, 12288, 0, 12288, 0, 2, 12285, 4,
0, 12287, 12287, 1, 1, 1, 12287, 12285, 4, 12282,
3, 1, 1, 12288, 2, 4, 12285, 12286, 3, 1,
0, 12287, 12283, 12285, 2, 5, 1, 1, 12288, 12288,
0, 8, 3, 12287, 12285, 12287, 12286, 12284, 1, 12286,
1, 12288, 2, 3, 12288, 12288, 2, 12288, 12284, 12285,
0, 3, 12288, 12288, 2, 3, 7, 12287, 3, 3,
3, 12284, 0, 0, 1, 12283, 5, 0, 1, 12288,
3, 12286, 12287, 12286, 0, 0, 12287, 12283, 4, 12283,
0, 0, 3, 12285, 5, 12286, 12282, 12288, 1, 12287,
12288, 1, 5, 2, 12287, 2, 12288, 7, 12288, 3,
5, 1, 0, 12287, 1, 12287, 3, 2, 4, 2,
12287, 12286, 12288, 2, 5, 1, 12286, 4, 0, 2,
6, 12286, 2, 12286, 3, 12288, 5, 12285, 0, 2,
12287, 5, 12286, 12284, 7, 12285, 12286, 12284, 12287, 1,
12288, 12284, 12286, 2, 4, 2, 2, 12283, 12286, 2,
2, 12283, 1, 12286, 1, 0, 12284, 3, 0, 4,
1, 0, 4, 12288, 0, 12287, 12287, 12287, 12286, 12284,
12288, 3, 1, 12285, 0, 3, 8, 4, 2, 12288,
3, 12287, 12287, 2, 3, 12288, 12286, 2, 12286, 12288,
0, 1, 12287, 12285, 0, 12285, 12288, 12287, 1, 12287,
0, 12284, 0, 1, 1, 12285, 0, 0, 0, 12287,
12287, 3, 0, 4, 12288, 1, 12288, 12285, 12283, 0,
12286, 12286, 12285, 12285, 12287, 1, 0, 2, 3, 1,
2, 12286, 12288, 3, 12286, 12288, 12288, 6, 2, 2,
0, 12288, 2, 5, 12288, 0, 12284, 12282, 12286, 1,
12288, 12288, 12286, 12288, 3, 12286, 2, 0, 12283, 0,
4, 2, 12288, 0, 12286, 0, 4, 3, 12286, 12287,
4, 12288, 3, 2, 12283, 1, 1, 1, 3, 12286,
4, 0, 12288, 12285, 12287, 0, 0, 12286, 4, 0,
12286, 2, 12288, 12288, 12285, 12283, 5, 3, 12286, 12288,
4, 1, 12283, 0, 12288, 0, 12287, 12287, 0, 3,
12287, 12287, 2, 2, 3, 0, 1, 4, 12288, 3,
3, 0, 12284, 12285, 4, 12288, 1, 12287, 0, 1,
12283, 1, 12284, 12287, 12286, 12285, 0, 0, 3, 12285,
3, 1, 12288, 12287, 12284, 12282, 5, 3, 3, 2,
12285, 4, 12288, 0, 3, 12288, 4, 0, 12283, 12288,
2, 12285, 12288, 12282, 0, 2, 12285, 3, 1, 12284,
1, 5, 7, 12286, 5, 12285, 1, 2, 0, 4,
12283, 12287, 12286, 2, 12280, 12287, 12288, 2, 12285, 12286,
2, 1, 2, 1, 2, 2, 3, 3, 0, 0,
4, 2, 12288, 12286, 4, 0, 1, 12288, 2, 12287,
12288, 12288, 1, 3, 12283, 12288, 1, 12287, 1, 1,
3, 12288, 12288, 1, 2, 1, 1, 12283, 7, 12286,
12288, 1, 12288, 12287, 12284, 7, 2, 12285, 12286, 0,
0, 0, 2, 4, 12288, 0, 12284, 12285, 12286, 2,
12284, 2, 4, 6, 3, 12287, 12288, 12285, 1, 2,
12286, 0, 0, 12287, 12288, 0, 12286, 2, 1, 1,
1, 3, 1, 12285, 4, 0, 12287, 12288, 12287, 0,
12288, 12287, 12288, 12287, 12288, 12288, 0, 12287, 12284, 0,
12288, 12285, 3, 2, 4, 2, 12284, 3, 1, 3,
4, 12288, 12285, 12284, 12287, 1, 4, 0, 2, 12288,
4, 12288, 12287, 3, 1, 0, 0, 12284, 12287, 2,
4, 12287, 2, 12288, 0, 2, 2, 3, 12287, 12286,
8, 12286, 12285, 0, 12285, 2, 3, 5, 12287, 12288,
6, 12288, 12284, 0, 0, 3, 1, 2, 12284, 2,
1, 3, 2, 0, 0, 12288, 12287, 12288, 1, 12288,
4, 3, 12284, 1, 3, 12288, 12283, 12288, 1, 1,
2, 1, 1, 3, 1, 12288, 0, 12288, 2, 0,
0, 12284, 12283, 3, 12288, 0, 2, 12287, 0, 0,
12286, 12286, 0, 0, 2, 4, 12288, 1, 2, 3,
2, 12286, 12286, 1, 2, 4, 12288, 12288, 12284, 12287,
6, 2, 12288, 12286, 0, 0, 3, 12286, 12288, 12287,
12286, 12287, 3, 1, 12286, 0, 4, 3, 12286, 5,
2, 1, 12287, 12286, 4, 12287, 0, 5, 12288, 0,
12288, 2, 2, 1, 1, 0, 0, 12288, 12288, 12288,
0, 0, 12288, 12287, 5, 1, 12288, 1, 10, 1,
0, 0, 2, 2, 2, 0, 12288, 4, 2, 12283,
3, 1, 1, 12285, 2, 12285, 5, 7, 5, 12288,
0, 12287, 5, 1, 12288, 12286, 12287, 0, 0, 0,
12287, 1, 3, 12288 }
},
{ 0x01, 0x00, /* polynomial s' */
{ 0x3a, 0xeb, 0x52, 0x24, 0xec, 0xf8, 0x49, 0x92, 0x9b, 0x9d,
0x82, 0x8d, 0xb1, 0xce, 0xd4, 0xdd, 0x83, 0x20, 0x25, 0xe8,
0x01, 0x8b, 0x81, 0x60, 0xb8, 0x22, 0x84, 0xf3, 0xc9, 0x49,
0xaa, 0x5a, 0x8e, 0xca, 0x00, 0xbb, 0xb4, 0xa7, 0x3b, 0xda,
0xd1, 0x92, 0xb5, 0xc4, 0x2f, 0x73, 0xf2, 0xfd, 0x4e, 0x27,
0x36, 0x44, 0xc8, 0xb3, 0x61, 0x25, 0xa6, 0x4a, 0xdd, 0xeb,
0x00, 0x6c, 0x13, 0xa0 },
{ 5, 4, 4, 12288, 12286, 1, 12287, 12288, 2, 12288,
12288, 12287, 2, 2, 12284, 12288, 12288, 3, 2, 3,
12287, 2, 2, 0, 0, 2, 5, 12285, 5, 12287,
2, 12282, 12286, 2, 1, 2, 1, 1, 12288, 12285,
12287, 12286, 2, 0, 0, 12285, 0, 0, 12287, 12286,
12285, 12286, 2, 12288, 12288, 0, 1, 2, 12286, 2,
1, 0, 0, 2, 1, 12288, 1, 12287, 1, 0,
0, 2, 12285, 2, 2, 12288, 12286, 3, 12287, 0,
1, 1, 0, 2, 12287, 2, 1, 2, 3, 0,
0, 1, 12288, 12288, 2, 12287, 12286, 12286, 6, 12288,
0, 0, 4, 0, 12286, 0, 4, 12288, 12288, 5,
12287, 12288, 12285, 2, 12285, 12288, 1, 0, 2, 12288,
12286, 1, 3, 12285, 2, 2, 1, 1, 12288, 12288,
12287, 1, 12288, 3, 0, 12285, 4, 12285, 12287, 2,
2, 12287, 12287, 12286, 12288, 12284, 2, 12286, 4, 1,
0, 12286, 12284, 3, 12286, 3, 12286, 3, 4, 1,
12288, 12282, 2, 2, 12284, 0, 12286, 12283, 3, 0,
4, 2, 4, 2, 12285, 10, 12288, 8, 3, 2,
2, 0, 1, 0, 0, 12286, 2, 12284, 4, 1,
12287, 12287, 1, 1, 12286, 1, 0, 12285, 12288, 12286,
12287, 2, 1, 12284, 12288, 12285, 12285, 3, 0, 1,
4, 4, 1, 0, 2, 1, 12288, 1, 12287, 0,
12286, 4, 2, 3, 3, 12285, 12288, 12288, 5, 2,
0, 4, 3, 12287, 12287, 5, 2, 3, 12284, 0,
8, 1, 1, 0, 5, 12288, 12288, 12288, 12286, 6,
3, 12288, 12286, 12287, 4, 12288, 2, 12288, 12284, 12287,
4, 12288, 0, 0, 3, 0, 4, 4, 12287, 0,
3, 0, 12285, 12287, 12288, 12288, 0, 0, 12287, 12288,
12286, 0, 0, 12285, 12288, 4, 12287, 1, 2, 12288,
12285, 5, 4, 12283, 2, 0, 12288, 2, 0, 0,
12286, 12284, 3, 3, 3, 12287, 1, 1, 0, 1,
3, 12288, 4, 4, 0, 2, 0, 1, 12286, 12284,
2, 2, 12287, 3, 2, 12288, 3, 12286, 2, 12286,
12288, 4, 3, 12288, 2, 12288, 2, 1, 12288, 12288,
7, 12288, 12288, 0, 12288, 1, 12284, 12288, 12288, 12287,
12287, 1, 12285, 12287, 12287, 1, 0, 2, 12286, 3,
12288, 12288, 12287, 3, 5, 0, 0, 12287, 2, 12287,
12288, 8, 12287, 1, 2, 12288, 12284, 3, 0, 12287,
12284, 3, 0, 2, 1, 3, 4, 12287, 12286, 12288,
12286, 0, 0, 12287, 12285, 0, 12286, 2, 1, 12287,
12288, 5, 12287, 12287, 12286, 2, 12283, 0, 0, 12286,
2, 12284, 5, 0, 1, 12287, 0, 3, 1, 12285,
12288, 0, 3, 12287, 2, 12286, 0, 1, 12288, 1,
12284, 12281, 12284, 12288, 12285, 2, 5, 4, 12286, 0,
12287, 12288, 12286, 12285, 3, 12282, 1, 12287, 2, 0,
6, 12288, 4, 12286, 3, 12288, 12286, 12284, 3, 1,
6, 3, 2, 1, 2, 1, 1, 12288, 12287, 1,
3, 3, 1, 0, 0, 12288, 3, 12284, 12285, 12284,
1, 3, 12286, 0, 1, 12285, 12287, 1, 12285, 2,
0, 1, 12287, 1, 4, 3, 1, 12287, 0, 5,
1, 12288, 2, 1, 1, 4, 3, 12286, 3, 3,
2, 12287, 3, 12286, 0, 12288, 12285, 2, 3, 12286,
0, 12287, 5, 4, 1, 1, 12287, 12288, 2, 0,
0, 0, 2, 0, 12286, 4, 12288, 12288, 12285, 12286,
2, 12288, 12288, 0, 12288, 12286, 12284, 12287, 1, 5,
0, 12285, 12287, 2, 4, 3, 12285, 12287, 12288, 0,
12288, 12287, 12286, 2, 12288, 12286, 12284, 1, 2, 12287,
4, 1, 4, 4, 12284, 2, 0, 12288, 3, 1,
0, 4, 1, 6, 0, 12286, 12288, 12287, 12287, 0,
12284, 12285, 2, 12286, 1, 0, 3, 12288, 1, 2,
12284, 12286, 12285, 12283, 12285, 0, 12285, 2, 0, 2,
1, 3, 1, 12286, 12288, 1, 4, 0, 0, 12287,
12287, 12286, 0, 1, 12286, 0, 2, 12288, 2, 12287,
0, 0, 12286, 12287, 4, 6, 12286, 0, 12288, 0,
0, 12287, 2, 3, 4, 1, 3, 12286, 4, 0,
12288, 12286, 12287, 12287, 12288, 4, 12285, 1, 12286, 12286,
2, 12288, 0, 0, 1, 5, 12285, 1, 12281, 3,
12281, 2, 3, 0, 12284, 12288, 5, 0, 0, 12288,
0, 0, 12288, 12286, 3, 12287, 0, 2, 12288, 0,
3, 12288, 12286, 0, 12286, 12287, 12284, 0, 12286, 1,
12287, 12282, 12287, 12288, 0, 5, 12288, 2, 1, 12288,
1, 12285, 5, 2, 12286, 12285, 12287, 0, 2, 12288,
1, 12288, 1, 12286, 0, 2, 12287, 12287, 6, 12286,
12288, 0, 12286, 4, 6, 12287, 12287, 2, 2, 12285,
1, 12288, 12285, 12286, 5, 12288, 1, 2, 1, 7,
12286, 5, 12288, 12287, 12286, 12284, 1, 2, 12287, 4,
1, 1, 0, 1, 2, 12285, 2, 12288, 12284, 1,
1, 12287, 12286, 12285, 12287, 1, 12287, 3, 1, 12286,
0, 12286, 3, 3, 12288, 2, 12288, 5, 12288, 1,
2, 0, 12287, 1, 12287, 7, 2, 3, 0, 12287,
2, 12284, 12284, 12281, 12286, 12285, 12287, 12287, 0, 12288,
3, 4, 3, 2, 3, 1, 12288, 12286, 0, 12288,
12286, 1, 12286, 6, 12287, 1, 6, 5, 3, 1,
12286, 2, 1, 3, 1, 12286, 12285, 3, 2, 0,
0, 12284, 1, 1, 3, 3, 1, 1, 12288, 0,
12284, 1, 12288, 0, 0, 12287, 0, 4, 12285, 0,
4, 12283, 1, 1, 0, 12285, 0, 12286, 0, 0,
1, 0, 12286, 0, 12288, 3, 4, 0, 2, 1,
12287, 2, 12288, 1, 0, 12288, 0, 12288, 6, 12288,
12287, 12286, 3, 12284, 0, 12288, 12284, 12286, 12287, 12288,
12288, 12288, 4, 0, 2, 6, 12286, 1, 4, 12288,
2, 1, 0, 5, 2, 1, 12285, 0, 0, 12285,
4, 12286, 5, 1, 3, 2, 12287, 2, 0, 2,
7, 12283, 12288, 12288, 3, 0, 3, 12288, 3, 12286,
12288, 12287, 12288, 3, 0, 2, 4, 1, 12284, 2,
12288, 12286, 12287, 1, 1, 12288, 0, 12288, 12283, 6,
2, 1, 12288, 3, 12287, 12288, 1, 1, 12285, 0,
12286, 12287, 12288, 1, 2, 12287, 0, 4, 0, 12286,
2, 1, 12288, 12285, 12287, 0, 2, 12287, 6, 2,
0, 12287, 12288, 2, 12288, 12284, 12288, 12285, 4, 1,
12288, 12284, 12287, 4, 12284, 1, 3, 12284, 12282, 0,
12286, 12287, 2, 12286, 3, 4, 2, 12288, 3, 3,
1, 3, 12287, 12283 }
},
{ 0x01, 0x01, /* polynomial e' */
{ 0x58, 0xd8, 0x6a, 0xcd, 0xe2, 0x79, 0x61, 0x98, 0xfd, 0xea,
0xcf, 0x2a, 0xc0, 0xfd, 0xf0, 0x72, 0x86, 0x32, 0xdc, 0xe9,
0xc6, 0x45, 0x81, 0x80, 0x67, 0x06, 0x72, 0x28, 0xa6, 0xfe,
0x41, 0x2b, 0x78, 0x88, 0x58, 0x6d, 0x58, 0x47, 0x3e, 0xb7,
0x46, 0x60, 0xd8, 0x2f, 0xa0, 0x83, 0xe4, 0xbc, 0x81, 0xdd,
0xc6, 0x29, 0x8b, 0xee, 0xf9, 0xec, 0x90, 0x39, 0x9d, 0x46,
0xbf, 0x2d, 0x7c, 0xdf },
{ 12287, 3, 3, 1, 12285, 4, 1, 5, 12287, 12285,
12285, 12285, 1, 12288, 12287, 12288, 2, 3, 12283, 12288,
12285, 0, 0, 12286, 12287, 12288, 12288, 12288, 12288, 1,
12288, 2, 2, 5, 5, 0, 12287, 12286, 3, 3,
2, 2, 1, 0, 2, 12287, 12285, 3, 1, 3,
5, 2, 12287, 12287, 2, 0, 4, 2, 0, 0,
1, 5, 12288, 6, 4, 12287, 1, 0, 12283, 0,
1, 12286, 2, 0, 2, 1, 12284, 12282, 0, 6,
1, 2, 5, 12288, 6, 12288, 12284, 2, 1, 2,
12288, 12283, 12288, 3, 12288, 12288, 2, 12286, 12283, 1,
12285, 0, 0, 12286, 12288, 12286, 12288, 12286, 4, 0,
1, 12285, 3, 1, 2, 12285, 12287, 12284, 12287, 12285,
12286, 1, 12288, 3, 5, 5, 3, 12285, 12286, 12288,
0, 1, 12287, 12284, 2, 4, 12288, 12287, 0, 12288,
12288, 12285, 12288, 12284, 3, 0, 2, 0, 2, 0,
1, 1, 1, 12287, 1, 12284, 12285, 0, 12284, 1,
12284, 2, 12288, 5, 4, 1, 1, 12284, 1, 3,
2, 6, 3, 2, 3, 12284, 0, 0, 4, 2,
6, 2, 2, 2, 6, 12288, 0, 1, 12286, 1,
5, 1, 12283, 2, 0, 12284, 1, 12286, 4, 1,
2, 4, 6, 12288, 12288, 12284, 1, 0, 3, 12286,
1, 0, 3, 12288, 12287, 2, 2, 0, 12285, 12286,
0, 12288, 4, 2, 12282, 12287, 1, 12288, 12287, 12286,
12284, 1, 4, 2, 7, 12288, 12283, 12288, 5, 12288,
12288, 12287, 3, 2, 12287, 5, 12287, 12286, 12288, 12287,
0, 12282, 12288, 12288, 0, 3, 12287, 2, 12287, 12284,
6, 12285, 2, 3, 3, 12284, 2, 4, 12286, 5,
0, 2, 12287, 3, 0, 12284, 12286, 0, 2, 12286,
12287, 3, 1, 4, 1, 12286, 12288, 1, 2, 0,
12285, 12287, 2, 0, 0, 0, 3, 12286, 12287, 2,
0, 0, 0, 12286, 4, 1, 12287, 0, 0, 2,
5, 0, 12284, 1, 1, 12288, 2, 12286, 12288, 2,
2, 12282, 1, 12286, 4, 12286, 3, 12287, 12287, 12286,
5, 5, 0, 12288, 3, 12285, 1, 12287, 7, 12286,
2, 12287, 1, 12285, 2, 12287, 12288, 0, 4, 12281,
0, 12286, 3, 1, 12285, 2, 2, 12285, 5, 0,
12285, 2, 12288, 1, 3, 12287, 1, 12288, 1, 5,
12287, 1, 0, 3, 2, 12286, 12286, 12288, 3, 0,
12287, 12288, 0, 12286, 12285, 0, 12286, 12288, 3, 12287,
12288, 2, 6, 0, 2, 12285, 1, 1, 7, 7,
12284, 12284, 5, 0, 12288, 12288, 4, 3, 1, 2,
12287, 0, 12288, 12284, 2, 5, 1, 2, 0, 12288,
1, 12284, 2, 3, 0, 12287, 12285, 2, 12288, 12288,
7, 1, 12287, 1, 12286, 2, 3, 4, 12288, 12288,
12286, 12286, 3, 12288, 1, 12286, 12286, 0, 12283, 12288,
2, 0, 7, 2, 12287, 0, 0, 12286, 4, 1,
12288, 12288, 1, 2, 12287, 12282, 3, 5, 0, 12288,
12288, 12286, 12286, 12286, 4, 2, 0, 1, 12284, 3,
12283, 5, 12287, 2, 2, 12288, 1, 12284, 1, 0,
1, 3, 12288, 2, 12287, 1, 12286, 12288, 0, 12287,
12288, 2, 2, 12286, 0, 12287, 12288, 12284, 0, 2,
2, 2, 1, 3, 12285, 12285, 1, 12285, 2, 6,
2, 0, 12288, 0, 0, 3, 2, 12287, 1, 12286,
0, 12287, 0, 1, 12285, 12287, 6, 12288, 2, 0,
12286, 2, 4, 12288, 2, 5, 12285, 12286, 0, 12284,
12288, 3, 3, 3, 12287, 4, 2, 0, 12283, 2,
12287, 0, 1, 12287, 2, 12288, 12287, 3, 2, 7,
7, 1, 12287, 12288, 2, 6, 1, 3, 2, 0,
2, 2, 3, 12288, 3, 4, 2, 0, 5, 12285,
3, 12285, 3, 12285, 1, 1, 12287, 12285, 2, 12285,
5, 0, 7, 2, 12284, 0, 12285, 7, 1, 12288,
12288, 0, 12288, 12287, 5, 0, 2, 0, 2, 12286,
1, 12286, 0, 12286, 12285, 4, 12286, 2, 12288, 12287,
12287, 1, 12286, 12287, 12287, 12286, 12287, 12288, 6, 5,
2, 5, 12283, 12286, 12286, 12288, 1, 0, 3, 12286,
5, 0, 12287, 12288, 12288, 12287, 12286, 2, 1, 0,
1, 2, 3, 1, 12286, 2, 1, 6, 12288, 1,
12286, 1, 12288, 0, 1, 0, 12283, 0, 2, 12288,
3, 1, 12287, 12288, 4, 0, 3, 12286, 0, 1,
12283, 4, 1, 4, 12287, 5, 0, 12287, 12288, 3,
3, 12282, 1, 4, 2, 3, 0, 2, 6, 12282,
12285, 12288, 12287, 12288, 2, 12285, 1, 0, 12287, 12288,
12286, 0, 0, 4, 12288, 12287, 1, 0, 2, 5,
2, 12287, 1, 7, 12284, 0, 12287, 12286, 2, 1,
12287, 0, 1, 12284, 12287, 12287, 12285, 12285, 3, 12282,
12286, 1, 1, 12288, 12282, 12287, 1, 1, 2, 2,
3, 1, 12287, 5, 12282, 0, 0, 12287, 1, 3,
12288, 3, 12285, 12286, 2, 0, 12288, 12288, 5, 12285,
4, 12288, 12287, 0, 1, 4, 1, 2, 12288, 0,
2, 1, 12288, 4, 6, 12288, 1, 12287, 4, 1,
12285, 12288, 3, 0, 12288, 12285, 2, 0, 12286, 2,
1, 12288, 1, 12288, 12284, 3, 0, 2, 2, 12288,
12287, 12286, 4, 12288, 2, 0, 0, 3, 4, 0,
12288, 12282, 6, 2, 12283, 12287, 2, 6, 1, 2,
12288, 2, 12283, 3, 12287, 3, 4, 0, 0, 12285,
0, 12288, 12287, 12284, 12286, 3, 1, 12286, 2, 0,
12287, 12286, 12286, 12288, 5, 2, 12288, 12286, 0, 12287,
0, 3, 2, 12287, 12286, 0, 1, 12287, 2, 0,
12286, 5, 12285, 12288, 12288, 12288, 12286, 4, 1, 12285,
12284, 12288, 12286, 1, 1, 12287, 2, 12286, 3, 2,
12283, 12283, 4, 2, 12283, 5, 0, 1, 0, 5,
12287, 1, 1, 0, 3, 10, 12287, 3, 12288, 12288,
12287, 2, 2, 0, 4, 12288, 12283, 12288, 1, 12287,
3, 0, 0, 1, 12288, 12284, 0, 12286, 12287, 0,
12287, 2, 1, 7, 12288, 12287, 0, 4, 12287, 12286,
3, 4, 12287, 12288, 12285, 12287, 12288, 12285, 12286, 7,
1, 1, 12288, 3, 12287, 3, 1, 4, 2, 5,
12282, 3, 0, 12286, 12288, 0, 12285, 0, 2, 3,
0, 12286, 3, 2, 12285, 0, 0, 12287, 1, 0,
0, 6, 2, 12287, 12284, 7, 5, 0, 1, 6,
2, 4, 1, 12286, 12288, 2, 12287, 3, 4, 12283,
0, 12288, 2, 2, 12286, 0, 2, 2, 12288, 12285,
12287, 12285, 12288, 0 }
},
{ 0x01, 0x02, /* polynomial e'' */
{ 0x20, 0x37, 0x77, 0x8a, 0x9c, 0x19, 0xde, 0xf0, 0x65, 0x9e,
0x0f, 0xa5, 0xfc, 0x0e, 0x78, 0xfe, 0x55, 0x89, 0xc9, 0x88,
0x41, 0xa2, 0x5a, 0x1e, 0xa4, 0x66, 0xcd, 0x3a, 0x29, 0x42,
0xd1, 0x25, 0xf2, 0x84, 0xd7, 0xee, 0xd5, 0x53, 0x86, 0x5b,
0xa3, 0x93, 0x4e, 0xee, 0xc7, 0x5b, 0xe5, 0x52, 0x68, 0x19,
0xdf, 0x63, 0xfb, 0x91, 0x3d, 0xe9, 0x5d, 0xd6, 0xeb, 0x81,
0x3d, 0xac, 0xf1, 0xad },
{ 12286, 12286, 1, 12287, 1, 12286, 12287, 12287, 12284, 1,
12287, 2, 12284, 0, 2, 12288, 0, 1, 0, 12285,
12288, 4, 2, 12287, 12282, 12288, 12285, 12288, 2, 12288,
6, 7, 12286, 12286, 1, 4, 12287, 12287, 3, 1,
3, 3, 2, 12285, 0, 1, 12288, 1, 1, 12287,
0, 0, 1, 0, 12287, 12283, 12283, 12288, 12287, 0,
0, 2, 12286, 3, 3, 0, 12286, 12282, 3, 6,
3, 3, 12285, 1, 1, 12288, 1, 0, 12288, 0,
12287, 4, 1, 0, 12285, 12288, 1, 1, 1, 3,
12286, 0, 12288, 0, 12287, 12287, 3, 5, 1, 12287,
12287, 0, 0, 0, 12283, 0, 0, 12288, 0, 12287,
12286, 12284, 12286, 0, 12286, 3, 5, 12287, 0, 12287,
1, 3, 2, 6, 1, 12287, 1, 1, 12285, 4,
12282, 12288, 12288, 3, 2, 12287, 3, 3, 12288, 12286,
2, 5, 12288, 12287, 12288, 3, 0, 12283, 3, 3,
1, 0, 12288, 2, 2, 12287, 12286, 4, 12287, 12288,
0, 0, 12286, 1, 4, 4, 12286, 12287, 4, 12288,
2, 1, 1, 12288, 12287, 3, 12287, 12286, 12285, 12288,
4, 1, 0, 12287, 3, 12286, 12287, 4, 0, 12287,
12286, 12287, 3, 1, 1, 12285, 12287, 0, 12285, 2,
5, 2, 12285, 3, 2, 12285, 12287, 2, 0, 12288,
2, 5, 2, 12283, 1, 1, 0, 12286, 12288, 3,
1, 12286, 12283, 0, 1, 2, 2, 1, 12287, 12287,
4, 4, 1, 0, 0, 12288, 12287, 12284, 12284, 7,
0, 12288, 5, 4, 12288, 12288, 1, 0, 1, 1,
2, 12288, 12288, 5, 1, 0, 12287, 3, 3, 0,
1, 12288, 12288, 3, 12285, 12288, 3, 5, 4, 1,
12285, 12285, 12288, 12285, 12288, 12285, 4, 1, 3, 12285,
4, 0, 12288, 12286, 5, 12287, 12285, 12288, 4, 12288,
0, 12287, 12286, 0, 12286, 12283, 0, 12287, 12284, 1,
12288, 12288, 3, 12286, 1, 2, 12286, 3, 1, 12285,
12286, 12285, 0, 12285, 12288, 0, 2, 12283, 0, 1,
2, 1, 2, 3, 3, 12285, 0, 0, 0, 12288,
12283, 4, 12286, 2, 1, 3, 3, 12284, 2, 4,
3, 12286, 12282, 12286, 0, 12286, 12287, 3, 12288, 12288,
2, 12287, 12286, 3, 0, 12286, 1, 1, 0, 12287,
2, 0, 0, 1, 12286, 1, 0, 12283, 0, 12288,
2, 5, 12288, 12287, 2, 1, 12288, 2, 2, 5,
2, 12286, 12286, 2, 12284, 12287, 0, 12284, 0, 12284,
12286, 12286, 12288, 12287, 12287, 2, 1, 12287, 12287, 1,
5, 0, 0, 12288, 2, 12285, 6, 2, 12288, 12288,
12286, 2, 12285, 0, 0, 0, 12288, 3, 12286, 1,
1, 0, 3, 0, 12286, 12288, 12287, 3, 2, 12287,
12288, 1, 12288, 12282, 2, 0, 12288, 12286, 12285, 12281,
4, 1, 7, 12283, 12287, 12288, 1, 6, 0, 12288,
5, 1, 1, 12286, 12286, 0, 12287, 12285, 12287, 1,
12288, 12286, 12286, 12288, 2, 12287, 12287, 12288, 12286, 12288,
12282, 12284, 12286, 0, 12285, 12285, 3, 12288, 12287, 12288,
2, 0, 2, 0, 12288, 12286, 3, 12288, 12286, 12287,
1, 1, 1, 0, 5, 5, 12285, 12288, 3, 12286,
1, 2, 12285, 1, 4, 12288, 1, 4, 1, 3,
4, 12286, 0, 7, 2, 12288, 2, 12287, 0, 2,
12283, 12286, 0, 12288, 12286, 4, 1, 12284, 7, 12285,
0, 12284, 12287, 0, 0, 3, 4, 12284, 0, 1,
0, 1, 12285, 1, 12286, 12284, 12287, 0, 7, 1,
4, 12282, 12288, 0, 2, 12285, 12288, 12287, 12287, 12283,
0, 1, 3, 12285, 12286, 3, 12288, 12288, 12284, 12286,
12288, 1, 0, 2, 12287, 0, 12286, 4, 12288, 0,
12284, 0, 0, 2, 12286, 0, 0, 12286, 12287, 1,
12288, 0, 12284, 1, 12288, 12288, 1, 1, 12282, 12284,
12288, 12285, 12285, 12288, 1, 12286, 2, 0, 0, 12284,
2, 12288, 0, 0, 12285, 0, 3, 0, 0, 12285,
12286, 5, 3, 12287, 5, 2, 12287, 0, 1, 12286,
12287, 1, 12286, 1, 12288, 0, 0, 12282, 5, 12282,
12287, 12288, 12287, 1, 0, 3, 4, 6, 1, 1,
12287, 12284, 12286, 12287, 12286, 2, 1, 12288, 3, 0,
3, 0, 12286, 1, 0, 12288, 1, 12284, 4, 0,
4, 12288, 1, 4, 1, 12286, 4, 0, 2, 1,
1, 4, 12287, 2, 1, 12288, 4, 3, 2, 12287,
0, 1, 12287, 1, 12285, 12286, 2, 2, 0, 12286,
12287, 0, 12288, 12285, 5, 12288, 0, 0, 12288, 3,
12288, 0, 4, 0, 12288, 12286, 12287, 0, 0, 2,
12283, 0, 12281, 1, 1, 3, 4, 2, 12284, 5,
12288, 2, 3, 4, 12287, 3, 12288, 12287, 12288, 2,
12286, 2, 0, 12286, 12286, 5, 12288, 2, 12288, 7,
12286, 12286, 4, 12288, 12288, 12288, 5, 12287, 7, 12286,
12282, 2, 12284, 0, 12288, 0, 2, 12283, 2, 5,
4, 1, 12288, 12283, 5, 12288, 12288, 0, 0, 0,
6, 1, 12286, 6, 4, 12287, 2, 12288, 12287, 12286,
4, 5, 0, 1, 2, 1, 4, 12286, 1, 2,
1, 1, 0, 12288, 12282, 1, 1, 3, 12284, 12288,
0, 12287, 1, 12286, 12288, 6, 1, 5, 12287, 12285,
2, 12288, 12288, 12284, 0, 12287, 2, 3, 5, 1,
12286, 1, 12287, 0, 12284, 1, 5, 12283, 1, 1,
12287, 12283, 12288, 0, 12287, 3, 0, 12288, 12286, 12287,
8, 0, 0, 12288, 1, 3, 2, 3, 12287, 9,
2, 3, 4, 12288, 3, 0, 12288, 12283, 0, 0,
2, 4, 12287, 2, 12287, 12286, 12287, 2, 12287, 2,
3, 1, 3, 1, 0, 1, 1, 5, 3, 12285,
1, 12281, 12287, 12286, 1, 4, 12287, 12286, 12285, 4,
2, 0, 12288, 12288, 12286, 12287, 12288, 1, 3, 4,
0, 1, 12285, 4, 3, 12284, 1, 12288, 12285, 12288,
0, 12281, 12288, 12285, 12285, 1, 12284, 12286, 12287, 0,
0, 12287, 1, 12282, 4, 4, 12288, 1, 4, 12286,
5, 4, 1, 5, 3, 1, 0, 6, 12288, 0,
12288, 2, 12286, 12287, 6, 0, 12288, 0, 12287, 1,
4, 0, 12282, 4, 1, 12286, 1, 12282, 3, 12285,
12283, 12286, 12288, 4, 12284, 12286, 12286, 0, 12286, 0,
0, 1, 12286, 1, 1, 4, 12284, 0, 3, 2,
12288, 1, 2, 12287, 2, 1, 12288, 0, 1, 2,
12286, 0, 6, 12285, 0, 1, 4, 0, 0, 3,
2, 12287, 12285, 7, 1, 3, 1, 0, 12286, 12288,
0, 12287, 1, 12286 }
}
};
START_TEST(test_newhope_noise_uniform)
{
newhope_noise_t *noise;
uint8_t seed_buf[seed_len], *uniform;
chunk_t seed = { seed_buf, seed_len };
memset(seed_buf, 0x00, seed_len - 1);
seed_buf[seed_len - 1] = noises[_i].key;
noise = newhope_noise_create(seed);
ck_assert(noise != NULL);
uniform = noise->get_uniform_bytes(noise, noises[_i].nonce, 64);
ck_assert(uniform != NULL);
ck_assert(memeq(uniform, noises[_i].uniform, 64));
free(uniform);
noise->destroy(noise);
}
END_TEST
START_TEST(test_newhope_noise_poly)
{
newhope_noise_t *noise;
uint8_t seed_buf[seed_len];
uint32_t *poly;
int i;
chunk_t seed = { seed_buf, seed_len };
memset(seed_buf, 0x00, seed_len - 1);
seed_buf[seed_len - 1] = noises[_i].key;
noise = newhope_noise_create(seed);
ck_assert(noise != NULL);
poly = noise->get_binomial_words(noise, noises[_i].nonce, n, q);
ck_assert(poly != NULL);
for (i = 0; i < n; i++)
{
ck_assert(poly[i] == noises[_i].poly[i]);
}
free(poly);
noise->destroy(noise);
}
END_TEST
static size_t seed_lengths[] = { 0, 1, 31, 33 };
START_TEST(test_newhope_noise_fail)
{
newhope_noise_t *noise;
chunk_t seed;
seed = chunk_alloc(seed_lengths[_i]);
memset(seed.ptr, 0x00, seed.len);
noise = newhope_noise_create(seed);
ck_assert(noise == NULL);
chunk_free(&seed);
}
END_TEST
Suite *newhope_noise_suite_create()
{
Suite *s;
TCase *tc;
s = suite_create("newhope_noise");
tc = tcase_create("noise_uniform");
tcase_add_loop_test(tc, test_newhope_noise_uniform, 0, countof(noises));
suite_add_tcase(s, tc);
tc = tcase_create("noise_poly");
tcase_add_loop_test(tc, test_newhope_noise_poly, 0, countof(noises));
suite_add_tcase(s, tc);
tc = tcase_create("noise_fail");
tcase_add_loop_test(tc, test_newhope_noise_fail, 0, countof(seed_lengths));
suite_add_tcase(s, tc);
return s;
}
@@ -0,0 +1,346 @@
/*
* Copyright (C) 2016 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 <newhope_reconciliation.h>
#include <library.h>
static const uint16_t n = 1024;
static const uint16_t q = 12289;
static const size_t seed_len = 32;
static uint32_t r_v[] = {
7832, 2714, 1942, 12135, 6869, 11272, 11601, 1783, 9639, 1465,
4603, 8158, 1418, 6162, 3907, 6653, 1091, 3026, 4540, 4797,
2751, 29, 768, 5580, 1304, 5262, 1644, 11294, 12257, 10466,
170, 8458, 7185, 6850, 8790, 11277, 10980, 5507, 10693, 9766,
7230, 3980, 796, 11125, 8042, 9022, 10207, 7577, 5041, 192,
10308, 7905, 8520, 3814, 3372, 11772, 11290, 418, 2744, 4782,
3072, 10921, 10721, 6100, 1021, 7943, 7426, 2142, 6618, 757,
5033, 9336, 9332, 3410, 6613, 11776, 1525, 9567, 5371, 1290,
3685, 11054, 11228, 10703, 70, 11215, 8992, 2855, 2962, 10104,
10083, 8146, 7599, 3428, 4316, 10056, 1245, 9776, 7867, 1381,
6540, 11273, 6626, 3708, 5348, 4521, 3760, 1771, 12037, 2681,
3044, 10226, 5133, 5013, 7851, 7187, 1965, 6776, 223, 3003,
4800, 10128, 9592, 8917, 10664, 7076, 2081, 5621, 2694, 8245,
10979, 929, 10593, 10429, 6890, 6222, 5891, 6633, 12124, 1508,
508, 9650, 2480, 10302, 3958, 4519, 5309, 8675, 6963, 5281,
8265, 4851, 7173, 2537, 1176, 259, 6422, 6782, 1429, 7231,
4948, 8137, 11341, 12090, 5395, 8087, 3098, 6724, 7462, 9973,
149, 7331, 562, 9753, 1227, 768, 7520, 12107, 6199, 6503,
9876, 306, 3876, 1903, 6306, 10288, 10184, 9401, 68, 5246,
630, 10136, 133, 12082, 648, 8537, 3896, 4482, 12011, 5407,
5305, 4301, 6551, 714, 5902, 11915, 3121, 5428, 5441, 5140,
10139, 2091, 875, 9478, 11576, 8663, 10514, 1018, 8780, 6445,
2501, 4204, 1276, 7474, 10594, 3808, 4367, 11469, 4875, 1899,
9136, 1507, 6235, 6367, 3851, 7341, 9925, 4629, 9588, 3150,
4739, 6109, 4850, 9944, 11565, 4995, 8383, 9623, 6248, 3020,
1730, 3368, 3431, 8617, 6478, 7182, 8720, 1927, 6493, 9285,
9779, 2800, 3730, 1754, 3772, 3124, 7569, 10008, 9240, 2493,
4402, 5851, 2050, 8630, 5054, 8421, 1536, 7671, 5467, 9075,
5881, 4355, 4554, 11354, 4048, 10335, 11033, 4252, 2558, 4363,
10448, 327, 1675, 4755, 8227, 7705, 398, 10398, 9913, 4129,
6571, 10743, 280, 6634, 796, 7264, 3916, 11349, 1415, 1187,
692, 9980, 1647, 4267, 1001, 12229, 6040, 268, 1308, 531,
3141, 7209, 1941, 4684, 10261, 1415, 8381, 4919, 11450, 1494,
8237, 11023, 3380, 4448, 10101, 9232, 11040, 7799, 4958, 741,
2234, 10436, 11442, 5073, 2908, 2355, 31, 7222, 5457, 3746,
8920, 122, 8960, 5708, 1750, 11161, 4847, 3199, 7954, 2151,
9419, 11678, 8997, 12016, 9690, 9605, 10718, 3735, 1617, 9574,
10384, 11604, 9311, 687, 7145, 11891, 6529, 5052, 1342, 8735,
7644, 6062, 6338, 8563, 2502, 5284, 220, 5224, 3771, 11067,
11609, 2972, 3799, 2566, 7488, 6369, 7704, 6095, 3598, 12112,
8545, 2026, 746, 3206, 2814, 8740, 1491, 5950, 8413, 4043,
12036, 6082, 4131, 1941, 6942, 9396, 11267, 8912, 7344, 10371,
9205, 9520, 12038, 4345, 8024, 10999, 8408, 4673, 6682, 8893,
8668, 10099, 7658, 11896, 4276, 2042, 10707, 9793, 3152, 11961,
3269, 5512, 5736, 5938, 9457, 10439, 10777, 6656, 3174, 9043,
6046, 2519, 11912, 5244, 6214, 2071, 11317, 5285, 891, 6184,
3819, 1563, 1474, 654, 5147, 2380, 10760, 4816, 3378, 1414,
7784, 10067, 1809, 6320, 4789, 9359, 2747, 9424, 9074, 9473,
3300, 6244, 104, 7612, 1105, 4276, 573, 1988, 923, 12047,
7948, 4860, 3949, 4971, 6956, 2831, 2034, 289, 10946, 6970,
3191, 5122, 2175, 1300, 6198, 256, 6433, 11646, 9119, 9723,
1046, 5967, 1124, 6449, 2817, 692, 4649, 3089, 5050, 11261,
2220, 3052, 12012, 10110, 1394, 2877, 10089, 11696, 4462, 5504,
66, 2500, 5384, 7461, 5712, 8649, 9536, 7670, 2385, 3469,
782, 2876, 7772, 6118, 142, 5396, 10951, 10556, 3450, 10602,
1604, 7909, 3323, 39, 10258, 2262, 7113, 11313, 10203, 10846,
9275, 4316, 965, 6006, 4458, 7926, 3171, 1797, 4659, 5336,
5543, 250, 9230, 10720, 11970, 4511, 4311, 11763, 1283, 4044,
2643, 3744, 4490, 5984, 8868, 8760, 11738, 6037, 9164, 7601,
7544, 11117, 7322, 2081, 4034, 10791, 11491, 7027, 1615, 5338,
8528, 3424, 2126, 927, 1650, 6068, 3812, 10958, 7574, 11032,
6954, 6132, 2598, 9458, 11346, 1974, 3273, 1040, 10331, 8587,
11017, 6864, 8246, 5328, 11330, 6779, 8761, 4342, 4595, 8610,
161, 4622, 6411, 10708, 7896, 11431, 12097, 9500, 3376, 9561,
10730, 2248, 3069, 1434, 8838, 566, 6397, 5881, 4956, 4203,
8362, 6047, 3484, 4784, 9901, 8989, 862, 8817, 12186, 9876,
9748, 1905, 5696, 9028, 5721, 2940, 10235, 2326, 2134, 6167,
1019, 10851, 1253, 5588, 9149, 6532, 3959, 11598, 4068, 3299,
8264, 9787, 7089, 2829, 6755, 6156, 455, 5900, 2839, 5921,
2140, 7428, 2688, 11175, 9247, 6727, 11711, 1762, 6244, 3336,
2308, 9922, 7883, 7007, 10890, 7013, 8452, 2743, 1482, 6927,
7846, 6128, 5114, 4868, 7487, 4584, 6785, 460, 6747, 8894,
9855, 12242, 3365, 1450, 6614, 3974, 5200, 3247, 2779, 8695,
828, 10940, 2304, 376, 3027, 3898, 10351, 1879, 10262, 2512,
5487, 4280, 10297, 8480, 9481, 7905, 197, 8361, 4927, 705,
9671, 6722, 2589, 8772, 1078, 333, 8696, 6267, 7420, 4471,
8994, 5038, 5318, 1846, 2574, 8779, 10724, 825, 7399, 7073,
4422, 8385, 5171, 8849, 11344, 10735, 8483, 2241, 11738, 6581,
10699, 2777, 6531, 4678, 7608, 10871, 3501, 9239, 7252, 11828,
7873, 9606, 4526, 5958, 8505, 11233, 9638, 2421, 5652, 3095,
9049, 11347, 6274, 1405, 11114, 11208, 5703, 10774, 3011, 11633,
5741, 9601, 5507, 4527, 3501, 5707, 8698, 178, 12091, 325,
6056, 635, 3772, 12169, 10509, 6528, 3573, 3675, 3389, 3161,
1148, 2687, 3509, 6639, 10452, 11804, 5355, 1085, 9580, 7106,
1396, 8279, 4881, 3402, 7803, 8801, 6142, 7623, 4386, 9291,
1502, 500, 11809, 6655, 2674, 10061, 1650, 5422, 8936, 10011,
1193, 9619, 1435, 8285, 4038, 9984, 9732, 4477, 1251, 7106,
7817, 10062, 3378, 5608, 2395, 2563, 1957, 3768, 4160, 7267,
11631, 2171, 4771, 6927, 4330, 10482, 6204, 11022, 7895, 1924,
3648, 1991, 6628, 10136, 2916, 5416, 7827, 1479, 2312, 9991,
7915, 5431, 10911, 10979, 4527, 436, 10521, 5725, 2201, 10198,
662, 1691, 8867, 10008, 9359, 5291, 567, 5725, 10329, 4772,
2813, 7323, 5646, 1861, 9922, 1831, 9356, 1219, 4107, 9999,
4569, 9092, 833, 1602, 4258, 1443, 1484, 4036, 5415, 3767,
9992, 412, 9343, 2251, 10513, 9067, 1494, 11893, 744, 1978,
11259, 3614, 7459, 5254, 4232, 5148, 4119, 11550, 6425, 4933,
4292, 10521, 9657, 9632, 4613, 7738, 5561, 8806, 3501, 3731,
11329, 2693, 11581, 6393, 10176, 10773, 1790, 1809, 9186, 12085,
5418, 7223, 1077, 1527, 10917, 4236, 7668, 11754, 6655, 7696,
1809, 11512, 3618, 5857, 7512, 1044, 7970, 6825, 4897, 2870,
126, 8619, 10445, 3883, 4238, 4051, 399, 1580, 9893, 11046,
2955, 6520, 5435, 1891, 1254, 12135, 4122, 10512, 11960, 6196,
3443, 10118, 1689, 10877
};
static uint32_t i_v[] = {
8355, 2010, 1416, 12110, 6361, 11296, 11668, 1446, 9822, 947,
5422, 8211, 1824, 6158, 3458, 6435, 685, 2707, 4804, 4929,
3204, 12158, 674, 5703, 1125, 5085, 1358, 10956, 12216, 11164,
12112, 8359, 7018, 7038, 9099, 11789, 10574, 5991, 10736, 9335,
7898, 4429, 587, 11156, 7912, 9063, 9673, 6792, 5530, 648,
10203, 7284, 7935, 4177, 3514, 11488, 10998, 12254, 2913, 4827,
2446, 10965, 10718, 5569, 1023, 8150, 7440, 1928, 6384, 802,
4726, 9738, 10374, 3842, 6761, 11788, 1133, 9413, 5818, 1099,
3710, 11315, 11667, 10285, 12431, 11195, 9193, 2842, 2267, 9902,
10076, 7409, 6751, 3748, 4487, 9961, 1547, 10060, 7443, 1276,
6827, 10798, 6323, 4038, 5508, 4006, 3300, 1774, 255, 2688,
3238, 10275, 4911, 5648, 7842, 7506, 1769, 6425, 195, 3176,
4455, 10337, 9451, 8912, 10445, 7646, 2837, 5109, 3033, 8668,
10295, 744, 10869, 10204, 6825, 6326, 6299, 7208, 11886, 1246,
704, 9626, 2538, 10932, 3903, 4545, 5111, 9006, 6698, 5008,
8464, 4679, 7230, 2223, 707, 705, 6592, 6207, 1114, 7645,
5374, 7595, 11064, 746, 5585, 8248, 2921, 7004, 6595, 9985,
506, 7147, 793, 9605, 596, 962, 8223, 11771, 6438, 6663,
9519, 12013, 4302, 2216, 6633, 10351, 10096, 9645, 347, 4601,
596, 10448, 12051, 12376, 1544, 8939, 5114, 4052, 11408, 5947,
5368, 4270, 6747, 423, 6283, 11211, 2574, 5974, 5533, 5143,
9757, 2155, 729, 9776, 11989, 8808, 11057, 1519, 9187, 5996,
2966, 3865, 1409, 8023, 10648, 4397, 5082, 10832, 4769, 2068,
9226, 1790, 5911, 6534, 3780, 7312, 9388, 5014, 9054, 3445,
4659, 6203, 5234, 9490, 11060, 4214, 8978, 9789, 6201, 3088,
1988, 3057, 3762, 8725, 7322, 7583, 8233, 1394, 6534, 9221,
9736, 2738, 3837, 2595, 4012, 3674, 7505, 10231, 8080, 2402,
3977, 5928, 1942, 8421, 5507, 8422, 1238, 6909, 5800, 9613,
6083, 4382, 4669, 11670, 4032, 10762, 11623, 4387, 3728, 4656,
9701, 722, 1255, 4495, 8158, 7762, 792, 10307, 9813, 3904,
6081, 11003, 12045, 6718, 1089, 7327, 4381, 11188, 943, 1740,
563, 10251, 756, 5027, 848, 325, 6547, 12288, 1222, 12189,
3641, 7314, 2049, 5254, 10043, 1068, 7906, 4741, 11639, 1981,
7660, 10911, 2746, 4536, 10068, 9700, 11057, 8114, 5556, 253,
2292, 10686, 11848, 5306, 3092, 2570, 12167, 7101, 5245, 3463,
8627, 12513, 9010, 5356, 1633, 10462, 4545, 3614, 7245, 1887,
9738, 11902, 8716, 12035, 9958, 9421, 11063, 3759, 883, 9754,
10730, 11706, 9132, 540, 6726, 11382, 7038, 4407, 1225, 8606,
7689, 5894, 6553, 7908, 2454, 4939, 613, 5811, 3580, 11792,
11364, 3153, 3698, 2604, 7470, 6053, 7699, 6018, 4289, 11497,
8580, 2249, 718, 2444, 2972, 8812, 1710, 6317, 8718, 4194,
12288, 5837, 3698, 2216, 7402, 9045, 11194, 8500, 7238, 10686,
9409, 9867, 12264, 3859, 7673, 11659, 8496, 4618, 6465, 8811,
9114, 10740, 7738, 11850, 4142, 2493, 11136, 9623, 3071, 11701,
2925, 5043, 6151, 6221, 9642, 10846, 11145, 6315, 3741, 9123,
5131, 2585, 11337, 4786, 5844, 1485, 11505, 5205, 797, 5955,
3717, 1756, 1551, 1122, 5057, 2585, 10857, 5129, 3557, 1254,
7750, 9688, 2462, 6415, 4345, 9460, 2957, 8793, 9210, 9242,
3487, 6506, 11888, 7563, 1078, 4486, 406, 2261, 867, 11965,
7979, 4533, 3654, 4747, 6636, 3166, 2114, 380, 9715, 7132,
2982, 5024, 1817, 1231, 6210, 12377, 6280, 10882, 9937, 9587,
633, 5668, 899, 6176, 2431, 956, 5022, 3094, 4658, 11168,
2989, 2654, 11990, 10494, 1691, 3017, 10044, 11882, 4020, 5342,
11911, 2426, 5748, 7592, 6340, 9214, 9357, 7169, 2109, 3210,
415, 3024, 7791, 5684, 246, 5134, 11335, 10092, 3133, 10427,
1502, 7739, 3272, 169, 9521, 2550, 7327, 11309, 10815, 10146,
9157, 4579, 1022, 6447, 4233, 8488, 2958, 1715, 4215, 4965,
5728, 551, 8942, 10845, 11881, 4472, 4331, 304, 1183, 3798,
1968, 3993, 4889, 6145, 8841, 8816, 11283, 6578, 9212, 8161,
7003, 11574, 7764, 1678, 4138, 10444, 11880, 7101, 1390, 4743,
8320, 3026, 2338, 1203, 1562, 6502, 3103, 10770, 7608, 11097,
6745, 6037, 2926, 9489, 10782, 1853, 3482, 524, 11063, 8299,
11092, 6838, 7779, 4598, 11245, 7274, 8908, 3886, 4440, 8651,
11949, 5344, 6954, 11015, 8333, 11347, 12677, 8716, 3514, 9892,
10366, 2029, 2875, 1540, 9013, 250, 6393, 5618, 4565, 3687,
8340, 6420, 3632, 5032, 9408, 9738, 961, 8653, 12315, 10459,
9883, 2074, 5357, 9341, 4850, 2514, 9746, 2605, 2394, 5928,
808, 10443, 1589, 5673, 9176, 6593, 3404, 12254, 4230, 3630,
7958, 10065, 7471, 2432, 6626, 6517, 382, 6131, 2888, 5440,
1571, 7341, 2841, 11202, 9462, 7180, 11206, 1433, 6183, 3882,
2105, 9906, 8076, 7074, 10572, 7262, 8456, 2979, 1095, 6891,
8025, 5914, 5380, 4300, 7363, 4989, 6788, 1043, 6836, 8710,
10099, 12310, 3997, 2102, 7002, 4041, 4948, 2601, 2958, 8665,
984, 10820, 1940, 541, 3377, 3533, 9357, 2049, 10721, 2732,
5355, 4280, 10281, 8056, 9557, 7749, 611, 8255, 4854, 708,
9199, 7033, 2582, 8343, 820, 944, 8651, 5547, 7052, 4723,
8972, 5594, 5314, 1938, 2539, 8789, 10341, 12368, 7475, 6903,
4436, 8346, 5391, 8336, 10864, 10397, 8517, 2078, 12127, 6612,
10511, 2970, 6576, 5166, 7744, 10934, 3186, 9515, 6831, 12085,
7284, 9791, 4755, 6341, 8713, 11526, 9392, 2122, 5743, 2776,
9581, 11396, 7006, 1465, 11235, 10997, 5776, 10401, 2929, 11732,
5847, 9512, 6068, 3934, 3730, 5813, 9195, 410, 11698, 896,
6321, 1310, 3478, 11649, 10201, 6850, 3612, 3451, 3569, 3266,
747, 3151, 3352, 6497, 10445, 11501, 5306, 1026, 9712, 7294,
813, 8005, 5090, 2905, 7903, 8358, 6290, 7756, 3955, 9471,
1858, 699, 11847, 7292, 2165, 10556, 1038, 5289, 8693, 9698,
1702, 10228, 1412, 8681, 3330, 10042, 8888, 4257, 1201, 7422,
7956, 10019, 3011, 5956, 2188, 2407, 1986, 3847, 4345, 7427,
12091, 1763, 3885, 6731, 4172, 10828, 6129, 10972, 7878, 2189,
3988, 2125, 6536, 10663, 3100, 5129, 7656, 1053, 2303, 10149,
8087, 5666, 11151, 10962, 4905, 779, 10113, 5451, 1509, 9590,
735, 1626, 8419, 10607, 9293, 5778, 907, 5527, 10408, 5454,
2266, 7131, 6332, 2055, 10105, 1188, 9842, 2059, 4417, 10026,
4339, 9779, 680, 1731, 4958, 1589, 1866, 3797, 5058, 3735,
9899, 543, 9330, 2436, 10757, 9010, 1270, 12232, 1122, 2222,
10945, 3733, 7454, 5251, 4185, 5118, 4331, 12022, 5900, 4767,
4393, 10252, 9957, 9653, 4674, 7705, 5694, 9123, 3882, 3137,
11627, 2712, 11985, 6346, 9990, 10760, 1869, 1778, 8899, 12168,
5207, 7250, 1088, 1131, 11567, 4337, 8286, 11660, 7152, 8010,
2286, 11335, 2984, 5740, 7114, 806, 7579, 7119, 5122, 2917,
541, 7913, 10555, 3684, 4720, 3954, 517, 1526, 9712, 10854,
1921, 6897, 4704, 2141, 1602, 11880, 4548, 10569, 11521, 6408,
3609, 9752, 1960, 10934
};
static uint8_t rbits[] = {
0x3f, 0xff, 0xaf, 0x0f, 0x6b, 0xb2, 0xb8, 0x46, 0x53, 0x44,
0x95, 0x98, 0x0a, 0x85, 0x0c, 0xfc, 0xc4, 0x86, 0xcc, 0x69,
0xc6, 0xd9, 0xfa, 0xee, 0x19, 0xa6, 0x34, 0x0f, 0x35, 0xc4,
0xdc, 0x08
};
static uint8_t r_ref[] = {
0, 3, 3, 1, 1, 1, 0, 1, 0, 3, 2, 0, 1, 1, 3, 0, 2, 1, 0, 3,
2, 1, 2, 3, 3, 0, 2, 0, 1, 3, 3, 2, 3, 3, 0, 3, 0, 2, 2, 0,
1, 1, 2, 0, 1, 1, 2, 1, 3, 0, 0, 3, 1, 1, 0, 0, 0, 2, 0, 1,
0, 2, 3, 1, 3, 0, 3, 1, 0, 0, 2, 1, 3, 3, 1, 3, 2, 1, 0, 2,
0, 0, 3, 3, 0, 1, 2, 2, 0, 1, 0, 3, 2, 2, 1, 1, 3, 0, 3, 3,
2, 2, 0, 2, 1, 0, 0, 0, 3, 0, 3, 1, 2, 1, 1, 0, 3, 3, 2, 1,
3, 3, 2, 2, 1, 3, 0, 0, 2, 2, 3, 1, 1, 2, 2, 2, 0, 2, 0, 2,
0, 0, 1, 2, 2, 2, 3, 1, 2, 0, 3, 0, 1, 3, 2, 3, 3, 1, 1, 2,
0, 0, 2, 1, 2, 2, 0, 2, 2, 2, 2, 1, 1, 3, 1, 3, 3, 1, 2, 2,
3, 0, 1, 0, 0, 2, 2, 1, 3, 2, 2, 2, 3, 1, 1, 0, 0, 3, 2, 3,
0, 0, 3, 3, 2, 2, 2, 2, 1, 1, 0, 1, 2, 1, 3, 2, 0, 3, 0, 2,
3, 3, 3, 3, 2, 3, 3, 3, 3, 2, 1, 0, 2, 3, 2, 1, 2, 0, 3, 0,
2, 2, 1, 1, 2, 1, 2, 0, 1, 2, 1, 3, 0, 0, 2, 3, 0, 3, 1, 0,
2, 2, 2, 1, 2, 0, 3, 1, 0, 0, 3, 0, 2, 3, 1, 0, 2, 3, 3, 0,
0, 0, 3, 0, 2, 3, 2, 0, 2, 2, 1, 0, 1, 2, 1, 3, 3, 3, 1, 2,
1, 2, 3, 1, 1, 2, 2, 0, 3, 0, 3, 3, 1, 3, 3, 3, 1, 3, 0, 3,
0, 0, 1, 2, 1, 0, 3, 0, 0, 2, 1, 3, 3, 3, 1, 1, 2, 3, 1, 0,
1, 1, 3, 3, 0, 3, 1, 3, 1, 2, 2, 2, 1, 3, 1, 2, 1, 3, 0, 1,
2, 2, 2, 3, 3, 2, 2, 3, 1, 2, 2, 1, 2, 1, 0, 0, 0, 1, 3, 2,
0, 3, 1, 1, 2, 1, 3, 2, 3, 2, 0, 1, 0, 1, 3, 0, 2, 3, 1, 3,
0, 1, 1, 3, 1, 1, 1, 0, 2, 3, 2, 1, 2, 0, 3, 3, 2, 0, 1, 0,
3, 3, 3, 1, 2, 2, 1, 0, 3, 3, 0, 2, 3, 1, 1, 1, 3, 3, 1, 3,
3, 0, 1, 0, 2, 0, 1, 1, 0, 0, 3, 2, 2, 3, 0, 2, 2, 0, 1, 1,
1, 3, 1, 1, 1, 0, 1, 2, 3, 2, 2, 3, 1, 1, 3, 3, 3, 1, 2, 0,
0, 0, 2, 2, 2, 3, 2, 0, 0, 1, 3, 0, 0, 0, 2, 0, 1, 0, 3, 0,
3, 1, 0, 1, 1, 1, 2, 2, 2, 0, 0, 2, 2, 0, 3, 1, 0, 2, 2, 0,
2, 0, 0, 1, 1, 0, 1, 2, 3, 2, 3, 2, 3, 3, 3, 0, 2, 1, 2, 2,
1, 0, 1, 1, 1, 2, 1, 3, 2, 0, 3, 3, 0, 0, 1, 1, 1, 2, 2, 2,
0, 1, 1, 2, 0, 2, 0, 1, 2, 0, 1, 3, 2, 2, 3, 0, 0, 1, 1, 2,
3, 1, 2, 0, 3, 0, 2, 1, 0, 0, 0, 1, 1, 1, 1, 3, 0, 0, 0, 3,
2, 3, 2, 1, 0, 3, 1, 1, 1, 1, 3, 0, 0, 1, 1, 1, 0, 3, 2, 2,
3, 1, 1, 3, 0, 1, 1, 3, 0, 3, 2, 2, 0, 3, 1, 3, 1, 0, 0, 1,
1, 0, 0, 1, 0, 3, 2, 2, 0, 1, 3, 0, 1, 3, 3, 2, 1, 3, 1, 1,
3, 3, 2, 1, 1, 3, 1, 0, 2, 1, 1, 3, 3, 3, 1, 3, 1, 3, 0, 1,
2, 2, 0, 3, 3, 2, 1, 1, 1, 3, 0, 2, 0, 3, 3, 1, 2, 3, 1, 3,
0, 0, 0, 1, 3, 3, 0, 2, 3, 0, 1, 3, 0, 0, 3, 0, 2, 2, 3, 3,
3, 3, 2, 1, 0, 3, 1, 1, 1, 2, 2, 0, 3, 2, 0, 2, 2, 3, 1, 0,
3, 3, 1, 2, 3, 0, 1, 1, 0, 3, 3, 1, 1, 3, 0, 2, 1, 2, 2, 2,
2, 3, 2, 3, 0, 0, 3, 1, 1, 0, 3, 2, 3, 2, 3, 3, 2, 2, 3, 1,
3, 2, 1, 0, 1, 0, 2, 2, 1, 3, 1, 2, 3, 3, 1, 3, 2, 1, 3, 2,
2, 3, 1, 1, 3, 3, 3, 3, 2, 0, 0, 3, 3, 3, 2, 3, 2, 0, 3, 0,
3, 1, 2, 0, 3, 0, 2, 2, 2, 3, 1, 2, 2, 1, 3, 3, 0, 1, 3, 0,
0, 1, 3, 2, 1, 1, 0, 1, 3, 3, 1, 1, 0, 1, 2, 2, 2, 0, 2, 3,
1, 2, 1, 1, 3, 2, 3, 3, 1, 0, 1, 3, 2, 3, 2, 2, 1, 2, 3, 1,
3, 2, 3, 1, 3, 3, 0, 3, 1, 1, 3, 2, 1, 2, 2, 0, 1, 1, 2, 3,
1, 3, 0, 0, 3, 0, 3, 0, 1, 2, 0, 2, 2, 3, 2, 0, 0, 0, 3, 0,
2, 0, 0, 2, 2, 2, 3, 1, 3, 2, 3, 2, 0, 1, 2, 1, 1, 3, 0, 3,
2, 0, 2, 2, 3, 2, 1, 0, 1, 1, 0, 2, 0, 3, 2, 0, 2, 3, 1, 3,
2, 2, 2, 2, 3, 1, 0, 2, 3, 3, 3, 2, 0, 0, 3, 3, 1, 2, 2, 3,
0, 1, 1, 1, 3, 2, 1, 0, 0, 1, 2, 3, 3, 0, 1, 1, 1, 1, 0, 1,
0, 2, 3, 3, 3, 3, 0, 2, 3, 0, 1, 0, 0, 1, 1, 3, 2, 2, 0, 0,
2, 2, 1, 3
};
static chunk_t shared_secret = chunk_from_chars(
0x14, 0x22, 0x06, 0xe3, 0x48, 0xf3, 0xfa, 0xfc, 0x21, 0x0d,
0x5d, 0x51, 0x19, 0x7f, 0x16, 0x4e, 0xe6, 0xd3, 0x10, 0xa9,
0xf5, 0xab, 0xfc, 0x96, 0x11, 0x1b, 0xc3, 0x4a, 0x89, 0xf9,
0x66, 0x55
);
START_TEST(test_newhope_rec_good)
{
newhope_reconciliation_t *rec;
chunk_t i_shared_secret, r_shared_secret;
uint8_t *r;
rec = newhope_reconciliation_create(n, q);
ck_assert(rec != NULL);
r = rec->help_reconcile(rec, r_v, rbits);
ck_assert(memeq(r, r_ref, n));
r_shared_secret = rec->reconcile(rec, r_v, r);
ck_assert(chunk_equals(r_shared_secret, shared_secret));
i_shared_secret = rec->reconcile(rec, i_v, r);
ck_assert(chunk_equals(i_shared_secret, shared_secret));
/* cleanup */
rec->destroy(rec);
chunk_free(&i_shared_secret);
chunk_free(&r_shared_secret);
free(r);
}
END_TEST
Suite *newhope_reconciliation_suite_create()
{
Suite *s;
TCase *tc;
s = suite_create("newhope_reconciliation");
tc = tcase_create("rec_good");
tcase_add_test(tc, test_newhope_rec_good);
suite_add_tcase(s, tc);
return s;
}
+7 -6
View File
@@ -25,22 +25,22 @@
typedef struct private_ntru_ke_t private_ntru_ke_t;
/* Best bandwidth and speed, no X9.98 compatibility */
static ntru_param_set_id_t param_sets_optimum[] = {
static const ntru_param_set_id_t param_sets_optimum[] = {
NTRU_EES401EP2, NTRU_EES439EP1, NTRU_EES593EP1, NTRU_EES743EP1
};
/* X9.98/IEEE 1363.1 parameter sets for best speed */
static ntru_param_set_id_t param_sets_x9_98_speed[] = {
static const ntru_param_set_id_t param_sets_x9_98_speed[] = {
NTRU_EES659EP1, NTRU_EES761EP1, NTRU_EES1087EP1, NTRU_EES1499EP1
};
/* X9.98/IEEE 1363.1 parameter sets for best bandwidth (smallest size) */
static ntru_param_set_id_t param_sets_x9_98_bandwidth[] = {
static const ntru_param_set_id_t param_sets_x9_98_bandwidth[] = {
NTRU_EES401EP1, NTRU_EES449EP1, NTRU_EES677EP1, NTRU_EES1087EP2
};
/* X9.98/IEEE 1363.1 parameter sets balancing speed and bandwidth */
static ntru_param_set_id_t param_sets_x9_98_balance[] = {
static const ntru_param_set_id_t param_sets_x9_98_balance[] = {
NTRU_EES541EP1, NTRU_EES613EP1, NTRU_EES887EP1, NTRU_EES1171EP1
};
@@ -61,7 +61,7 @@ struct private_ntru_ke_t {
/**
* NTRU Parameter Set
*/
ntru_param_set_t *param_set;
const ntru_param_set_t *param_set;
/**
* Cryptographical strength in bits of the NTRU Parameter Set
@@ -243,7 +243,8 @@ METHOD(diffie_hellman_t, destroy, void,
ntru_ke_t *ntru_ke_create(diffie_hellman_group_t group, chunk_t g, chunk_t p)
{
private_ntru_ke_t *this;
ntru_param_set_id_t *param_sets, param_set_id;
const ntru_param_set_id_t *param_sets;
ntru_param_set_id_t param_set_id;
rng_t *entropy;
ntru_drbg_t *drbg;
char *parameter_set;
@@ -41,7 +41,7 @@ ENUM(ntru_param_set_id_names, NTRU_EES401EP1, NTRU_EES743EP1,
/**
* NTRU encryption parameter set definitions
*/
static ntru_param_set_t ntru_param_sets[] = {
static const ntru_param_set_t ntru_param_sets[] = {
/* X9.98/IEEE 1363.1 parameter sets for best bandwidth (smallest size) */
{
@@ -340,7 +340,7 @@ static ntru_param_set_t ntru_param_sets[] = {
/**
* See header.
*/
ntru_param_set_t* ntru_param_set_get_by_id(ntru_param_set_id_t id)
const ntru_param_set_t* ntru_param_set_get_by_id(ntru_param_set_id_t id)
{
int i;
@@ -358,7 +358,7 @@ ntru_param_set_t* ntru_param_set_get_by_id(ntru_param_set_id_t id)
/**
* See header.
*/
ntru_param_set_t* ntru_param_set_get_by_oid(uint8_t const *oid)
const ntru_param_set_t* ntru_param_set_get_by_oid(uint8_t const *oid)
{
int i;
+77 -19
View File
@@ -80,23 +80,81 @@ extern enum_name_t *ntru_param_set_id_names;
* NTRU encryption parameter set definitions
*/
struct ntru_param_set_t {
ntru_param_set_id_t id; /* NTRU parameter set ID */
uint8_t oid[NTRU_OID_LEN]; /* pointer to OID */
uint8_t der_id; /* parameter-set DER id */
uint8_t N_bits; /* no. of bits in N (i.e. in an index */
uint16_t N; /* ring dimension */
uint16_t sec_strength_len; /* no. of octets of security strength */
uint16_t q; /* big modulus */
uint8_t q_bits; /* no. of bits in q (i.e. in a coefficient */
bool is_product_form; /* if product form used */
uint32_t dF_r; /* no. of +1 or -1 coefficients in ring elements
F, r */
uint16_t dg; /* no. - 1 of +1 coefficients or
no. of -1 coefficients in ring element g */
uint16_t m_len_max; /* max no. of plaintext octets */
uint16_t min_msg_rep_wt; /* min. message representative weight */
uint8_t c_bits; /* no. bits in candidate for deriving an index */
uint8_t m_len_len; /* no. of octets to hold mLenOctets */
/**
* NTRU parameter set ID
*/
const ntru_param_set_id_t id;
/**
* pointer to OID
*/
const uint8_t oid[NTRU_OID_LEN];
/**
* parameter-set DER id
*/
const uint8_t der_id;
/**
* no. of bits in N (i.e. in an index
*/
const uint8_t N_bits;
/**
* ring dimension
*/
const uint16_t N;
/**
* no. of octets of security strength
*/
const uint16_t sec_strength_len;
/**
* big modulus
*/
const uint16_t q;
/**
* no. of bits in q (i.e. in a coefficient)
*/
const uint8_t q_bits;
/**
* if product form used
*/
const bool is_product_form;
/**
* no. of +1 or -1 coefficients in ring elements F, r
*/
const uint32_t dF_r;
/**
* no. - 1 of +1 coefficients or no. of -1 coefficients in ring element g
*/
const uint16_t dg;
/**
* max no. of plaintext octets
*/
const uint16_t m_len_max;
/**
* min. message representative weight
*/
const uint16_t min_msg_rep_wt;
/**
* no. bits in candidate for deriving an index
*/
const uint8_t c_bits;
/**
* no. of octets to hold mLenOctets
*/
const uint8_t m_len_len;
};
/**
@@ -105,7 +163,7 @@ struct ntru_param_set_t {
* @param id NTRU parameter set ID
* @return NTRU parameter set
*/
ntru_param_set_t* ntru_param_set_get_by_id(ntru_param_set_id_t id);
const ntru_param_set_t* ntru_param_set_get_by_id(ntru_param_set_id_t id);
/**
* Get NTRU encryption parameter set by NTRU parameter set OID
@@ -113,6 +171,6 @@ ntru_param_set_t* ntru_param_set_get_by_id(ntru_param_set_id_t id);
* @param oid NTRU parameter set OID
* @return NTRU parameter set
*/
ntru_param_set_t* ntru_param_set_get_by_oid(uint8_t const *oid);
const ntru_param_set_t* ntru_param_set_get_by_oid(uint8_t const *oid);
#endif /** NTRU_PARAM_SET_H_ @}*/
@@ -38,7 +38,7 @@ struct private_ntru_private_key_t {
/**
* NTRU Parameter Set
*/
ntru_param_set_t *params;
const ntru_param_set_t *params;
/**
* Polynomial F which is the private key
@@ -642,7 +642,7 @@ static bool ring_inv(uint16_t *a, uint16_t N, uint16_t q, uint16_t *t,
* Described in header.
*/
ntru_private_key_t *ntru_private_key_create(ntru_drbg_t *drbg,
ntru_param_set_t *params)
const ntru_param_set_t *params)
{
private_ntru_private_key_t *this;
size_t t_len;
@@ -775,7 +775,7 @@ ntru_private_key_t *ntru_private_key_create_from_data(ntru_drbg_t *drbg,
size_t privkey_packed_trits_len, privkey_packed_indices_len;
uint8_t *privkey_packed, tag;
uint16_t *indices, dF;
ntru_param_set_t *params;
const ntru_param_set_t *params;
header_len = 2 + NTRU_OID_LEN;
@@ -77,7 +77,8 @@ struct ntru_private_key_t {
* @param drbg Digital Random Bit Generator used for key generation
* @param params NTRU encryption parameter set to be used
*/
ntru_private_key_t *ntru_private_key_create(ntru_drbg_t *drbg, ntru_param_set_t *params);
ntru_private_key_t *ntru_private_key_create(ntru_drbg_t *drbg,
const ntru_param_set_t *params);
/**
* Creates an NTRU encryption private key from encoding
@@ -37,7 +37,7 @@ struct private_ntru_public_key_t {
/**
* NTRU Parameter Set
*/
ntru_param_set_t *params;
const ntru_param_set_t *params;
/**
* Polynomial h which is the public key
@@ -320,7 +320,7 @@ METHOD(ntru_public_key_t, destroy, void,
* Described in header.
*/
ntru_public_key_t *ntru_public_key_create(ntru_drbg_t *drbg,
ntru_param_set_t *params,
const ntru_param_set_t *params,
uint16_t *pubkey)
{
private_ntru_public_key_t *this;
@@ -357,7 +357,7 @@ ntru_public_key_t *ntru_public_key_create_from_data(ntru_drbg_t *drbg,
{
private_ntru_public_key_t *this;
size_t header_len, pubkey_packed_len;
ntru_param_set_t *params;
const ntru_param_set_t *params;
header_len = 2 + NTRU_OID_LEN;
@@ -71,7 +71,7 @@ struct ntru_public_key_t {
* @param pubkey Coefficients of public key polynomial h
*/
ntru_public_key_t *ntru_public_key_create(ntru_drbg_t *drbg,
ntru_param_set_t *params,
const ntru_param_set_t *params,
uint16_t *pubkey);
/**
@@ -30,6 +30,7 @@ ENUM(plugin_feature_names, FEATURE_NONE, FEATURE_CUSTOM,
"SIGNER",
"HASHER",
"PRF",
"XOF",
"DH",
"RNG",
"NONCE_GEN",
@@ -87,6 +88,9 @@ uint32_t plugin_feature_hash(plugin_feature_t *feature)
case FEATURE_PRF:
data = chunk_from_thing(feature->arg.prf);
break;
case FEATURE_XOF:
data = chunk_from_thing(feature->arg.xof);
break;
case FEATURE_DH:
data = chunk_from_thing(feature->arg.dh_group);
break;
@@ -160,6 +164,8 @@ bool plugin_feature_matches(plugin_feature_t *a, plugin_feature_t *b)
return a->arg.hasher == b->arg.hasher;
case FEATURE_PRF:
return a->arg.prf == b->arg.prf;
case FEATURE_XOF:
return a->arg.xof == b->arg.xof;
case FEATURE_DH:
return a->arg.dh_group == b->arg.dh_group;
case FEATURE_RNG:
@@ -218,6 +224,7 @@ bool plugin_feature_equals(plugin_feature_t *a, plugin_feature_t *b)
case FEATURE_SIGNER:
case FEATURE_HASHER:
case FEATURE_PRF:
case FEATURE_XOF:
case FEATURE_DH:
case FEATURE_NONCE_GEN:
case FEATURE_RESOLVER:
@@ -305,6 +312,13 @@ char* plugin_feature_get_string(plugin_feature_t *feature)
return str;
}
break;
case FEATURE_XOF:
if (asprintf(&str, "%N:%N", plugin_feature_names, feature->type,
ext_out_function_names, feature->arg.xof) > 0)
{
return str;
}
break;
case FEATURE_DH:
if (asprintf(&str, "%N:%N", plugin_feature_names, feature->type,
diffie_hellman_group_names, feature->arg.dh_group) > 0)
@@ -465,6 +479,10 @@ bool plugin_feature_load(plugin_t *plugin, plugin_feature_t *feature,
lib->crypto->add_prf(lib->crypto, feature->arg.prf,
name, reg->arg.reg.f);
break;
case FEATURE_XOF:
lib->crypto->add_xof(lib->crypto, feature->arg.xof,
name, reg->arg.reg.f);
break;
case FEATURE_DH:
lib->crypto->add_dh(lib->crypto, feature->arg.dh_group,
name, reg->arg.reg.f);
@@ -552,6 +570,9 @@ bool plugin_feature_unload(plugin_t *plugin, plugin_feature_t *feature,
case FEATURE_PRF:
lib->crypto->remove_prf(lib->crypto, reg->arg.reg.f);
break;
case FEATURE_XOF:
lib->crypto->remove_xof(lib->crypto, reg->arg.reg.f);
break;
case FEATURE_DH:
lib->crypto->remove_dh(lib->crypto, reg->arg.reg.f);
break;
@@ -110,6 +110,8 @@ struct plugin_feature_t {
FEATURE_HASHER,
/** prf_t */
FEATURE_PRF,
/** xof_t */
FEATURE_XOF,
/** diffie_hellman_t */
FEATURE_DH,
/** rng_t */
@@ -171,6 +173,8 @@ struct plugin_feature_t {
integrity_algorithm_t signer;
/** FEATURE_PRF */
pseudo_random_function_t prf;
/** FEATURE_XOFF */
ext_out_function_t xof;
/** FEATURE_HASHER */
hash_algorithm_t hasher;
/** FEATURE_DH */
@@ -278,6 +282,7 @@ struct plugin_feature_t {
#define _PLUGIN_FEATURE_SIGNER(kind, alg) __PLUGIN_FEATURE(kind, SIGNER, .signer = alg)
#define _PLUGIN_FEATURE_HASHER(kind, alg) __PLUGIN_FEATURE(kind, HASHER, .hasher = alg)
#define _PLUGIN_FEATURE_PRF(kind, alg) __PLUGIN_FEATURE(kind, PRF, .prf = alg)
#define _PLUGIN_FEATURE_XOF(kind, alg) __PLUGIN_FEATURE(kind, XOF, .xof = alg)
#define _PLUGIN_FEATURE_DH(kind, group) __PLUGIN_FEATURE(kind, DH, .dh_group = group)
#define _PLUGIN_FEATURE_RNG(kind, quality) __PLUGIN_FEATURE(kind, RNG, .rng_quality = quality)
#define _PLUGIN_FEATURE_NONCE_GEN(kind, ...) __PLUGIN_FEATURE(kind, NONCE_GEN, .custom = NULL)
@@ -310,6 +315,7 @@ struct plugin_feature_t {
#define _PLUGIN_FEATURE_REGISTER_SIGNER(type, f) __PLUGIN_FEATURE_REGISTER(type, f)
#define _PLUGIN_FEATURE_REGISTER_HASHER(type, f) __PLUGIN_FEATURE_REGISTER(type, f)
#define _PLUGIN_FEATURE_REGISTER_PRF(type, f) __PLUGIN_FEATURE_REGISTER(type, f)
#define _PLUGIN_FEATURE_REGISTER_XOF(type, f) __PLUGIN_FEATURE_REGISTER(type, f)
#define _PLUGIN_FEATURE_REGISTER_DH(type, f) __PLUGIN_FEATURE_REGISTER(type, f)
#define _PLUGIN_FEATURE_REGISTER_RNG(type, f) __PLUGIN_FEATURE_REGISTER(type, f)
#define _PLUGIN_FEATURE_REGISTER_NONCE_GEN(type, f) __PLUGIN_FEATURE_REGISTER(type, f)
+4 -1
View File
@@ -11,6 +11,9 @@ plugin_LTLIBRARIES = libstrongswan-sha3.la
endif
libstrongswan_sha3_la_SOURCES = \
sha3_plugin.h sha3_plugin.c sha3_hasher.c sha3_hasher.h
sha3_plugin.h sha3_plugin.c \
sha3_hasher.c sha3_hasher.h \
sha3_shake.h sha3_shake.c \
sha3_keccak.h sha3_keccak.c
libstrongswan_sha3_la_LDFLAGS = -module -avoid-version
+35 -412
View File
@@ -1,53 +1,25 @@
/*
* Copyright (C) 2015 Andreas Steffen
* Copyright (C) 2015-2016 Andreas Steffen
* HSR Hochschule fuer Technik Rapperswil
*
* Based on the implementation by the Keccak, Keyak and Ketje Teams, namely,
* Guido Bertoni, Joan Daemen, Michaël Peeters, Gilles Van Assche and
* Ronny Van Keer, hereby denoted as "the implementer".
* 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>.
*
* To the extent possible under law, the implementer has waived all copyright
* and related or neighboring rights to the source code in this file.
* http://creativecommons.org/publicdomain/zero/1.0/
* 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 <string.h>
#include "sha3_hasher.h"
#include "sha3_keccak.h"
typedef struct private_sha3_hasher_t private_sha3_hasher_t;
#define KECCAK_STATE_SIZE 200 /* bytes */
#define KECCAK_MAX_RATE 144 /* bytes */
#define DELIMITED_SUFFIX 0x06
static const uint64_t round_constants[] = {
0x0000000000000001ULL,
0x0000000000008082ULL,
0x800000000000808aULL,
0x8000000080008000ULL,
0x000000000000808bULL,
0x0000000080000001ULL,
0x8000000080008081ULL,
0x8000000000008009ULL,
0x000000000000008aULL,
0x0000000000000088ULL,
0x0000000080008009ULL,
0x000000008000000aULL,
0x000000008000808bULL,
0x800000000000008bULL,
0x8000000000008089ULL,
0x8000000000008003ULL,
0x8000000000008002ULL,
0x8000000000000080ULL,
0x000000000000800aULL,
0x800000008000000aULL,
0x8000000080008081ULL,
0x8000000000008080ULL,
0x0000000080000001ULL,
0x8000000080008008ULL
};
/**
* Private data structure with hashing context for SHA-3
*/
@@ -64,309 +36,16 @@ struct private_sha3_hasher_t {
hash_algorithm_t algorithm;
/**
* Internal state of 1600 bits as defined by FIPS-202
* SHA-3 Keccak state
*/
uint8_t state[KECCAK_STATE_SIZE];
/**
* Rate in bytes
*/
u_int rate;
/**
* Rate input buffer
*/
uint8_t rate_buffer[KECCAK_MAX_RATE];
/**
* Index pointing to the current position in the rate buffer
*/
u_int rate_index;
sha3_keccak_t *keccak;
};
#if BYTE_ORDER != LITTLE_ENDIAN
/**
* Function to load a 64-bit value using the little-endian (LE) convention.
* On a LE platform, this could be greatly simplified using a cast.
*/
static uint64_t load64(const uint8_t *x)
{
int i;
uint64_t u = 0;
for (i = 7; i >= 0; --i)
{
u <<= 8;
u |= x[i];
}
return u;
}
/**
* Function to store a 64-bit value using the little-endian (LE) convention.
* On a LE platform, this could be greatly simplified using a cast.
*/
static void store64(uint8_t *x, uint64_t u)
{
u_int i;
for (i = 0; i < 8; ++i)
{
x[i] = u;
u >>= 8;
}
}
/**
* Function to XOR into a 64-bit value using the little-endian (LE) convention.
* On a LE platform, this could be greatly simplified using a cast.
*/
static void xor64(uint8_t *x, uint64_t u)
{
u_int i;
for (i = 0; i < 8; ++i)
{
x[i] ^= u;
u >>= 8;
}
}
#endif
/**
* Some macros used by the Keccak-f[1600] permutation.
*/
#define ROL64(a, offset) ((((uint64_t)a) << offset) ^ (((uint64_t)a) >> (64-offset)))
#if BYTE_ORDER == LITTLE_ENDIAN
#define readLane(i) (((uint64_t*)state)[i])
#define writeLane(i, lane) (((uint64_t*)state)[i]) = (lane)
#define XORLane(i, lane) (((uint64_t*)state)[i]) ^= (lane)
#elif BYTE_ORDER == BIG_ENDIAN
#define readLane(i) load64((uint8_t*)state+sizeof(uint64_t)*i))
#define writeLane(i, lane) store64((uint8_t*)state+sizeof(uint64_t)*i, lane)
#define XORLane(i, lane) xor64((uint8_t*)state+sizeof(uint64_t)*i, lane)
#endif
/**
* Function that computes the Keccak-f[1600] permutation on the given state.
*/
static void keccak_f1600_state_permute(void *state)
{
int round;
for (round = 0; round < 24; round++)
{
{ /* θ step (see [Keccak Reference, Section 2.3.2]) */
uint64_t C[5], D;
/* Compute the parity of the columns */
C[0] = readLane(0) ^ readLane( 5) ^ readLane(10)
^ readLane(15) ^ readLane(20);
C[1] = readLane(1) ^ readLane( 6) ^ readLane(11)
^ readLane(16) ^ readLane(21);
C[2] = readLane(2) ^ readLane( 7) ^ readLane(12)
^ readLane(17) ^ readLane(22);
C[3] = readLane(3) ^ readLane( 8) ^ readLane(13)
^ readLane(18) ^ readLane(23);
C[4] = readLane(4) ^ readLane( 9) ^ readLane(14)
^ readLane(19) ^ readLane(24);
/* Compute and add the θ effect to the whole column */
D = C[4] ^ ROL64(C[1], 1);
XORLane( 0, D);
XORLane( 5, D);
XORLane(10, D);
XORLane(15, D);
XORLane(20, D);
D = C[0] ^ ROL64(C[2], 1);
XORLane( 1, D);
XORLane( 6, D);
XORLane(11, D);
XORLane(16, D);
XORLane(21, D);
D = C[1] ^ ROL64(C[3], 1);
XORLane( 2, D);
XORLane( 7, D);
XORLane(12, D);
XORLane(17, D);
XORLane(22, D);
D = C[2] ^ ROL64(C[4], 1);
XORLane( 3, D);
XORLane( 8, D);
XORLane(13, D);
XORLane(18, D);
XORLane(23, D);
D = C[3] ^ ROL64(C[0], 1);
XORLane( 4, D);
XORLane( 9, D);
XORLane(14, D);
XORLane(19, D);
XORLane(24, D);
}
{ /* ρ and π steps (see [Keccak Reference, Sections 2.3.3 and 2.3.4]) */
uint64_t t1, t2;
t1 = readLane( 1);
t2 = readLane(10);
writeLane(10, ROL64(t1, 1));
t1 = readLane( 7);
writeLane( 7, ROL64(t2, 3));
t2 = readLane(11);
writeLane(11, ROL64(t1, 6));
t1 = readLane(17);
writeLane(17, ROL64(t2, 10));
t2 = readLane(18);
writeLane(18, ROL64(t1, 15));
t1 = readLane( 3);
writeLane( 3, ROL64(t2, 21));
t2 = readLane( 5);
writeLane( 5, ROL64(t1, 28));
t1 = readLane(16);
writeLane(16, ROL64(t2, 36));
t2 = readLane( 8);
writeLane( 8, ROL64(t1, 45));
t1 = readLane(21);
writeLane(21, ROL64(t2, 55));
t2 = readLane(24);
writeLane(24, ROL64(t1, 2));
t1 = readLane( 4);
writeLane( 4, ROL64(t2, 14));
t2 = readLane(15);
writeLane(15, ROL64(t1, 27));
t1 = readLane(23);
writeLane(23, ROL64(t2, 41));
t2 = readLane(19);
writeLane(19, ROL64(t1, 56));
t1 = readLane(13);
writeLane(13, ROL64(t2, 8));
t2 = readLane(12);
writeLane(12, ROL64(t1, 25));
t1 = readLane( 2);
writeLane( 2, ROL64(t2, 43));
t2 = readLane(20);
writeLane(20, ROL64(t1, 62));
t1 = readLane(14);
writeLane(14, ROL64(t2, 18));
t2 = readLane(22);
writeLane(22, ROL64(t1, 39));
t1 = readLane( 9);
writeLane( 9, ROL64(t2, 61));
t2 = readLane( 6);
writeLane( 6, ROL64(t1, 20));
writeLane( 1, ROL64(t2, 44));
}
{ /* χ step (see [Keccak Reference, Section 2.3.1]) */
uint64_t t[5];
t[0] = readLane(0);
t[1] = readLane(1);
t[2] = readLane(2);
t[3] = readLane(3);
t[4] = readLane(4);
writeLane(0, t[0] ^ ((~t[1]) & t[2]));
writeLane(1, t[1] ^ ((~t[2]) & t[3]));
writeLane(2, t[2] ^ ((~t[3]) & t[4]));
writeLane(3, t[3] ^ ((~t[4]) & t[0]));
writeLane(4, t[4] ^ ((~t[0]) & t[1]));
t[0] = readLane(5);
t[1] = readLane(6);
t[2] = readLane(7);
t[3] = readLane(8);
t[4] = readLane(9);
writeLane(5, t[0] ^ ((~t[1]) & t[2]));
writeLane(6, t[1] ^ ((~t[2]) & t[3]));
writeLane(7, t[2] ^ ((~t[3]) & t[4]));
writeLane(8, t[3] ^ ((~t[4]) & t[0]));
writeLane(9, t[4] ^ ((~t[0]) & t[1]));
t[0] = readLane(10);
t[1] = readLane(11);
t[2] = readLane(12);
t[3] = readLane(13);
t[4] = readLane(14);
writeLane(10, t[0] ^ ((~t[1]) & t[2]));
writeLane(11, t[1] ^ ((~t[2]) & t[3]));
writeLane(12, t[2] ^ ((~t[3]) & t[4]));
writeLane(13, t[3] ^ ((~t[4]) & t[0]));
writeLane(14, t[4] ^ ((~t[0]) & t[1]));
t[0] = readLane(15);
t[1] = readLane(16);
t[2] = readLane(17);
t[3] = readLane(18);
t[4] = readLane(19);
writeLane(15, t[0] ^ ((~t[1]) & t[2]));
writeLane(16, t[1] ^ ((~t[2]) & t[3]));
writeLane(17, t[2] ^ ((~t[3]) & t[4]));
writeLane(18, t[3] ^ ((~t[4]) & t[0]));
writeLane(19, t[4] ^ ((~t[0]) & t[1]));
t[0] = readLane(20);
t[1] = readLane(21);
t[2] = readLane(22);
t[3] = readLane(23);
t[4] = readLane(24);
writeLane(20, t[0] ^ ((~t[1]) & t[2]));
writeLane(21, t[1] ^ ((~t[2]) & t[3]));
writeLane(22, t[2] ^ ((~t[3]) & t[4]));
writeLane(23, t[3] ^ ((~t[4]) & t[0]));
writeLane(24, t[4] ^ ((~t[0]) & t[1]));
}
{ /* ι step (see [Keccak Reference, Section 2.3.5]) */
XORLane(0, round_constants[round]);
}
}
}
METHOD(hasher_t, reset, bool,
private_sha3_hasher_t *this)
{
memset(this->state, 0x00, KECCAK_STATE_SIZE);
this->rate_index = 0;
this->keccak->reset(this->keccak);
return TRUE;
}
@@ -388,79 +67,17 @@ METHOD(hasher_t, get_hash_size, size_t,
}
}
static void sha3_absorb(private_sha3_hasher_t *this, chunk_t data)
{
uint64_t *buffer_lanes, *state_lanes;
size_t len, rate_lanes;
int i;
buffer_lanes = (uint64_t*)this->rate_buffer;
state_lanes = (uint64_t*)this->state;
rate_lanes = this->rate / sizeof(uint64_t);
while (data.len)
{
len = min(data.len, this->rate - this->rate_index);
memcpy(this->rate_buffer + this->rate_index, data.ptr, len);
this->rate_index += len;
data.ptr += len;
data.len -= len;
if (this->rate_index == this->rate)
{
for (i = 0; i < rate_lanes; i++)
{
state_lanes[i] ^= buffer_lanes[i];
}
this->rate_index = 0;
keccak_f1600_state_permute(this->state);
}
}
}
static void sha3_final(private_sha3_hasher_t *this)
{
uint64_t *buffer_lanes, *state_lanes;
size_t rate_lanes, remainder;
int i;
/* Add the delimitedSuffix as the first bit of padding */
this->rate_buffer[this->rate_index++] = DELIMITED_SUFFIX;
buffer_lanes = (uint64_t*)this->rate_buffer;
state_lanes = (uint64_t*)this->state;
rate_lanes = this->rate_index / sizeof(uint64_t);
remainder = this->rate_index - rate_lanes * sizeof(uint64_t);
if (remainder)
{
memset(this->rate_buffer + this->rate_index, 0x00,
sizeof(uint64_t) - remainder);
rate_lanes++;
}
for (i = 0; i < rate_lanes; i++)
{
state_lanes[i] ^= buffer_lanes[i];
}
/* Add the second bit of padding */
this->state[this->rate - 1] ^= 0x80;
/* Switch to the squeezing phase */
keccak_f1600_state_permute(this->state);
}
METHOD(hasher_t, get_hash, bool,
private_sha3_hasher_t *this, chunk_t chunk, uint8_t *buffer)
{
sha3_absorb(this, chunk);
this->keccak->absorb(this->keccak, chunk);
if (buffer != NULL)
{
sha3_final(this);
memcpy(buffer, this->state, get_hash_size(this));
reset(this);
this->keccak->finalize(this->keccak);
this->keccak->squeeze(this->keccak, get_hash_size(this), buffer);
this->keccak->reset(this->keccak);
}
return TRUE;
}
@@ -470,22 +87,24 @@ METHOD(hasher_t, allocate_hash, bool,
{
chunk_t allocated_hash;
sha3_absorb(this, chunk);
this->keccak->absorb(this->keccak, chunk);
if (hash != NULL)
{
sha3_final(this);
this->keccak->finalize(this->keccak);
allocated_hash = chunk_alloc(get_hash_size(this));
memcpy(allocated_hash.ptr, this->state, allocated_hash.len);
reset(this);
this->keccak->squeeze(this->keccak, allocated_hash.len,
allocated_hash.ptr);
this->keccak->reset(this->keccak);
*hash = allocated_hash;
}
return TRUE;
}
METHOD(hasher_t, destroy, void,
sha3_hasher_t *this)
private_sha3_hasher_t *this)
{
this->keccak->destroy(this->keccak);
free(this);
}
@@ -510,18 +129,22 @@ sha3_hasher_t *sha3_hasher_create(hash_algorithm_t algorithm)
INIT(this,
.public = {
.hasher_interface = {
.reset = _reset,
.get_hash_size = _get_hash_size,
.get_hash = _get_hash,
.allocate_hash = _allocate_hash,
.destroy = _destroy,
.reset = _reset,
.get_hash_size = _get_hash_size,
.get_hash = _get_hash,
.allocate_hash = _allocate_hash,
.destroy = _destroy,
},
},
.algorithm = algorithm,
);
this->rate = KECCAK_STATE_SIZE - 2*get_hash_size(this);
reset(this);
this->keccak = sha3_keccak_create(2*get_hash_size(this), 0x06);
if (!this->keccak)
{
free(this);
return NULL;
}
return &this->public;
}
@@ -0,0 +1,498 @@
/*
* Copyright (C) 2015-2016 Andreas Steffen
* HSR Hochschule fuer Technik Rapperswil
*
* Based on the implementation by the Keccak, Keyak and Ketje Teams, namely,
* Guido Bertoni, Joan Daemen, Michaël Peeters, Gilles Van Assche and
* Ronny Van Keer, hereby denoted as "the implementer".
*
* To the extent possible under law, the implementer has waived all copyright
* and related or neighboring rights to the source code in this file.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
#include <string.h>
#include "sha3_keccak.h"
typedef struct private_sha3_keccak_t private_sha3_keccak_t;
#define KECCAK_STATE_SIZE 200 /* bytes */
#define KECCAK_MAX_RATE 168 /* bytes */
static const uint64_t round_constants[] = {
0x0000000000000001ULL,
0x0000000000008082ULL,
0x800000000000808aULL,
0x8000000080008000ULL,
0x000000000000808bULL,
0x0000000080000001ULL,
0x8000000080008081ULL,
0x8000000000008009ULL,
0x000000000000008aULL,
0x0000000000000088ULL,
0x0000000080008009ULL,
0x000000008000000aULL,
0x000000008000808bULL,
0x800000000000008bULL,
0x8000000000008089ULL,
0x8000000000008003ULL,
0x8000000000008002ULL,
0x8000000000000080ULL,
0x000000000000800aULL,
0x800000008000000aULL,
0x8000000080008081ULL,
0x8000000000008080ULL,
0x0000000080000001ULL,
0x8000000080008008ULL
};
/**
* Private data structure with hashing context for SHA-3
*/
struct private_sha3_keccak_t {
/**
* Public interface for this hasher.
*/
sha3_keccak_t public;
/**
* Internal state of 1600 bits as defined by FIPS-202
*/
uint8_t state[KECCAK_STATE_SIZE];
/**
* Rate in bytes
*/
u_int rate;
/**
* Rate input buffer
*/
uint8_t rate_buffer[KECCAK_MAX_RATE];
/**
* Index pointing to the current position in the rate buffer
*/
u_int rate_index;
/**
* Suffix delimiting the input message
*/
uint8_t delimited_suffix;
};
#if BYTE_ORDER != LITTLE_ENDIAN
/**
* Function to load a 64-bit value using the little-endian (LE) convention.
* On a LE platform, this could be greatly simplified using a cast.
*/
static uint64_t load64(const uint8_t *x)
{
int i;
uint64_t u = 0;
for (i = 7; i >= 0; --i)
{
u <<= 8;
u |= x[i];
}
return u;
}
/**
* Function to store a 64-bit value using the little-endian (LE) convention.
* On a LE platform, this could be greatly simplified using a cast.
*/
static void store64(uint8_t *x, uint64_t u)
{
u_int i;
for (i = 0; i < 8; ++i)
{
x[i] = u;
u >>= 8;
}
}
/**
* Function to XOR into a 64-bit value using the little-endian (LE) convention.
* On a LE platform, this could be greatly simplified using a cast.
*/
static void xor64(uint8_t *x, uint64_t u)
{
u_int i;
for (i = 0; i < 8; ++i)
{
x[i] ^= u;
u >>= 8;
}
}
#endif
/**
* Some macros used by the Keccak-f[1600] permutation.
*/
#define ROL64(a, offset) ((((uint64_t)a) << offset) ^ (((uint64_t)a) >> (64-offset)))
#if BYTE_ORDER == LITTLE_ENDIAN
#define readLane(i) (((uint64_t*)state)[i])
#define writeLane(i, lane) (((uint64_t*)state)[i]) = (lane)
#define XORLane(i, lane) (((uint64_t*)state)[i]) ^= (lane)
#elif BYTE_ORDER == BIG_ENDIAN
#define readLane(i) load64((uint8_t*)state+sizeof(uint64_t)*i))
#define writeLane(i, lane) store64((uint8_t*)state+sizeof(uint64_t)*i, lane)
#define XORLane(i, lane) xor64((uint8_t*)state+sizeof(uint64_t)*i, lane)
#endif
/**
* Function that computes the Keccak-f[1600] permutation on the given state.
*/
static void keccak_f1600_state_permute(void *state)
{
int round;
for (round = 0; round < 24; round++)
{
{ /* θ step (see [Keccak Reference, Section 2.3.2]) */
uint64_t C[5], D;
/* Compute the parity of the columns */
C[0] = readLane(0) ^ readLane( 5) ^ readLane(10)
^ readLane(15) ^ readLane(20);
C[1] = readLane(1) ^ readLane( 6) ^ readLane(11)
^ readLane(16) ^ readLane(21);
C[2] = readLane(2) ^ readLane( 7) ^ readLane(12)
^ readLane(17) ^ readLane(22);
C[3] = readLane(3) ^ readLane( 8) ^ readLane(13)
^ readLane(18) ^ readLane(23);
C[4] = readLane(4) ^ readLane( 9) ^ readLane(14)
^ readLane(19) ^ readLane(24);
/* Compute and add the θ effect to the whole column */
D = C[4] ^ ROL64(C[1], 1);
XORLane( 0, D);
XORLane( 5, D);
XORLane(10, D);
XORLane(15, D);
XORLane(20, D);
D = C[0] ^ ROL64(C[2], 1);
XORLane( 1, D);
XORLane( 6, D);
XORLane(11, D);
XORLane(16, D);
XORLane(21, D);
D = C[1] ^ ROL64(C[3], 1);
XORLane( 2, D);
XORLane( 7, D);
XORLane(12, D);
XORLane(17, D);
XORLane(22, D);
D = C[2] ^ ROL64(C[4], 1);
XORLane( 3, D);
XORLane( 8, D);
XORLane(13, D);
XORLane(18, D);
XORLane(23, D);
D = C[3] ^ ROL64(C[0], 1);
XORLane( 4, D);
XORLane( 9, D);
XORLane(14, D);
XORLane(19, D);
XORLane(24, D);
}
{ /* ρ and π steps (see [Keccak Reference, Sections 2.3.3 and 2.3.4]) */
uint64_t t1, t2;
t1 = readLane( 1);
t2 = readLane(10);
writeLane(10, ROL64(t1, 1));
t1 = readLane( 7);
writeLane( 7, ROL64(t2, 3));
t2 = readLane(11);
writeLane(11, ROL64(t1, 6));
t1 = readLane(17);
writeLane(17, ROL64(t2, 10));
t2 = readLane(18);
writeLane(18, ROL64(t1, 15));
t1 = readLane( 3);
writeLane( 3, ROL64(t2, 21));
t2 = readLane( 5);
writeLane( 5, ROL64(t1, 28));
t1 = readLane(16);
writeLane(16, ROL64(t2, 36));
t2 = readLane( 8);
writeLane( 8, ROL64(t1, 45));
t1 = readLane(21);
writeLane(21, ROL64(t2, 55));
t2 = readLane(24);
writeLane(24, ROL64(t1, 2));
t1 = readLane( 4);
writeLane( 4, ROL64(t2, 14));
t2 = readLane(15);
writeLane(15, ROL64(t1, 27));
t1 = readLane(23);
writeLane(23, ROL64(t2, 41));
t2 = readLane(19);
writeLane(19, ROL64(t1, 56));
t1 = readLane(13);
writeLane(13, ROL64(t2, 8));
t2 = readLane(12);
writeLane(12, ROL64(t1, 25));
t1 = readLane( 2);
writeLane( 2, ROL64(t2, 43));
t2 = readLane(20);
writeLane(20, ROL64(t1, 62));
t1 = readLane(14);
writeLane(14, ROL64(t2, 18));
t2 = readLane(22);
writeLane(22, ROL64(t1, 39));
t1 = readLane( 9);
writeLane( 9, ROL64(t2, 61));
t2 = readLane( 6);
writeLane( 6, ROL64(t1, 20));
writeLane( 1, ROL64(t2, 44));
}
{ /* χ step (see [Keccak Reference, Section 2.3.1]) */
uint64_t t[5];
t[0] = readLane(0);
t[1] = readLane(1);
t[2] = readLane(2);
t[3] = readLane(3);
t[4] = readLane(4);
writeLane(0, t[0] ^ ((~t[1]) & t[2]));
writeLane(1, t[1] ^ ((~t[2]) & t[3]));
writeLane(2, t[2] ^ ((~t[3]) & t[4]));
writeLane(3, t[3] ^ ((~t[4]) & t[0]));
writeLane(4, t[4] ^ ((~t[0]) & t[1]));
t[0] = readLane(5);
t[1] = readLane(6);
t[2] = readLane(7);
t[3] = readLane(8);
t[4] = readLane(9);
writeLane(5, t[0] ^ ((~t[1]) & t[2]));
writeLane(6, t[1] ^ ((~t[2]) & t[3]));
writeLane(7, t[2] ^ ((~t[3]) & t[4]));
writeLane(8, t[3] ^ ((~t[4]) & t[0]));
writeLane(9, t[4] ^ ((~t[0]) & t[1]));
t[0] = readLane(10);
t[1] = readLane(11);
t[2] = readLane(12);
t[3] = readLane(13);
t[4] = readLane(14);
writeLane(10, t[0] ^ ((~t[1]) & t[2]));
writeLane(11, t[1] ^ ((~t[2]) & t[3]));
writeLane(12, t[2] ^ ((~t[3]) & t[4]));
writeLane(13, t[3] ^ ((~t[4]) & t[0]));
writeLane(14, t[4] ^ ((~t[0]) & t[1]));
t[0] = readLane(15);
t[1] = readLane(16);
t[2] = readLane(17);
t[3] = readLane(18);
t[4] = readLane(19);
writeLane(15, t[0] ^ ((~t[1]) & t[2]));
writeLane(16, t[1] ^ ((~t[2]) & t[3]));
writeLane(17, t[2] ^ ((~t[3]) & t[4]));
writeLane(18, t[3] ^ ((~t[4]) & t[0]));
writeLane(19, t[4] ^ ((~t[0]) & t[1]));
t[0] = readLane(20);
t[1] = readLane(21);
t[2] = readLane(22);
t[3] = readLane(23);
t[4] = readLane(24);
writeLane(20, t[0] ^ ((~t[1]) & t[2]));
writeLane(21, t[1] ^ ((~t[2]) & t[3]));
writeLane(22, t[2] ^ ((~t[3]) & t[4]));
writeLane(23, t[3] ^ ((~t[4]) & t[0]));
writeLane(24, t[4] ^ ((~t[0]) & t[1]));
}
{ /* ι step (see [Keccak Reference, Section 2.3.5]) */
XORLane(0, round_constants[round]);
}
}
}
METHOD(sha3_keccak_t, get_rate, u_int,
private_sha3_keccak_t *this)
{
return this->rate;
}
METHOD(sha3_keccak_t, reset, void,
private_sha3_keccak_t *this)
{
memset(this->state, 0x00, KECCAK_STATE_SIZE);
this->rate_index = 0;
}
METHOD(sha3_keccak_t, absorb, void,
private_sha3_keccak_t *this, chunk_t data)
{
uint64_t *buffer_lanes, *state_lanes;
size_t len, rate_lanes;
int i;
buffer_lanes = (uint64_t*)this->rate_buffer;
state_lanes = (uint64_t*)this->state;
rate_lanes = this->rate / sizeof(uint64_t);
while (data.len)
{
len = min(data.len, this->rate - this->rate_index);
memcpy(this->rate_buffer + this->rate_index, data.ptr, len);
this->rate_index += len;
data.ptr += len;
data.len -= len;
if (this->rate_index == this->rate)
{
for (i = 0; i < rate_lanes; i++)
{
state_lanes[i] ^= buffer_lanes[i];
}
this->rate_index = 0;
keccak_f1600_state_permute(this->state);
}
}
}
METHOD(sha3_keccak_t, finalize, void,
private_sha3_keccak_t *this)
{
uint64_t *buffer_lanes, *state_lanes;
size_t rate_lanes, remainder;
int i;
/* Add the delimitedSuffix as the first bit of padding */
this->rate_buffer[this->rate_index++] = this->delimited_suffix;
buffer_lanes = (uint64_t*)this->rate_buffer;
state_lanes = (uint64_t*)this->state;
rate_lanes = this->rate_index / sizeof(uint64_t);
remainder = this->rate_index - rate_lanes * sizeof(uint64_t);
if (remainder)
{
memset(this->rate_buffer + this->rate_index, 0x00,
sizeof(uint64_t) - remainder);
rate_lanes++;
}
for (i = 0; i < rate_lanes; i++)
{
state_lanes[i] ^= buffer_lanes[i];
}
/* Add the second bit of padding */
this->state[this->rate - 1] ^= 0x80;
/* Switch to the squeezing phase */
keccak_f1600_state_permute(this->state);
this->rate_index = 0;
}
METHOD(sha3_keccak_t, squeeze, void,
private_sha3_keccak_t *this, size_t out_len, uint8_t *out)
{
size_t index = 0, len;
while (index < out_len)
{
if (this->rate_index == this->rate)
{
keccak_f1600_state_permute(this->state);
this->rate_index = 0;
}
len = min(out_len - index, this->rate - this->rate_index);
memcpy(out, &this->state[this->rate_index], len);
out += len;
index += len;
this->rate_index += len;
}
}
METHOD(sha3_keccak_t, destroy, void,
private_sha3_keccak_t *this)
{
free(this);
}
/*
* Described in header.
*/
sha3_keccak_t *sha3_keccak_create(u_int capacity, uint8_t delimited_suffix)
{
private_sha3_keccak_t *this;
int rate;
rate = KECCAK_STATE_SIZE - capacity;
if (rate <= 0 || rate > KECCAK_MAX_RATE)
{
return NULL;
}
INIT(this,
.public = {
.get_rate = _get_rate,
.reset = _reset,
.absorb = _absorb,
.finalize = _finalize,
.squeeze = _squeeze,
.destroy = _destroy,
},
.rate = rate,
.delimited_suffix = delimited_suffix,
);
return &this->public;
}
@@ -0,0 +1,82 @@
/*
* Copyright (C) 2016 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.
n */
/**
* @defgroup sha3_keccak sha3_keccak
* @{ @ingroup sha3_p
*/
#ifndef SHA3_KECCAK_H_
#define SHA3_KECCAK_H_
typedef struct sha3_keccak_t sha3_keccak_t;
#include <crypto/hashers/hasher.h>
/**
* Implements the Keccak-f[1600] sponge function as defined by FIPS-202.
*/
struct sha3_keccak_t {
/**
* Get the available rate in bytes
*
* @return rate in bytes
*/
u_int (*get_rate)(sha3_keccak_t *this);
/**
* Resets the interal Keccak state
*/
void (*reset)(sha3_keccak_t *this);
/**
* Absorbs data into the Keccak state
*
* @param data data to be absorbed
*/
void (*absorb)(sha3_keccak_t *this, chunk_t data);
/**
* Finalize the absorbtion phase and switch to the squeeze phase
*/
void (*finalize)(sha3_keccak_t *this);
/**
* Squeeze the Keccak state to get output data
* Can be called multiple times
*
* @param out_len number of output bytes requested
* @param out output buffer, must comprise at least out_len bytes
*/
void (*squeeze)(sha3_keccak_t *this, size_t out_len, uint8_t *out);
/**
* Destroy the sha3_keccak_t object
*/
void (*destroy)(sha3_keccak_t *this);
};
/**
* Creates a new sha3_keccak_t.
*
* @param capacity required capacity to achieve a given security level
* @param delimited_suffix bits delimiting the input message
* @return sha3_keccak_t object, NULL if capacity too big
*/
sha3_keccak_t *sha3_keccak_create(u_int capacity, uint8_t delimited_suffix);
#endif /** SHA3_KECCAK_H_ @}*/
+5 -1
View File
@@ -14,9 +14,10 @@
*/
#include "sha3_plugin.h"
#include "sha3_hasher.h"
#include "sha3_shake.h"
#include <library.h>
#include "sha3_hasher.h"
typedef struct private_sha3_plugin_t private_sha3_plugin_t;
@@ -46,6 +47,9 @@ METHOD(plugin_t, get_features, int,
PLUGIN_PROVIDE(HASHER, HASH_SHA3_256),
PLUGIN_PROVIDE(HASHER, HASH_SHA3_384),
PLUGIN_PROVIDE(HASHER, HASH_SHA3_512),
PLUGIN_REGISTER(XOF, sha3_shake_create),
PLUGIN_PROVIDE(XOF, XOF_SHAKE_128),
PLUGIN_PROVIDE(XOF, XOF_SHAKE_256),
};
*features = f;
return countof(f);
+137
View File
@@ -0,0 +1,137 @@
/*
* Copyright (C) 2016 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 "sha3_shake.h"
#include "sha3_keccak.h"
typedef struct private_sha3_shake_t private_sha3_shake_t;
/**
* Private data structure with hashing context for SHA-3
*/
struct private_sha3_shake_t {
/**
* Public interface for this hasher.
*/
sha3_shake_t public;
/**
* XOF algorithm to be used (XOF_SHAKE_128 or XOF_SHAKE_256)
*/
ext_out_function_t algorithm;
/**
* SHA-3 Keccak state
*/
sha3_keccak_t *keccak;
/**
* Capacity in bytes of the SHA-3 Keccak state
*/
u_int capacity;
};
METHOD(xof_t, get_bytes, bool,
private_sha3_shake_t *this, size_t out_len, uint8_t *buffer)
{
this->keccak->squeeze(this->keccak, out_len, buffer);
return TRUE;
}
METHOD(xof_t, allocate_bytes, bool,
private_sha3_shake_t *this, size_t out_len, chunk_t *chunk)
{
*chunk = chunk_alloc(out_len);
this->keccak->squeeze(this->keccak, out_len, chunk->ptr);
return TRUE;
}
METHOD(xof_t, get_block_size, size_t,
private_sha3_shake_t *this)
{
return this->keccak->get_rate(this->keccak);
}
METHOD(xof_t, get_seed_size, size_t,
private_sha3_shake_t *this)
{
return this->capacity;
}
METHOD(xof_t, set_seed, bool,
private_sha3_shake_t *this, chunk_t seed)
{
this->keccak->reset(this->keccak);
this->keccak->absorb(this->keccak, seed);
this->keccak->finalize(this->keccak);
return TRUE;
}
METHOD(xof_t, destroy, void,
private_sha3_shake_t *this)
{
this->keccak->destroy(this->keccak);
free(this);
}
/*
* Described in header.
*/
sha3_shake_t* sha3_shake_create(ext_out_function_t algorithm)
{
private_sha3_shake_t *this;
u_int capacity = 0;
switch (algorithm)
{
case XOF_SHAKE_128:
capacity = 32;
break;
case XOF_SHAKE_256:
capacity = 64;
break;
default:
return NULL;
}
INIT(this,
.public = {
.xof_interface = {
.get_bytes = _get_bytes,
.allocate_bytes = _allocate_bytes,
.get_block_size = _get_block_size,
.get_seed_size = _get_seed_size,
.set_seed = _set_seed,
.destroy = _destroy,
},
},
.algorithm = algorithm,
.capacity = capacity,
);
this->keccak = sha3_keccak_create(capacity, 0x1f);
if (!this->keccak)
{
free(this);
return NULL;
}
return &this->public;
}
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2016 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.
*/
/**
* @defgroup sha3_shake sha3_shake
* @{ @ingroup sha3_p
*/
#ifndef SHA3_SHAKE_H_
#define SHA3_SHAKE_H_
typedef struct sha3_shake_t sha3_shake_t;
#include <crypto/xofs/xof.h>
/**
* Implementation of xof_t interface using the SHA-3 XOF algorithm family
* SHAKE128 and SHAKE256 as defined by FIPS-202.
*/
struct sha3_shake_t {
/**
* Generic xof_t interface for this Extended Output Function (XOF).
*/
xof_t xof_interface;
};
/**
* Creates a new sha3_shake_t.
*
* @param algorithm XOF_SHAKE_128 or XOF_SHAKE_256
* @return sha3_shake_t object, NULL if not supported
*/
sha3_shake_t* sha3_shake_create(ext_out_function_t algorithm);
#endif /** SHA3_SHAKE_H_ @}*/
@@ -20,6 +20,7 @@ libstrongswan_test_vectors_la_SOURCES = \
test_vectors/aes_ccm.c \
test_vectors/aes_gcm.c \
test_vectors/chacha20poly1305.c \
test_vectors/chacha20_xof.c \
test_vectors/blowfish.c \
test_vectors/camellia_cbc.c \
test_vectors/camellia_ctr.c \
@@ -41,6 +42,7 @@ libstrongswan_test_vectors_la_SOURCES = \
test_vectors/sha2.c \
test_vectors/sha2_hmac.c \
test_vectors/sha3.c \
test_vectors/sha3_shake.c \
test_vectors/fips_prf.c \
test_vectors/modp.c \
test_vectors/modpsub.c \
@@ -258,6 +258,21 @@ TEST_VECTOR_PRF(sha512_hmac_p5)
TEST_VECTOR_PRF(sha512_hmac_p6)
TEST_VECTOR_PRF(fips_prf_1)
TEST_VECTOR_XOF(shake_128_0)
TEST_VECTOR_XOF(shake_128_32)
TEST_VECTOR_XOF(shake_128_167)
TEST_VECTOR_XOF(shake_128_168)
TEST_VECTOR_XOF(shake_128_255)
TEST_VECTOR_XOF(shake_256_0)
TEST_VECTOR_XOF(shake_256_64)
TEST_VECTOR_XOF(shake_256_135)
TEST_VECTOR_XOF(shake_256_136)
TEST_VECTOR_XOF(shake_256_255)
TEST_VECTOR_XOF(chacha20_xof_1)
TEST_VECTOR_XOF(chacha20_xof_2)
TEST_VECTOR_XOF(chacha20_xof_3)
TEST_VECTOR_XOF(chacha20_xof_4)
TEST_VECTOR_RNG(rng_monobit_1)
TEST_VECTOR_RNG(rng_monobit_2)
TEST_VECTOR_RNG(rng_monobit_3)
@@ -0,0 +1,81 @@
/*
* Copyright (C) 2016 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 Licenseor (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 usefulbut
* 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 <crypto/crypto_tester.h>
/**
* ChaCha20 Stream Test Vector from RFC 7539, Section 2.3.2
*/
xof_test_vector_t chacha20_xof_1 = {
.alg = XOF_CHACHA20, .len = 44,
.seed = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
"\x00\x00\x00\x09\x00\x00\x00\x4a\x00\x00\x00\x00",
.out_len = 64,
.out = "\x10\xf1\xe7\xe4\xd1\x3b\x59\x15\x50\x0f\xdd\x1f\xa3\x20\x71\xc4"
"\xc7\xd1\xf4\xc7\x33\xc0\x68\x03\x04\x22\xaa\x9a\xc3\xd4\x6c\x4e"
"\xd2\x82\x64\x46\x07\x9f\xaa\x09\x14\xc2\xd7\x05\xd9\x8b\x02\xa2"
"\xb5\x12\x9c\xd1\xde\x16\x4e\xb9\xcb\xd0\x83\xe8\xa2\x50\x3c\x4e"
};
/**
* ChaCha20 Stream Test Vector from RFC 7539, Section 2.4.2
*/
xof_test_vector_t chacha20_xof_2 = {
.alg = XOF_CHACHA20, .len = 44,
.seed = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
"\x00\x00\x00\x00\x00\x00\x00\x4a\x00\x00\x00\x00",
.out_len = 114,
.out = "\x22\x4f\x51\xf3\x40\x1b\xd9\xe1\x2f\xde\x27\x6f\xb8\x63\x1d\xed"
"\x8c\x13\x1f\x82\x3d\x2c\x06\xe2\x7e\x4f\xca\xec\x9e\xf3\xcf\x78"
"\x8a\x3b\x0a\xa3\x72\x60\x0a\x92\xb5\x79\x74\xcd\xed\x2b\x93\x34"
"\x79\x4c\xba\x40\xc6\x3e\x34\xcd\xea\x21\x2c\x4c\xf0\x7d\x41\xb7"
"\x69\xa6\x74\x9f\x3f\x63\x0f\x41\x22\xca\xfe\x28\xec\x4d\xc4\x7e"
"\x26\xd4\x34\x6d\x70\xb9\x8c\x73\xf3\xe9\xc5\x3a\xc4\x0c\x59\x45"
"\x39\x8b\x6e\xda\x1a\x83\x2c\x89\xc1\x67\xea\xcd\x90\x1d\x7e\x2b"
"\xf3\x63"
};
/**
* ChaCha20 Stream Test Vector #2 from RFC 7539, Section A1.
*/
xof_test_vector_t chacha20_xof_3 = {
.alg = XOF_CHACHA20, .len = 44,
.seed = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
.out_len = 64,
.out = "\x9f\x07\xe7\xbe\x55\x51\x38\x7a\x98\xba\x97\x7c\x73\x2d\x08\x0d"
"\xcb\x0f\x29\xa0\x48\xe3\x65\x69\x12\xc6\x53\x3e\x32\xee\x7a\xed"
"\x29\xb7\x21\x76\x9c\xe6\x4e\x43\xd5\x71\x33\xb0\x74\xd8\x39\xd5"
"\x31\xed\x1f\x28\x51\x0a\xfb\x45\xac\xe1\x0a\x1f\x4b\x79\x4d\x6f"
};
/**
* ChaCha20 Stream Test Vector #3 from RFC 7539, Section A1.
*/
xof_test_vector_t chacha20_xof_4 = {
.alg = XOF_CHACHA20, .len = 44,
.seed = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
.out_len = 64,
.out = "\x3a\xeb\x52\x24\xec\xf8\x49\x92\x9b\x9d\x82\x8d\xb1\xce\xd4\xdd"
"\x83\x20\x25\xe8\x01\x8b\x81\x60\xb8\x22\x84\xf3\xc9\x49\xaa\x5a"
"\x8e\xca\x00\xbb\xb4\xa7\x3b\xda\xd1\x92\xb5\xc4\x2f\x73\xf2\xfd"
"\x4e\x27\x36\x44\xc8\xb3\x61\x25\xa6\x4a\xdd\xeb\x00\x6c\x13\xa0"
};
@@ -23,7 +23,6 @@ hasher_test_vector_t sha3_224_0 = {
.data = "",
.hash = "\x6B\x4E\x03\x42\x36\x67\xDB\xB7\x3B\x6E\x15\x45\x4F\x0E\xB1\xAB"
"\xD4\x59\x7F\x9A\x1B\x07\x8E\x3F\x5B\x5A\x6B\xC7"
};
hasher_test_vector_t sha3_224_1 = {
@@ -0,0 +1,472 @@
/*
* Copyright (C) 2016 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 Licenseor (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 usefulbut
* 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 <crypto/crypto_tester.h>
/**
* SHAKE-128 vectors from "https://github.com/gvanas/KeccakCodePackage/"
*/
xof_test_vector_t shake_128_0 = {
.alg = XOF_SHAKE_128, .len = 0,
.seed = "",
.out_len = 512,
.out = "\x7F\x9C\x2B\xA4\xE8\x8F\x82\x7D\x61\x60\x45\x50\x76\x05\x85\x3E"
"\xD7\x3B\x80\x93\xF6\xEF\xBC\x88\xEB\x1A\x6E\xAC\xFA\x66\xEF\x26"
"\x3C\xB1\xEE\xA9\x88\x00\x4B\x93\x10\x3C\xFB\x0A\xEE\xFD\x2A\x68"
"\x6E\x01\xFA\x4A\x58\xE8\xA3\x63\x9C\xA8\xA1\xE3\xF9\xAE\x57\xE2"
"\x35\xB8\xCC\x87\x3C\x23\xDC\x62\xB8\xD2\x60\x16\x9A\xFA\x2F\x75"
"\xAB\x91\x6A\x58\xD9\x74\x91\x88\x35\xD2\x5E\x6A\x43\x50\x85\xB2"
"\xBA\xDF\xD6\xDF\xAA\xC3\x59\xA5\xEF\xBB\x7B\xCC\x4B\x59\xD5\x38"
"\xDF\x9A\x04\x30\x2E\x10\xC8\xBC\x1C\xBF\x1A\x0B\x3A\x51\x20\xEA"
"\x17\xCD\xA7\xCF\xAD\x76\x5F\x56\x23\x47\x4D\x36\x8C\xCC\xA8\xAF"
"\x00\x07\xCD\x9F\x5E\x4C\x84\x9F\x16\x7A\x58\x0B\x14\xAA\xBD\xEF"
"\xAE\xE7\xEE\xF4\x7C\xB0\xFC\xA9\x76\x7B\xE1\xFD\xA6\x94\x19\xDF"
"\xB9\x27\xE9\xDF\x07\x34\x8B\x19\x66\x91\xAB\xAE\xB5\x80\xB3\x2D"
"\xEF\x58\x53\x8B\x8D\x23\xF8\x77\x32\xEA\x63\xB0\x2B\x4F\xA0\xF4"
"\x87\x33\x60\xE2\x84\x19\x28\xCD\x60\xDD\x4C\xEE\x8C\xC0\xD4\xC9"
"\x22\xA9\x61\x88\xD0\x32\x67\x5C\x8A\xC8\x50\x93\x3C\x7A\xFF\x15"
"\x33\xB9\x4C\x83\x4A\xDB\xB6\x9C\x61\x15\xBA\xD4\x69\x2D\x86\x19"
"\xF9\x0B\x0C\xDF\x8A\x7B\x9C\x26\x40\x29\xAC\x18\x5B\x70\xB8\x3F"
"\x28\x01\xF2\xF4\xB3\xF7\x0C\x59\x3E\xA3\xAE\xEB\x61\x3A\x7F\x1B"
"\x1D\xE3\x3F\xD7\x50\x81\xF5\x92\x30\x5F\x2E\x45\x26\xED\xC0\x96"
"\x31\xB1\x09\x58\xF4\x64\xD8\x89\xF3\x1B\xA0\x10\x25\x0F\xDA\x7F"
"\x13\x68\xEC\x29\x67\xFC\x84\xEF\x2A\xE9\xAF\xF2\x68\xE0\xB1\x70"
"\x0A\xFF\xC6\x82\x0B\x52\x3A\x3D\x91\x71\x35\xF2\xDF\xF2\xEE\x06"
"\xBF\xE7\x2B\x31\x24\x72\x1D\x4A\x26\xC0\x4E\x53\xA7\x5E\x30\xE7"
"\x3A\x7A\x9C\x4A\x95\xD9\x1C\x55\xD4\x95\xE9\xF5\x1D\xD0\xB5\xE9"
"\xD8\x3C\x6D\x5E\x8C\xE8\x03\xAA\x62\xB8\xD6\x54\xDB\x53\xD0\x9B"
"\x8D\xCF\xF2\x73\xCD\xFE\xB5\x73\xFA\xD8\xBC\xD4\x55\x78\xBE\xC2"
"\xE7\x70\xD0\x1E\xFD\xE8\x6E\x72\x1A\x3F\x7C\x6C\xCE\x27\x5D\xAB"
"\xE6\xE2\x14\x3F\x1A\xF1\x8D\xA7\xEF\xDD\xC4\xC7\xB7\x0B\x5E\x34"
"\x5D\xB9\x3C\xC9\x36\xBE\xA3\x23\x49\x1C\xCB\x38\xA3\x88\xF5\x46"
"\xA9\xFF\x00\xDD\x4E\x13\x00\xB9\xB2\x15\x3D\x20\x41\xD2\x05\xB4"
"\x43\xE4\x1B\x45\xA6\x53\xF2\xA5\xC4\x49\x2C\x1A\xDD\x54\x45\x12"
"\xDD\xA2\x52\x98\x33\x46\x2B\x71\xA4\x1A\x45\xBE\x97\x29\x0B\x6F"
};
xof_test_vector_t shake_128_32 = {
.alg = XOF_SHAKE_128, .len = 32,
.seed = "\x9F\x2F\xCC\x7C\x90\xDE\x09\x0D\x6B\x87\xCD\x7E\x97\x18\xC1\xEA"
"\x6C\xB2\x11\x18\xFC\x2D\x5D\xE9\xF9\x7E\x5D\xB6\xAC\x1E\x9C\x10",
.out_len = 512,
.out = "\xFC\xDE\xAD\x82\xF3\x9C\xDF\xCE\xF9\x9C\x1B\xAB\xB6\x74\xA9\xA8"
"\xE2\x4A\xC5\x94\x64\x6C\x31\xD0\x20\xA4\xCD\x2B\xC2\x55\x4A\xFD"
"\x78\xC4\xE4\x13\xF7\x80\x4F\xA1\x70\x8B\x9F\x40\x00\xFD\x86\x0E"
"\x30\x70\xF2\xE1\xBA\x9E\xEE\x38\x05\x35\x2A\xAD\x65\x5B\x4B\x0A"
"\x72\x8F\x2D\x5F\xCC\x43\x24\x38\x25\xBC\x0D\xCE\x33\xCA\x71\x66"
"\x26\xDC\x76\xE9\x20\xD7\x25\x75\xE2\x6D\xDD\x71\x10\xD0\xF9\x91"
"\xA9\x12\x00\xB5\x13\xAE\xE2\x3A\xC9\xBC\x70\x43\xA1\x52\xAC\xE0"
"\xCD\x0B\x49\x18\x1D\x2B\xB6\xBD\x36\xE9\x3C\x0B\x62\x7A\xCA\x9C"
"\x6A\xB6\xC8\x5E\xD7\x0C\xE7\x62\x42\x9C\x8F\x26\x27\x08\x10\x32"
"\x84\xC0\xA7\x92\x13\x8F\x10\xE8\x56\x8E\xFB\x23\x99\xB3\x8A\x31"
"\x05\x5C\x11\x88\xBA\x59\x34\x4E\x6A\x2B\x73\xD5\xC0\x4A\xA5\x24"
"\x05\x66\x49\x84\x4D\x1D\xAD\xCD\x07\xD3\x5D\xF5\xD8\x51\xEB\xAF"
"\xFC\xA5\x70\x3B\x80\x15\x3E\xA6\x27\xB1\xBA\xDF\xB2\x88\x5F\x70"
"\xF7\x86\xD3\x4F\x56\x50\xFE\x73\xE3\x69\x0A\x8A\x96\x61\x00\x59"
"\x25\x3D\xD3\xAB\xB5\xFA\x7C\x54\xCF\x6E\x77\x69\x5D\x24\xA6\x59"
"\x40\x77\xEE\x4D\x36\x73\xF9\xFC\x56\xC6\x2F\xC7\xF7\x10\xCF\x87"
"\x20\x14\xC0\xA7\xDE\x8B\x1C\xA6\xAE\x8C\xEF\xAA\xDE\xAF\x5F\x4D"
"\x05\x5F\xF7\x65\xAD\x41\x87\x13\xF2\xDD\x08\xEA\xFB\x5E\x16\xEE"
"\xD9\xFE\x34\x4E\xE8\xD4\x38\x8F\xDC\x22\x35\x1F\x63\x83\x40\x17"
"\xB5\x39\xE3\xFF\x14\x3F\x39\x4B\x5B\x74\xD0\x6F\x65\xE9\x6A\x7A"
"\x3D\x02\x8F\xD1\x4F\x6C\x70\x01\xEB\x7A\xD2\xDC\xFC\xF4\xB2\x44"
"\x7A\xA1\x73\xA2\xAE\x8E\xDB\x58\x1B\x5B\xBD\x89\xE8\xA4\x68\xFE"
"\x0A\x38\x50\x75\x30\xB9\x79\x5D\xA3\xBC\xEC\x6D\xDE\xBC\xE9\xEB"
"\x31\x32\xEF\x18\xC9\xC2\xA8\xB9\x36\xA4\x31\xC8\xB1\x21\xFA\x99"
"\x6F\xF9\xBA\x5C\xE5\x22\x98\x6B\x67\x8A\x5E\xC9\x9A\x10\x3A\x91"
"\xCF\x33\x19\x6E\x08\xC8\x2D\xC6\x5E\x68\xAE\xD2\x38\xA9\x31\x6A"
"\x73\xE7\x1C\xF5\xA6\x7C\xE4\x40\xB9\x3B\xDB\x84\x5B\x3A\x60\x53"
"\x9E\xCC\xDC\xE4\x1B\xC7\x23\xEC\x9A\x14\xEE\x4E\x08\x2F\x60\xC0"
"\xBE\x3D\x5E\x50\xDF\xC8\xBE\x1E\x86\xA9\x7E\xCE\xE9\xD8\x8E\x2B"
"\xB2\xA3\xAF\xF4\x7F\xBD\x6D\x66\x75\xD8\x1E\xFE\x07\x08\x92\x6B"
"\x81\xAB\x31\x4A\x52\x4F\xC7\x45\x09\x01\x62\xD2\xAC\x72\x3C\x43"
"\x26\xE0\xF9\xE1\x6F\xBD\xBA\x2B\x1E\x99\x14\xBB\xEE\xDF\xF9\x6B"
};
xof_test_vector_t shake_128_167 = {
.alg = XOF_SHAKE_128, .len = 167,
.seed = "\x0D\x8D\x09\xAE\xD1\x9F\x10\x13\x96\x9C\xE5\xE7\xEB\x92\xF8\x3A"
"\x20\x9A\xE7\x6B\xE3\x1C\x75\x48\x44\xEA\x91\x16\xCE\xB3\x9A\x22"
"\xEB\xB6\x00\x30\x17\xBB\xCF\x26\x55\x5F\xA6\x62\x41\x85\x18\x7D"
"\xB8\xF0\xCB\x35\x64\xB8\xB1\xC0\x6B\xF6\x85\xD4\x7F\x32\x86\xED"
"\xA2\x0B\x83\x35\x8F\x59\x9D\x20\x44\xBB\xF0\x58\x3F\xAB\x8D\x78"
"\xF8\x54\xFE\x0A\x59\x61\x83\x23\x0C\x5E\xF8\xE5\x44\x26\x75\x0E"
"\xAF\x2C\xC4\xE2\x9D\x3B\xDD\x03\x7E\x73\x4D\x86\x3C\x2B\xD9\x78"
"\x9B\x4C\x24\x30\x96\x13\x8F\x76\x72\xC2\x32\x31\x4E\xFF\xDF\xC6"
"\x51\x34\x27\xE2\xDA\x76\x91\x6B\x52\x48\x93\x3B\xE3\x12\xEB\x5D"
"\xDE\x4C\xF7\x08\x04\xFB\x25\x8A\xC5\xFB\x82\xD5\x8D\x08\x17\x7A"
"\xC6\xF4\x75\x60\x17\xFF\xF5",
.out_len = 512,
.out = "\xC7\x3D\x8F\xAA\xB5\xD0\xB4\xD6\x60\xBD\x50\x82\xE4\x4C\x3C\xAC"
"\x97\xE6\x16\x48\xBE\x0A\x04\xB1\x16\x72\x4E\x6F\x6B\x65\x76\x84"
"\x67\x4B\x4B\x0E\x90\xD0\xAE\x96\xC0\x85\x3E\xBD\x83\x7B\xD8\x24"
"\x9A\xDB\xD3\xB6\x0A\x1A\xD1\xFC\xF8\xA6\xAB\x8E\x2F\x5A\xA7\xFF"
"\x19\x7A\x3D\x7D\xBE\xDE\xFB\x43\x3B\x61\x35\x36\xAE\xC4\xD6\x55"
"\xB7\xBC\xD7\x78\x52\x6B\xE6\x67\x84\x7A\xCD\x2E\x05\x64\xD9\x6C"
"\xE5\x14\x0C\x91\x35\x7F\xAD\xE0\x00\xEF\xCB\x40\x45\x7E\x1B\x6C"
"\xED\x41\xFA\x10\x2E\x36\xE7\x99\x79\x2D\xB0\x3E\x9A\x40\xC7\x99"
"\xBC\xA9\x12\x62\x94\x8E\x17\x60\x50\x65\xFB\xF6\x38\xFB\x40\xA1"
"\x57\xB4\x5C\xF7\x91\x1A\x75\x3D\x0D\x20\x5D\xF8\x47\x16\xA5\x71"
"\x12\xBE\xAB\x44\xF6\x20\x1F\xF7\x5A\xAD\xE0\xBA\xFB\xA5\x04\x74"
"\x5C\xFE\x23\xE4\xE6\x0E\x67\xE3\x99\x36\x22\xAE\xD7\x3A\x1D\xD6"
"\xA4\x65\xBD\x45\x3D\xD3\xC5\xBA\x7D\x2C\xDF\x3F\x1D\x39\x37\x6A"
"\x67\xC2\x3E\x55\x5F\x5A\xCF\x25\xBC\xE1\xE5\x5F\x30\x72\x52\xB9"
"\xAA\xC2\xC0\xA3\x9C\x88\x5C\x7E\x44\xF2\x04\xCB\x82\x1C\x0D\x37"
"\xA2\x2D\xE3\xA7\x1F\x3A\x19\x09\xB1\x1B\x71\x81\xC4\x2B\xE9\xB7"
"\x8A\xA0\xD0\xA1\x54\x44\xF3\x30\x00\x75\x54\xBC\xFC\xC0\xD8\xFD"
"\x87\xD6\x43\x1F\xB9\x3C\x7C\xC3\x87\x67\xA5\x5D\x30\xD3\x54\x55"
"\x60\xBD\x38\x0D\xB8\xC4\xC0\xED\xA9\x39\x9F\x68\xF8\x54\x64\x42"
"\x66\xC1\xB7\x95\x8B\x27\x0E\x75\xB7\x91\x34\xAA\x01\xE7\xDC\xF1"
"\xE6\xFD\xB6\xD9\xAE\x5D\x02\xCC\xE8\xCE\x8E\x48\x04\x75\xE9\x61"
"\x7C\xC4\x2A\x91\xC0\x8D\x9A\xF6\xE5\x10\x1B\x8A\xC5\x83\x4A\xDB"
"\x2C\x66\x98\x7F\x42\xA5\x80\xBB\x50\x3A\x4B\x34\xA9\xF1\x5A\xDC"
"\xD0\xE2\x3D\x0D\x40\x29\x47\x97\x64\x83\x1D\x06\xB5\xCA\xF3\xF1"
"\x4B\x91\x44\x9F\x15\xA2\x91\xF4\xAC\x25\x0B\x27\x0B\x6C\xB3\xC3"
"\x04\x72\x5C\x99\xE3\x26\x45\xE1\xFC\x02\xA0\xCD\xDD\x9E\x71\x79"
"\x11\xF2\x34\x2D\x94\x82\xF8\xE0\x97\x99\x85\xA0\x17\x0D\x72\x5D"
"\xAB\x4E\xA6\x6D\x44\xF6\x26\xBA\x47\x59\x25\xFA\x39\xFC\x9D\xEE"
"\x92\x9C\x06\xD0\x09\x41\x6C\x0A\xDC\x1D\x98\x7C\xD6\x25\xA2\x0A"
"\xCB\xA4\xCC\x87\xF7\x2F\x61\x08\x67\xC3\xA7\xA9\x28\xA3\xA0\x37"
"\x96\x76\xE8\xFE\x25\x71\x07\xAB\x2F\x5C\x03\x0B\xD2\x48\x0E\x3D"
"\x18\x63\x56\x2E\x1F\xD0\x79\x02\x80\x33\x3E\xD9\xD5\xDD\x5A\x5C"
};
xof_test_vector_t shake_128_168 = {
.alg = XOF_SHAKE_128, .len = 168,
.seed = "\xC3\x23\x6B\x73\xDE\xB7\x66\x2B\xF3\xF3\xDA\xA5\x8F\x13\x7B\x35"
"\x8B\xA6\x10\x56\x0E\xF7\x45\x57\x85\xA9\xBE\xFD\xB0\x35\xA0\x66"
"\xE9\x07\x04\xF9\x29\xBD\x96\x89\xCE\xF0\xCE\x3B\xDA\x5A\xCF\x44"
"\x80\xBC\xEB\x8D\x09\xD1\x0B\x09\x8A\xD8\x50\x0D\x9B\x60\x71\xDF"
"\xC3\xA1\x4A\xF6\xC7\x75\x11\xD8\x1E\x3A\xA8\x84\x49\x86\xC3\xBE"
"\xA6\xF4\x69\xF9\xE0\x21\x94\xC9\x28\x68\xCD\x5F\x51\x64\x62\x56"
"\x79\x8F\xF0\x42\x49\x54\xC1\x43\x4B\xDF\xED\x9F\xAC\xB3\x90\xB0"
"\x7D\x34\x2E\x99\x29\x36\xE0\xF8\x8B\xFD\x0E\x88\x4A\x0D\xDB\x67"
"\x9D\x05\x47\xCC\xDE\xC6\x38\x42\x85\xA4\x54\x29\xD1\x15\xAC\x7D"
"\x23\x5A\x71\x72\x42\x02\x1D\x1D\xC3\x56\x41\xF5\xF0\xA4\x8E\x84"
"\x45\xDB\xA5\x8E\x6C\xB2\xC8\xEA",
.out_len = 512,
.out = "\x4A\x05\xF2\xEF\x1A\xAD\x5F\xF4\x30\x64\x29\xEC\x0F\x19\x04\x40"
"\x77\xFB\x64\xBF\xE1\xDC\xC5\x0F\x74\xC3\xF0\x45\xE9\xA9\xC3\xDE"
"\x4A\x3B\x59\x63\xAE\xF7\x71\xB0\x49\x11\x1B\x7B\x46\x40\xE2\x0B"
"\x1B\xA8\x4E\xD7\xAF\xEE\x32\x55\x71\xAC\xF3\x47\xE3\x11\xF3\x3C"
"\x1D\x42\x1F\x21\xD6\x63\x06\x5C\x4D\xAD\xDB\xD1\x78\x5C\x5D\xAC"
"\x0D\x55\x4C\xED\xB1\xA4\x5A\x32\xE2\x81\x45\xE9\x8F\x49\xDE\xE2"
"\x85\xB3\x3D\xE1\x4C\x33\x6D\x10\x95\x0E\xCC\x30\x96\x6B\x79\xE8"
"\x61\x3F\xFE\xBB\x70\x2F\xCC\x00\xA1\xC4\x25\x0D\xD3\x85\xAB\xB5"
"\x37\xA2\x84\xE9\x10\x8D\x16\xB6\xF0\x8F\x4E\x10\x3F\x2C\x5E\x9E"
"\x5C\x87\x9C\xB5\x09\x55\x34\x15\x1E\x3C\x9A\x31\x6D\x06\xDC\xE5"
"\x3B\x7F\x01\xB4\x24\xD3\x75\xB5\x64\xFE\x68\x39\xD1\xD1\xF0\x0A"
"\x2E\x62\x60\x40\x60\xA9\x74\x8B\xCD\xC8\x14\x37\x37\x95\x9F\xAB"
"\xBC\xAE\x18\x51\x21\x3E\x6D\xC2\x8B\xEF\xDA\x48\x14\x9D\xE6\xAA"
"\xF4\xA6\x0D\x46\x15\xBE\xD6\x7D\x11\x79\x6F\x61\x73\xC3\xDC\xF1"
"\x39\x03\x7B\x31\xEE\xC9\xA8\x40\x4D\xF0\x75\x97\xBC\x26\x6D\x3C"
"\x7D\x9E\xB9\xA7\xCA\xBF\x74\x9F\xB4\x4E\x40\xD7\x46\xD0\xE9\xDF"
"\xB5\xC8\xBB\xEB\x25\xE3\xF1\x61\x2D\x03\xD3\xEB\x0C\x15\x4D\xE4"
"\xB2\x70\x8C\x4F\x8A\x89\x76\x2E\x17\x1F\x74\x45\x18\xAE\xC1\x34"
"\xA0\x2E\xEA\xF4\x9D\xB2\xE2\xC6\xC9\x91\x47\x11\x28\x8D\x6B\x0C"
"\xE8\x77\x86\x1D\x9B\x10\xAC\xFC\xC1\x96\x43\x73\x82\x87\xDA\x00"
"\x52\x82\xF3\xFC\x82\xF9\xF5\x0A\xA6\x81\xF2\xF5\x5F\xE1\x80\x9C"
"\x9E\x23\xA3\xA5\x9E\x51\xC2\xE8\x94\xF7\x18\x37\x2F\x9F\xA1\x56"
"\x4B\x47\xAB\x3F\x43\xF0\x74\x7A\x17\x83\x9E\x93\x33\x69\xB6\x77"
"\x80\x53\xE1\x76\x4F\x52\xC5\xF3\x19\xE3\x3C\x8B\x25\x67\x8F\x72"
"\x33\x2E\x33\xCC\xA9\x7C\x68\xF1\x9E\x05\x8E\x70\xC3\x14\x10\xDF"
"\x4D\xE7\xE0\x81\x69\xD6\x09\x6B\x7B\x4E\xA4\x82\x71\xEB\x68\x4F"
"\xEE\x9F\xC8\xB5\x61\xC3\xFE\xE2\xDC\xE8\x3D\x09\x2B\x14\x2B\xEC"
"\x14\x78\xD2\x6B\x48\xC3\xC6\xE5\x97\xA7\xB2\xE4\x40\x27\xE1\xEC"
"\xA2\x31\x78\xD3\xAF\xCC\x67\xBB\x53\x0A\x52\x9C\x7E\x13\x36\xE1"
"\xAD\xAE\x74\xEF\x0B\xE9\xCD\x61\xE9\x1C\x6A\xEA\x57\xF7\xCC\xB2"
"\x3B\x64\xB2\xF8\x48\x61\xCE\x15\x92\x09\xFE\xF7\xA8\x97\xA1\x6A"
"\x87\x1A\xA9\x9E\x63\xA5\x12\x6D\xF2\xB0\x33\x87\xE4\x2C\x3D\x18"
};
xof_test_vector_t shake_128_255 = {
.alg = XOF_SHAKE_128, .len = 255,
.seed = "\x3A\x3A\x81\x9C\x48\xEF\xDE\x2A\xD9\x14\xFB\xF0\x0E\x18\xAB\x6B"
"\xC4\xF1\x45\x13\xAB\x27\xD0\xC1\x78\xA1\x88\xB6\x14\x31\xE7\xF5"
"\x62\x3C\xB6\x6B\x23\x34\x67\x75\xD3\x86\xB5\x0E\x98\x2C\x49\x3A"
"\xDB\xBF\xC5\x4B\x9A\x3C\xD3\x83\x38\x23\x36\xA1\xA0\xB2\x15\x0A"
"\x15\x35\x8F\x33\x6D\x03\xAE\x18\xF6\x66\xC7\x57\x3D\x55\xC4\xFD"
"\x18\x1C\x29\xE6\xCC\xFD\xE6\x3E\xA3\x5F\x0A\xDF\x58\x85\xCF\xC0"
"\xA3\xD8\x4A\x2B\x2E\x4D\xD2\x44\x96\xDB\x78\x9E\x66\x31\x70\xCE"
"\xF7\x47\x98\xAA\x1B\xBC\xD4\x57\x4E\xA0\xBB\xA4\x04\x89\xD7\x64"
"\xB2\xF8\x3A\xAD\xC6\x6B\x14\x8B\x4A\x0C\xD9\x52\x46\xC1\x27\xD5"
"\x87\x1C\x4F\x11\x41\x86\x90\xA5\xDD\xF0\x12\x46\xA0\xC8\x0A\x43"
"\xC7\x00\x88\xB6\x18\x36\x39\xDC\xFD\xA4\x12\x5B\xD1\x13\xA8\xF4"
"\x9E\xE2\x3E\xD3\x06\xFA\xAC\x57\x6C\x3F\xB0\xC1\xE2\x56\x67\x1D"
"\x81\x7F\xC2\x53\x4A\x52\xF5\xB4\x39\xF7\x2E\x42\x4D\xE3\x76\xF4"
"\xC5\x65\xCC\xA8\x23\x07\xDD\x9E\xF7\x6D\xA5\xB7\xC4\xEB\x7E\x08"
"\x51\x72\xE3\x28\x80\x7C\x02\xD0\x11\xFF\xBF\x33\x78\x53\x78\xD7"
"\x9D\xC2\x66\xF6\xA5\xBE\x6B\xB0\xE4\xA9\x2E\xCE\xEB\xAE\xB1",
.out_len = 512,
.out = "\x14\x23\x6E\x75\xB9\x78\x4D\xF4\xF5\x79\x35\xF9\x45\x35\x6C\xBE"
"\x38\x3F\xE5\x13\xED\x30\x28\x6F\x91\x06\x07\x59\xBC\xB0\xEF\x4B"
"\xAA\xC8\x58\xEC\xAE\x7C\x6E\x7E\xDD\x49\x8F\x01\xA0\x82\xB6\x3F"
"\xA5\x7D\x22\x54\x02\x31\xE2\xE2\x5C\x83\xEF\xB3\xB3\xF2\x95\x3A"
"\x5F\x67\x45\x02\xAB\x63\x52\x26\x44\x6B\x84\x93\x76\x43\xDC\xD5"
"\x78\x9E\xE7\x3F\x1D\x73\x4B\xC8\xFE\x5F\x7F\x08\x83\xAB\x10\x96"
"\x1B\x9A\x31\xFF\x60\xDE\xE1\x61\x59\xBC\x69\x82\xEF\xB0\x85\x45"
"\x98\x4B\xF7\x1F\xED\x1C\x4C\xD8\x1C\x09\x14\xB4\xC1\x9F\xCF\xEE"
"\xF5\x4A\xF4\xBB\xE3\x72\xF1\x8C\xFC\xD3\xA1\x86\x57\xF5\xB9\x45"
"\x0F\x99\xA7\x8F\x0F\xA2\xC3\xCD\xCA\x74\x61\xC4\xED\x75\x69\x53"
"\x68\x83\xB6\x6C\xD8\x7E\x9C\x20\x09\x62\x90\x2E\xAA\x16\xA5\x4D"
"\xB6\xA0\xA5\xCC\x26\xD8\x89\x03\x8C\x07\x60\x81\x0B\x5B\xB4\xF3"
"\x3F\x1E\x5D\x63\x9B\x6F\x9B\xC7\xCA\x62\xBA\x6F\x8C\x9F\x8D\xE7"
"\x70\x26\x0A\xFE\x47\xF4\xE0\xF8\x2F\x10\x21\x98\xEB\xA2\x7F\x54"
"\x32\x52\xAC\x8D\xDD\x83\xE1\xB8\xDB\x0A\x91\xAC\x65\x63\x3F\xD1"
"\x2A\x55\x0E\xBE\x96\xF9\x3A\xA6\x70\x4E\xD5\x90\x5C\x23\x4F\xA6"
"\xD9\x20\x39\x10\xCB\xD0\x2D\xE1\x66\xC4\xC3\x34\x8F\xB8\x1E\xF7"
"\xB8\x4A\xE1\x45\x5F\xE3\x18\xB5\xFD\x17\x08\x83\xF4\x9B\xA2\xF2"
"\x42\x89\xC4\x79\xA2\xC7\x53\x14\x06\xBA\x98\x9B\xEA\xEF\x3A\x79"
"\xF6\x59\x02\x86\x42\xE9\xB0\x33\xF7\xDE\xB9\xEC\xEC\x3A\x7A\x9F"
"\x1D\xBD\x24\x51\xFC\xB4\x7C\x81\xE2\x1E\x91\xD2\x0B\x92\x4C\x6B"
"\xD0\x4C\x1F\x0B\x27\x10\xD2\xE5\x70\xCD\x24\xBA\xD5\xB5\xDE\x4E"
"\x49\xAA\x80\xB6\xAD\xD5\x50\x7B\x4D\x2E\x51\x03\x70\xC7\xAF\xA8"
"\x14\xD7\xE1\xA7\xE2\x78\xE5\x3D\x7C\xCF\x49\xA0\xA8\x66\xCA\x3A"
"\x7B\x5B\xB7\x1E\xF3\x42\x5E\x46\x0F\xEE\xB2\x91\x49\xF2\x17\x06"
"\x66\x13\x69\x5F\x85\x50\x6A\x09\x46\xCF\x68\x97\x9F\x04\xAE\x07"
"\x3A\xF8\x02\x89\x76\xBF\x0C\x5B\xDC\x22\x12\xE8\xC3\x64\x58\x3D"
"\xE9\xFB\xD0\x3B\x34\xDD\xEE\x5E\xC4\xCF\xA8\xED\x8C\xE5\x92\x97"
"\x1D\x01\x08\xFA\xF7\x6C\x89\x40\xE2\x5E\x6C\x5F\x86\x55\x84\xC3"
"\x4A\x23\x3C\x14\xF0\x05\x32\x67\x3F\xDB\xE3\x88\xCC\x7E\x98\xA5"
"\xB8\x67\xB1\xC5\x91\x30\x7A\x90\x15\x11\x2B\x56\x7F\xF6\xB4\xF3"
"\x18\x11\x41\x11\xFC\x95\xE5\xBD\x7C\x9C\x60\xB7\x4C\x1F\x87\x25"
};
/**
* SHAKE-256 vectors from "https://github.com/gvanas/KeccakCodePackage/"
*/
xof_test_vector_t shake_256_0 = {
.alg = XOF_SHAKE_256, .len = 0,
.seed = "",
.out_len = 512,
.out = "\x46\xB9\xDD\x2B\x0B\xA8\x8D\x13\x23\x3B\x3F\xEB\x74\x3E\xEB\x24"
"\x3F\xCD\x52\xEA\x62\xB8\x1B\x82\xB5\x0C\x27\x64\x6E\xD5\x76\x2F"
"\xD7\x5D\xC4\xDD\xD8\xC0\xF2\x00\xCB\x05\x01\x9D\x67\xB5\x92\xF6"
"\xFC\x82\x1C\x49\x47\x9A\xB4\x86\x40\x29\x2E\xAC\xB3\xB7\xC4\xBE"
"\x14\x1E\x96\x61\x6F\xB1\x39\x57\x69\x2C\xC7\xED\xD0\xB4\x5A\xE3"
"\xDC\x07\x22\x3C\x8E\x92\x93\x7B\xEF\x84\xBC\x0E\xAB\x86\x28\x53"
"\x34\x9E\xC7\x55\x46\xF5\x8F\xB7\xC2\x77\x5C\x38\x46\x2C\x50\x10"
"\xD8\x46\xC1\x85\xC1\x51\x11\xE5\x95\x52\x2A\x6B\xCD\x16\xCF\x86"
"\xF3\xD1\x22\x10\x9E\x3B\x1F\xDD\x94\x3B\x6A\xEC\x46\x8A\x2D\x62"
"\x1A\x7C\x06\xC6\xA9\x57\xC6\x2B\x54\xDA\xFC\x3B\xE8\x75\x67\xD6"
"\x77\x23\x13\x95\xF6\x14\x72\x93\xB6\x8C\xEA\xB7\xA9\xE0\xC5\x8D"
"\x86\x4E\x8E\xFD\xE4\xE1\xB9\xA4\x6C\xBE\x85\x47\x13\x67\x2F\x5C"
"\xAA\xAE\x31\x4E\xD9\x08\x3D\xAB\x4B\x09\x9F\x8E\x30\x0F\x01\xB8"
"\x65\x0F\x1F\x4B\x1D\x8F\xCF\x3F\x3C\xB5\x3F\xB8\xE9\xEB\x2E\xA2"
"\x03\xBD\xC9\x70\xF5\x0A\xE5\x54\x28\xA9\x1F\x7F\x53\xAC\x26\x6B"
"\x28\x41\x9C\x37\x78\xA1\x5F\xD2\x48\xD3\x39\xED\xE7\x85\xFB\x7F"
"\x5A\x1A\xAA\x96\xD3\x13\xEA\xCC\x89\x09\x36\xC1\x73\xCD\xCD\x0F"
"\xAB\x88\x2C\x45\x75\x5F\xEB\x3A\xED\x96\xD4\x77\xFF\x96\x39\x0B"
"\xF9\xA6\x6D\x13\x68\xB2\x08\xE2\x1F\x7C\x10\xD0\x4A\x3D\xBD\x4E"
"\x36\x06\x33\xE5\xDB\x4B\x60\x26\x01\xC1\x4C\xEA\x73\x7D\xB3\xDC"
"\xF7\x22\x63\x2C\xC7\x78\x51\xCB\xDD\xE2\xAA\xF0\xA3\x3A\x07\xB3"
"\x73\x44\x5D\xF4\x90\xCC\x8F\xC1\xE4\x16\x0F\xF1\x18\x37\x8F\x11"
"\xF0\x47\x7D\xE0\x55\xA8\x1A\x9E\xDA\x57\xA4\xA2\xCF\xB0\xC8\x39"
"\x29\xD3\x10\x91\x2F\x72\x9E\xC6\xCF\xA3\x6C\x6A\xC6\xA7\x58\x37"
"\x14\x30\x45\xD7\x91\xCC\x85\xEF\xF5\xB2\x19\x32\xF2\x38\x61\xBC"
"\xF2\x3A\x52\xB5\xDA\x67\xEA\xF7\xBA\xAE\x0F\x5F\xB1\x36\x9D\xB7"
"\x8F\x3A\xC4\x5F\x8C\x4A\xC5\x67\x1D\x85\x73\x5C\xDD\xDB\x09\xD2"
"\xB1\xE3\x4A\x1F\xC0\x66\xFF\x4A\x16\x2C\xB2\x63\xD6\x54\x12\x74"
"\xAE\x2F\xCC\x86\x5F\x61\x8A\xBE\x27\xC1\x24\xCD\x8B\x07\x4C\xCD"
"\x51\x63\x01\xB9\x18\x75\x82\x4D\x09\x95\x8F\x34\x1E\xF2\x74\xBD"
"\xAB\x0B\xAE\x31\x63\x39\x89\x43\x04\xE3\x58\x77\xB0\xC2\x8A\x9B"
"\x1F\xD1\x66\xC7\x96\xB9\xCC\x25\x8A\x06\x4A\x8F\x57\xE2\x7F\x2A"
};
xof_test_vector_t shake_256_64 = {
.alg = XOF_SHAKE_256, .len = 64,
.seed = "\xE9\x26\xAE\x8B\x0A\xF6\xE5\x31\x76\xDB\xFF\xCC\x2A\x6B\x88\xC6"
"\xBD\x76\x5F\x93\x9D\x3D\x17\x8A\x9B\xDE\x9E\xF3\xAA\x13\x1C\x61"
"\xE3\x1C\x1E\x42\xCD\xFA\xF4\xB4\xDC\xDE\x57\x9A\x37\xE1\x50\xEF"
"\xBE\xF5\x55\x5B\x4C\x1C\xB4\x04\x39\xD8\x35\xA7\x24\xE2\xFA\xE7",
.out_len = 512,
.out = "\x77\xB7\x49\x6E\xD0\x8C\x39\x33\xBD\x75\x98\x3C\x0C\x04\x94\xBD"
"\xD8\x26\x24\x93\xA4\xB5\x5D\xDC\xCC\x64\x16\x7E\x67\xEA\xC0\xF6"
"\xE6\x30\x7A\xCC\x15\xC3\x3F\x39\x63\x74\x4E\x26\xCA\x6C\x50\x4D"
"\x39\x3B\x3E\xE8\x16\x5E\x4D\x49\xEB\x3B\x6E\x64\x92\x07\x65\x30"
"\x48\xF8\xB8\x22\xFF\x88\x4D\xC7\x49\x37\x44\x3B\x1C\x4A\x88\x8C"
"\x7A\x76\x8C\x63\xD5\xB5\xD2\x9E\x74\x46\x87\x39\x23\xB9\xD7\xA5"
"\x6F\xA5\xD9\xE9\x07\x60\xAB\x86\xD5\x71\x8E\x34\x64\x82\x1B\x79"
"\xEB\x46\xD1\x69\x14\x1F\xF1\x61\x20\xBF\xB6\x50\xC7\x6D\x4B\x3E"
"\x5B\x3F\x6C\xE6\x1F\xEB\xDB\xE0\x9A\xED\x7F\x4C\x91\x06\x6D\x90"
"\x3A\xF6\xE5\x65\x31\xE8\xFF\x71\x54\x95\x08\xB6\xE4\x20\xCA\xC6"
"\xBE\xDF\xE0\xCB\xEA\xE6\xBC\x22\x84\x76\xBC\x8C\x00\xEA\xE4\x3D"
"\x40\xC8\x2C\xBD\xF6\xB4\x60\xC3\x76\xD7\xC1\x16\x48\xEB\x28\x15"
"\xB6\x50\x6A\xBD\x43\x39\xB2\x5D\x58\xD4\x5C\xDD\x0A\x0B\x9E\x35"
"\xA8\x8E\x25\x1F\xDC\x34\xD4\x81\x0D\x65\x9D\x17\x9F\x59\xEB\xD0"
"\x37\x17\xFD\x31\xA6\x39\x4C\xE1\x2C\xD5\x56\x90\x66\xE1\x38\x88"
"\x5C\xB2\xBD\xEB\xBA\x06\x36\x75\x57\xCE\x84\x9E\xB8\x69\xF3\xCA"
"\xC3\x88\x00\xD5\x1C\x22\xB6\x66\xAE\x27\x01\xE5\x80\x79\x63\x94"
"\xDF\xA0\x2F\x49\x10\xBF\x5F\x86\xAA\xB5\x39\x51\x23\x33\x64\xEA"
"\x20\xCD\xA3\x5A\xFB\xAB\x44\x5B\xE7\xF6\x86\x64\x38\x56\xF8\x25"
"\x39\x4B\xE7\xB4\xB6\xD2\xC9\x18\xD0\x15\x1F\x46\xFB\x9A\xEE\x8A"
"\x7B\xA2\xD7\x06\xE4\x8C\xB0\xBC\x42\x9B\x06\x42\x62\xC1\xA0\xEB"
"\x35\x24\xFF\x14\x63\x2F\x51\x84\x57\x5C\x15\xF6\xF4\xA3\x44\x6E"
"\x93\xCB\x4E\x86\xB6\xA9\x31\xBA\x26\x84\x09\xCE\x30\xB4\x59\x5F"
"\xD2\x05\x9A\x27\x18\x3B\x3B\xA8\xD0\xAC\xE8\xE4\x82\x86\x6D\x5C"
"\x7D\x5B\x03\xDB\x8D\xBD\x24\xB9\x9D\x59\xEB\x6E\xEF\xFD\x20\x9E"
"\x12\x45\x35\xD1\x54\xB9\x8F\x99\x91\xD8\x4F\xE1\xAA\x76\x3C\x51"
"\x33\xD4\x1E\xCC\x23\x39\x30\x95\x7D\xCE\xB7\x89\x6A\xF7\x0F\x73"
"\x5A\x2F\x5C\x1E\x79\x48\x0A\xFD\x50\x94\x3B\xC5\x01\x4B\xCF\x0A"
"\x73\x54\xAA\x7F\x71\x31\x63\xB5\x5A\x1E\x41\xBD\xD0\x5F\xBB\xA9"
"\xC1\xDB\x2C\x69\x04\x3E\xD9\xEE\xA4\xFA\x45\xC9\x90\xCC\xB4\xA8"
"\xDC\x41\xAF\xAB\x18\x16\x40\x18\xE5\x4C\x47\xAC\x5B\xD6\x98\x0F"
"\xD7\x96\xAC\xF0\xDD\xB4\x2C\x70\x42\xA4\x87\x7E\x8B\xE3\xDE\x29"
};
xof_test_vector_t shake_256_135 = {
.alg = XOF_SHAKE_256, .len = 135,
.seed = "\xB7\x71\xD5\xCE\xF5\xD1\xA4\x1A\x93\xD1\x56\x43\xD7\x18\x1D\x2A"
"\x2E\xF0\xA8\xE8\x4D\x91\x81\x2F\x20\xED\x21\xF1\x47\xBE\xF7\x32"
"\xBF\x3A\x60\xEF\x40\x67\xC3\x73\x4B\x85\xBC\x8C\xD4\x71\x78\x0F"
"\x10\xDC\x9E\x82\x91\xB5\x83\x39\xA6\x77\xB9\x60\x21\x8F\x71\xE7"
"\x93\xF2\x79\x7A\xEA\x34\x94\x06\x51\x28\x29\x06\x5D\x37\xBB\x55"
"\xEA\x79\x6F\xA4\xF5\x6F\xD8\x89\x6B\x49\xB2\xCD\x19\xB4\x32\x15"
"\xAD\x96\x7C\x71\x2B\x24\xE5\x03\x2D\x06\x52\x32\xE0\x2C\x12\x74"
"\x09\xD2\xED\x41\x46\xB9\xD7\x5D\x76\x3D\x52\xDB\x98\xD9\x49\xD3"
"\xB0\xFE\xD6\xA8\x05\x2F\xBB",
.out_len = 512,
.out = "\x6C\x60\x95\x5D\xCB\x8A\x66\x3B\x6D\xC7\xF5\xEF\x7E\x06\x9C\xA8"
"\xFE\x3D\xA9\x9A\x66\xDF\x65\x96\x92\x5D\x55\x7F\xED\x91\xF4\x70"
"\x91\x40\x7D\x6F\xDE\x32\x02\x3B\x57\xE2\xEE\x4C\x6A\xC9\x7B\x07"
"\x76\x24\xFA\xC2\x5F\x6E\x13\xF4\x19\x16\x96\xB4\x0A\x4D\xF7\x5F"
"\x61\xCD\x55\x21\xD9\x82\xC6\xD0\x9D\x83\x42\xC1\x7A\x36\x6E\xC6"
"\x34\x6E\x35\x28\xB2\x6C\xFF\x91\x5B\xE9\x44\x2B\x9E\xBC\xC3\x0F"
"\xF2\xF6\xAD\xD0\xE8\x2B\xA9\x04\xC7\x37\x00\xCC\x99\xAC\xFF\x48"
"\x0C\xAF\x04\x87\xCE\xE5\x4C\xBA\x37\x53\xB6\xA5\xDD\x6F\x0D\xFE"
"\x65\x71\xF0\x11\x5E\x87\x37\xB0\x71\x03\x10\x23\xB6\xBB\x0D\x79"
"\x86\x4C\x3F\x33\x16\x2E\x78\x26\x9C\xEE\x23\xFC\xE4\x7B\x91\xB4"
"\xFD\xF9\x1F\x98\x46\x4A\x1D\x21\xE7\x99\xD1\x7F\x76\xC1\xBB\x80"
"\x7D\xEE\x66\x7B\x0B\x27\x30\x54\xBE\x29\x82\x99\xBD\x12\xB7\xA8"
"\x0F\xB3\x54\xCE\x3E\x6D\x1A\xCF\x98\x44\x38\x79\xA5\x54\xEC\xA6"
"\xB9\x6D\xF0\x61\xD0\x4A\x11\x7C\x98\xAE\xEC\x1C\xDE\x1A\xFA\x9C"
"\xEF\x62\xDD\x68\x6D\xA9\x1B\xB2\xB1\xF1\x23\x79\xBB\xDC\x9F\xA3"
"\x2A\x6B\x69\x98\xB7\x7E\x8E\xB0\xB5\x05\x07\x86\x2A\xFA\x77\x99"
"\xD0\x18\xE2\x72\x09\x1F\x51\xCA\xDD\x81\xAD\xB5\x87\xEF\x67\xBA"
"\x67\x61\x8C\x45\xD1\xF3\xD5\x59\xDB\xD2\x99\xAB\xC2\x6E\xC7\x12"
"\xDA\x8F\xA3\x4B\xA3\x3B\xFF\x40\x0D\x1F\x0F\x8B\x63\x45\xCF\x57"
"\x26\x9B\x85\x85\x78\xC0\x07\x2A\x91\xA6\x3E\xF8\x5F\x9D\x37\x89"
"\x00\xCD\x1A\x55\xD2\xBD\x46\x30\xDB\x82\x9E\xB4\x84\xD8\x9C\xE7"
"\xA4\x14\xAC\xA1\x73\xC5\x25\x34\xAD\x5F\x93\x55\xE8\x0E\x39\x5E"
"\x79\x15\x6D\x75\x1A\x93\x0F\x7F\x8B\x5D\x9F\x4D\x5A\x2C\x9A\x75"
"\x37\x23\x08\x3C\x5E\x8E\xC6\xCB\x24\xD8\xEF\x93\xC8\xFE\xF2\xD1"
"\xBE\x4E\xCA\x22\x2C\x6E\x6C\x2A\xCF\xD6\x84\x89\x3C\xEA\x65\xCB"
"\xF5\xB0\x96\xB3\xD8\x66\x00\x71\x36\x12\x6A\x33\xEF\x49\x6B\xF2"
"\x31\x0F\x29\x3B\xFA\x4C\x93\xAB\x82\x68\x21\xE2\xB9\x32\x59\xC4"
"\x64\xE0\xAE\xB0\x6D\x6D\xF8\xFF\xA3\x0B\x1C\x1E\x7E\x38\x4C\x7E"
"\x42\x7A\x2B\xA3\xD9\x9F\xF8\xA6\x66\x38\x0C\x5C\x1B\x67\x8F\x74"
"\x2C\x57\xB0\xC3\xB0\x88\x49\xFD\x65\x30\x0D\xF1\x34\x99\xDD\x89"
"\x4E\xFC\x33\x11\x6E\x7D\x07\x74\x06\x43\x31\xFD\xD4\x07\x48\x74"
"\x17\xD1\x3B\xBA\x42\x85\x29\x9A\xF6\x50\xD3\x06\x5D\x95\x11\x31"
};
xof_test_vector_t shake_256_136 = {
.alg = XOF_SHAKE_256, .len = 136,
.seed = "\xB3\x2D\x95\xB0\xB9\xAA\xD2\xA8\x81\x6D\xE6\xD0\x6D\x1F\x86\x00"
"\x85\x05\xBD\x8C\x14\x12\x4F\x6E\x9A\x16\x3B\x5A\x2A\xDE\x55\xF8"
"\x35\xD0\xEC\x38\x80\xEF\x50\x70\x0D\x3B\x25\xE4\x2C\xC0\xAF\x05"
"\x0C\xCD\x1B\xE5\xE5\x55\xB2\x30\x87\xE0\x4D\x7B\xF9\x81\x36\x22"
"\x78\x0C\x73\x13\xA1\x95\x4F\x87\x40\xB6\xEE\x2D\x3F\x71\xF7\x68"
"\xDD\x41\x7F\x52\x04\x82\xBD\x3A\x08\xD4\xF2\x22\xB4\xEE\x9D\xBD"
"\x01\x54\x47\xB3\x35\x07\xDD\x50\xF3\xAB\x42\x47\xC5\xDE\x9A\x8A"
"\xBD\x62\xA8\xDE\xCE\xA0\x1E\x3B\x87\xC8\xB9\x27\xF5\xB0\x8B\xEB"
"\x37\x67\x4C\x6F\x8E\x38\x0C\x04",
.out_len = 512,
.out = "\xCC\x2E\xAA\x04\xEE\xF8\x47\x9C\xDA\xE8\x56\x6E\xB8\xFF\xA1\x10"
"\x0A\x40\x79\x95\xBF\x99\x9A\xE9\x7E\xDE\x52\x66\x81\xDC\x34\x90"
"\x61\x6F\x28\x44\x2D\x20\xDA\x92\x12\x4C\xE0\x81\x58\x8B\x81\x49"
"\x1A\xED\xF6\x5C\xAA\xF0\xD2\x7E\x82\xA4\xB0\xE1\xD1\xCA\xB2\x38"
"\x33\x32\x8F\x1B\x8D\xA4\x30\xC8\xA0\x87\x66\xA8\x63\x70\xFA\x84"
"\x8A\x79\xB5\x99\x8D\xB3\xCF\xFD\x05\x7B\x96\xE1\xE2\xEE\x0E\xF2"
"\x29\xEC\xA1\x33\xC1\x55\x48\xF9\x83\x99\x02\x04\x37\x30\xE4\x4B"
"\xC5\x2C\x39\xFA\xDC\x1D\xDE\xEA\xD9\x5F\x99\x39\xF2\x20\xCA\x30"
"\x06\x61\x54\x0D\xF7\xED\xD9\xAF\x37\x8A\x5D\x4A\x19\xB2\xB9\x3E"
"\x6C\x78\xF4\x9C\x35\x33\x43\xA0\xB5\xF1\x19\x13\x2B\x53\x12\xD0"
"\x04\x83\x1D\x01\x76\x9A\x31\x6D\x2F\x51\xBF\x64\xCC\xB2\x0A\x21"
"\xC2\xCF\x7A\xC8\xFB\x6F\x6E\x90\x70\x61\x26\xBD\xAE\x06\x11\xDD"
"\x13\x96\x2E\x8B\x53\xD6\xEA\xE2\x6C\x7B\x0D\x25\x51\xDA\xF6\x24"
"\x8E\x9D\x65\x81\x73\x82\xB0\x4D\x23\x39\x2D\x10\x8E\x4D\x34\x43"
"\xDE\x5A\xDC\x72\x73\xC7\x21\xA8\xF8\x32\x0E\xCF\xE8\x17\x7A\xC0"
"\x67\xCA\x8A\x50\x16\x9A\x6E\x73\x00\x0E\xBC\xDC\x1E\x4E\xE6\x33"
"\x9F\xC8\x67\xC3\xD7\xAE\xAB\x84\x14\x63\x98\xD7\xBA\xDE\x12\x1D"
"\x19\x89\xFA\x45\x73\x35\x56\x4E\x97\x57\x70\xA3\xA0\x02\x59\xCA"
"\x08\x70\x61\x08\x26\x1A\xA2\xD3\x4D\xE0\x0F\x8C\xAC\x7D\x45\xD3"
"\x5E\x5A\xA6\x3E\xA6\x9E\x1D\x1A\x2F\x7D\xAB\x39\x00\xD5\x1E\x0B"
"\xC6\x53\x48\xA2\x55\x54\x00\x70\x39\xA5\x2C\x3C\x30\x99\x80\xD1"
"\x7C\xAD\x20\xF1\x15\x63\x10\xA3\x9C\xD3\x93\x76\x0C\xFE\x58\xF6"
"\xF8\xAD\xE4\x21\x31\x28\x82\x80\xA3\x5E\x1D\xB8\x70\x81\x83\xB9"
"\x1C\xFA\xF5\x82\x7E\x96\xB0\xF7\x74\xC4\x50\x93\xB4\x17\xAF\xF9"
"\xDD\x64\x17\xE5\x99\x64\xA0\x1B\xD2\xA6\x12\xFF\xCF\xBA\x18\xA0"
"\xF1\x93\xDB\x29\x7B\x9A\x6C\xC1\xD2\x70\xD9\x7A\xAE\x8F\x8A\x3A"
"\x6B\x26\x69\x5A\xB6\x64\x31\xC2\x02\xE1\x39\xD6\x3D\xD3\xA2\x47"
"\x78\x67\x6C\xEF\xE3\xE2\x1B\x02\xEC\x4E\x8F\x5C\xFD\x66\x58\x7A"
"\x12\xB4\x40\x78\xFC\xD3\x9E\xEE\x44\xBB\xEF\x4A\x94\x9A\x63\xC0"
"\xDF\xD5\x8C\xF2\xFB\x2C\xD5\xF0\x02\xE2\xB0\x21\x92\x66\xCF\xC0"
"\x31\x81\x74\x86\xDE\x70\xB4\x28\x5A\x8A\x70\xF3\xD3\x8A\x61\xD3"
"\x15\x5D\x99\xAA\xF4\xC2\x53\x90\xD7\x36\x45\xAB\x3E\x8D\x80\xF0"
};
xof_test_vector_t shake_256_255 = {
.alg = XOF_SHAKE_256, .len = 255,
.seed = "\x3A\x3A\x81\x9C\x48\xEF\xDE\x2A\xD9\x14\xFB\xF0\x0E\x18\xAB\x6B"
"\xC4\xF1\x45\x13\xAB\x27\xD0\xC1\x78\xA1\x88\xB6\x14\x31\xE7\xF5"
"\x62\x3C\xB6\x6B\x23\x34\x67\x75\xD3\x86\xB5\x0E\x98\x2C\x49\x3A"
"\xDB\xBF\xC5\x4B\x9A\x3C\xD3\x83\x38\x23\x36\xA1\xA0\xB2\x15\x0A"
"\x15\x35\x8F\x33\x6D\x03\xAE\x18\xF6\x66\xC7\x57\x3D\x55\xC4\xFD"
"\x18\x1C\x29\xE6\xCC\xFD\xE6\x3E\xA3\x5F\x0A\xDF\x58\x85\xCF\xC0"
"\xA3\xD8\x4A\x2B\x2E\x4D\xD2\x44\x96\xDB\x78\x9E\x66\x31\x70\xCE"
"\xF7\x47\x98\xAA\x1B\xBC\xD4\x57\x4E\xA0\xBB\xA4\x04\x89\xD7\x64"
"\xB2\xF8\x3A\xAD\xC6\x6B\x14\x8B\x4A\x0C\xD9\x52\x46\xC1\x27\xD5"
"\x87\x1C\x4F\x11\x41\x86\x90\xA5\xDD\xF0\x12\x46\xA0\xC8\x0A\x43"
"\xC7\x00\x88\xB6\x18\x36\x39\xDC\xFD\xA4\x12\x5B\xD1\x13\xA8\xF4"
"\x9E\xE2\x3E\xD3\x06\xFA\xAC\x57\x6C\x3F\xB0\xC1\xE2\x56\x67\x1D"
"\x81\x7F\xC2\x53\x4A\x52\xF5\xB4\x39\xF7\x2E\x42\x4D\xE3\x76\xF4"
"\xC5\x65\xCC\xA8\x23\x07\xDD\x9E\xF7\x6D\xA5\xB7\xC4\xEB\x7E\x08"
"\x51\x72\xE3\x28\x80\x7C\x02\xD0\x11\xFF\xBF\x33\x78\x53\x78\xD7"
"\x9D\xC2\x66\xF6\xA5\xBE\x6B\xB0\xE4\xA9\x2E\xCE\xEB\xAE\xB1",
.out_len = 512,
.out = "\x8A\x51\x99\xB4\xA7\xE1\x33\xE2\x64\xA8\x62\x02\x72\x06\x55\x89"
"\x4D\x48\xCF\xF3\x44\xA9\x28\xCF\x83\x47\xF4\x83\x79\xCE\xF3\x47"
"\xDF\xC5\xBC\xFF\xAB\x99\xB2\x7B\x1F\x89\xAA\x27\x35\xE2\x3D\x30"
"\x08\x8F\xFA\x03\xB9\xED\xB0\x2B\x96\x35\x47\x0A\xB9\xF1\x03\x89"
"\x85\xD5\x5F\x9C\xA7\x74\x57\x2D\xD0\x06\x47\x0E\xA6\x51\x45\x46"
"\x96\x09\xF9\xFA\x08\x31\xBF\x1F\xFD\x84\x2D\xC2\x4A\xCA\xDE\x27"
"\xBD\x98\x16\xE3\xB5\xBF\x28\x76\xCB\x11\x22\x32\xA0\xEB\x44\x75"
"\xF1\xDF\xF9\xF5\xC7\x13\xD9\xFF\xD4\xCC\xB8\x9A\xE5\x60\x7F\xE3"
"\x57\x31\xDF\x06\x31\x79\x49\xEE\xF6\x46\xE9\x59\x1C\xF3\xBE\x53"
"\xAD\xD6\xB7\xDD\x2B\x60\x96\xE2\xB3\xFB\x06\xE6\x62\xEC\x8B\x2D"
"\x77\x42\x2D\xAA\xD9\x46\x3C\xD1\x55\x20\x4A\xCD\xBD\x38\xE3\x19"
"\x61\x3F\x39\xF9\x9B\x6D\xFB\x35\xCA\x93\x65\x16\x00\x66\xDB\x19"
"\x83\x58\x88\xC2\x24\x1F\xF9\xA7\x31\xA4\xAC\xBB\x56\x63\x72\x7A"
"\xAC\x34\xA4\x01\x24\x7F\xBA\xA7\x49\x9E\x7D\x5E\xE5\xB6\x9D\x31"
"\x02\x5E\x63\xD0\x4C\x35\xC7\x98\xBC\xA1\x26\x2D\x56\x73\xA9\xCF"
"\x09\x30\xB5\xAD\x89\xBD\x48\x55\x99\xDC\x18\x45\x28\xDA\x47\x90"
"\xF0\x88\xEB\xD1\x70\xB6\x35\xD9\x58\x16\x32\xD2\xFF\x90\xDB\x79"
"\x66\x5C\xED\x43\x00\x89\xAF\x13\xC9\xF2\x1F\x6D\x44\x3A\x81\x80"
"\x64\xF1\x7A\xEC\x9E\x9C\x54\x57\x00\x1F\xA8\xDC\x6A\xFB\xAD\xBE"
"\x31\x38\xF3\x88\xD8\x9D\x0E\x6F\x22\xF6\x66\x71\x25\x5B\x21\x07"
"\x54\xED\x63\xD8\x1D\xCE\x75\xCE\x8F\x18\x9B\x53\x4E\x6D\x6B\x35"
"\x39\xAA\x51\xE8\x37\xC4\x2D\xF9\xDF\x59\xC7\x1E\x61\x71\xCD\x49"
"\x02\xFE\x1B\xDC\x73\xFB\x17\x75\xB5\xC7\x54\xA1\xED\x4E\xA7\xF3"
"\x10\x5F\xC5\x43\xEE\x04\x18\xDA\xD2\x56\xF3\xF6\x11\x8E\xA7\x71"
"\x14\xA1\x6C\x15\x35\x5B\x42\x87\x7A\x1D\xB2\xA7\xDF\x0E\x15\x5A"
"\xE1\xD8\x67\x0A\xBC\xEC\x34\x50\xF4\xE2\xEE\xC9\x83\x8F\x89\x54"
"\x23\xEF\x63\xD2\x61\x13\x8B\xAA\xF5\xD9\xF1\x04\xCB\x5A\x95\x7A"
"\xEA\x06\xC0\xB9\xB8\xC7\x8B\x0D\x44\x17\x96\xDC\x03\x50\xDD\xEA"
"\xBB\x78\xA3\x3B\x6F\x1F\x9E\x68\xED\xE3\xD1\x80\x5C\x7B\x7E\x2C"
"\xFD\x54\xE0\xFA\xD6\x2F\x0D\x8C\xA6\x7A\x77\x5D\xC4\x54\x6A\xF9"
"\x09\x6F\x2E\xDB\x22\x1D\xB4\x28\x43\xD6\x53\x27\x86\x12\x82\xDC"
"\x94\x6A\x0B\xA0\x1A\x11\x86\x3A\xB2\xD1\xDF\xD1\x6E\x39\x73\xD4"
};
@@ -24,6 +24,7 @@
#define TEST_VECTOR_SIGNER(x) extern signer_test_vector_t x;
#define TEST_VECTOR_HASHER(x) extern hasher_test_vector_t x;
#define TEST_VECTOR_PRF(x) extern prf_test_vector_t x;
#define TEST_VECTOR_XOF(x) extern xof_test_vector_t x;
#define TEST_VECTOR_RNG(x) extern rng_test_vector_t x;
#define TEST_VECTOR_DH(x) extern dh_test_vector_t x;
@@ -34,6 +35,7 @@
#undef TEST_VECTOR_SIGNER
#undef TEST_VECTOR_HASHER
#undef TEST_VECTOR_PRF
#undef TEST_VECTOR_XOF
#undef TEST_VECTOR_RNG
#undef TEST_VECTOR_DH
@@ -42,6 +44,7 @@
#define TEST_VECTOR_SIGNER(x)
#define TEST_VECTOR_HASHER(x)
#define TEST_VECTOR_PRF(x)
#define TEST_VECTOR_XOF(x)
#define TEST_VECTOR_RNG(x)
#define TEST_VECTOR_DH(x)
@@ -86,6 +89,14 @@ static prf_test_vector_t *prf[] = {
#undef TEST_VECTOR_PRF
#define TEST_VECTOR_PRF(x)
#undef TEST_VECTOR_XOF
#define TEST_VECTOR_XOF(x) &x,
static xof_test_vector_t *xof[] = {
#include "test_vectors.h"
};
#undef TEST_VECTOR_XOF
#define TEST_VECTOR_XOF(x)
#undef TEST_VECTOR_RNG
#define TEST_VECTOR_RNG(x) &x,
static rng_test_vector_t *rng[] = {
@@ -181,6 +192,11 @@ plugin_t *test_vectors_plugin_create()
lib->crypto->add_test_vector(lib->crypto,
PSEUDO_RANDOM_FUNCTION, prf[i]);
}
for (i = 0; i < countof(xof); i++)
{
lib->crypto->add_test_vector(lib->crypto,
EXTENDED_OUTPUT_FUNCTION, xof[i]);
}
for (i = 0; i < countof(rng); i++)
{
lib->crypto->add_test_vector(lib->crypto,
+42
View File
@@ -44,6 +44,21 @@
#define BITFIELD5(t, a, b, c, d, e,...) struct { t e; t d; t c; t b; t a; __VA_ARGS__}
#endif
#ifndef le16toh
# if BYTE_ORDER == BIG_ENDIAN
# define le16toh(x) __builtin_bswap16(x)
# else
# define le16toh(x) (x)
# endif
#endif
#ifndef htole16
# if BYTE_ORDER == BIG_ENDIAN
# define htole16(x) __builtin_bswap16(x)
# else
# define htole16(x) (x)
# endif
#endif
#ifndef le32toh
# if BYTE_ORDER == BIG_ENDIAN
# define le32toh(x) __builtin_bswap32(x)
@@ -176,6 +191,33 @@ static inline uint64_t untoh64(void *network)
return be64toh(tmp);
}
/**
* Read a 16-bit value in little-endian order from unaligned address.
*
* @param p unaligned address to read little endian value from
* @return host order value
*/
static inline uint16_t uletoh16(void *p)
{
uint16_t ret;
memcpy(&ret, p, sizeof(ret));
ret = le16toh(ret);
return ret;
}
/**
* Write a 16-bit value in little-endian to an unaligned address.
*
* @param p host order 16-bit value
* @param v unaligned address to write little endian value to
*/
static inline void htoule16(void *p, uint16_t v)
{
v = htole16(v);
memcpy(p, &v, sizeof(v));
}
/**
* Read a 32-bit value in little-endian order from unaligned address.
*
+2 -1
View File
@@ -99,7 +99,8 @@ CONFIG_OPTS = \
--enable-ntru \
--enable-lookip \
--enable-bliss \
--enable-sha3
--enable-sha3 \
--enable-newhope
export ADA_PROJECT_PATH=/usr/local/ada/lib/gnat
@@ -1,7 +1,7 @@
# /etc/strongswan.conf - strongSwan configuration file
charon {
load = test-vectors aes des sha1 sha2 sha3 md5 pem pkcs1 pkcs8 gmp random nonce x509 curl revocation hmac xcbc cmac ctr ccm gcm stroke kernel-netlink socket-default updown
load = random nonce test-vectors aes des sha1 sha2 sha3 md5 chapoly ntru newhope pem pkcs1 pkcs8 gmp x509 curl revocation hmac xcbc cmac ctr ccm gcm stroke kernel-netlink socket-default updown
integrity_test = yes
crypto_test {
@@ -1,7 +1,7 @@
# /etc/strongswan.conf - strongSwan configuration file
charon {
load = test-vectors aes des sha1 sha2 sha3 md5 pem pkcs1 pkcs8 gmp random nonce x509 curl revocation hmac xcbc cmac ctr ccm gcm stroke kernel-netlink socket-default updown
load = random nonce test-vectors aes des sha1 sha2 sha3 md5 chapoly ntru newhope pem pkcs1 pkcs8 gmp x509 curl revocation hmac xcbc cmac ctr ccm gcm stroke kernel-netlink socket-default updown
integrity_test = yes
crypto_test {
@@ -1,7 +1,7 @@
# /etc/strongswan.conf - strongSwan configuration file
charon {
load = test-vectors aes des sha1 sha2 sha3 md5 pem pkcs1 pkcs8 gmp random nonce x509 curl revocation hmac xcbc cmac ctr ccm gcm stroke kernel-netlink socket-default updown
load = random nonce test-vectors aes des sha1 sha2 sha3 md5 chapoly ntru newhope pem pkcs1 pkcs8 gmp x509 curl revocation hmac xcbc cmac ctr ccm gcm stroke kernel-netlink socket-default updown
integrity_test = yes
crypto_test {
@@ -0,0 +1,15 @@
The roadwarriors <b>carol</b> and <b>dave</b> set up a connection each to gateway <b>moon</b>.
The IKEv2 key exchange is based on the NewHope lattice-based post-quantum algorithm
with a cryptographical strength of 128 bits. Authentication is based on the BLISS
algorithm with strengths 128 bits (BLISS I), 160 bits (BLISS III) and 192 bits (BLISS IV) for
<b>carol</b>, <b>dave</b> and <b>moon</b>, respectively.
<p>
Both <b>carol</b> and <b>dave</b> request a <b>virtual IP</b> via the IKEv2 configuration payload
by using the <b>leftsourceip=%config</b> parameter. The gateway <b>moon</b> assigns virtual
IP addresses from a simple pool defined by <b>rightsourceip=10.3.0.0/28</b> in a monotonously
increasing order.
<p>
<b>leftfirewall=yes</b> automatically inserts iptables-based firewall rules that let pass
the tunneled traffic. In order to test the tunnels, <b>carol</b> and <b>dave</b> then ping
the client <b>alice</b> behind the gateway <b>moon</b>. The source IP addresses of the two
pings will be the virtual IPs <b>carol1</b> and <b>dave1</b>, respectively.
@@ -0,0 +1,26 @@
carol::cat /var/log/daemon.log::authentication of.*moon.strongswan.org.*with BLISS_WITH_SHA2_512 successful::YES
carol::ipsec statusall 2> /dev/null::home.*IKE proposal: AES_CBC_256/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/NEWHOPE_128::YES
carol::ipsec status 2> /dev/null::home.*ESTABLISHED.*[email protected].*moon.strongswan.org::YES
carol::ipsec status 2> /dev/null::home.*INSTALLED, TUNNEL::YES
carol::ping -c 1 PH_IP_ALICE::64 bytes from PH_IP_ALICE: icmp_.eq=1::YES
dave::cat /var/log/daemon.log::authentication of.*moon.strongswan.org.*with BLISS_WITH_SHA2_512 successful::YES
dave:: ipsec statusall 2> /dev/null::home.*IKE proposal: AES_CBC_256/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/NEWHOPE_128::YES
dave:: ipsec status 2> /dev/null::home.*ESTABLISHED.*[email protected].*moon.strongswan.org::YES
dave:: ipsec status 2> /dev/null::home.*INSTALLED, TUNNEL::YES
dave:: ping -c 1 PH_IP_ALICE::64 bytes from PH_IP_ALICE: icmp_.eq=1::YES
moon:: cat /var/log/daemon.log::authentication of.*[email protected].*with BLISS_WITH_SHA2_256 successful::YES
moon:: cat /var/log/daemon.log::authentication of.*[email protected].*with BLISS_WITH_SHA2_384 successful::YES
moon:: ipsec statusall 2> /dev/null::rw\[1]: IKE proposal: AES_CBC_256/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/NEWHOPE_128::YES
moon:: ipsec statusall 2> /dev/null::rw\[2]: IKE proposal: AES_CBC_256/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/NEWHOPE_128::YES
moon:: ipsec status 2> /dev/null::rw\[1]: ESTABLISHED.*moon.strongswan.org.*[email protected]::YES
moon:: ipsec status 2> /dev/null::rw\[2]: ESTABLISHED.*moon.strongswan.org.*[email protected]::YES
moon:: ipsec status 2> /dev/null::rw[{]1}.*INSTALLED, TUNNEL::ESP
moon:: ipsec status 2> /dev/null::rw[{]2}.*INSTALLED, TUNNEL::ESP
moon::tcpdump::IP carol.strongswan.org > moon.strongswan.org: ESP::YES
moon::tcpdump::IP moon.strongswan.org > carol.strongswan.org: ESP::YES
moon::tcpdump::IP dave.strongswan.org > moon.strongswan.org: ESP::YES
moon::tcpdump::IP moon.strongswan.org > dave.strongswan.org: ESP::YES
alice::tcpdump::IP carol1.strongswan.org > alice.strongswan.org: ICMP echo request::YES
alice::tcpdump::IP alice.strongswan.org > carol1.strongswan.org: ICMP echo reply::YES
alice::tcpdump::IP dave1.strongswan.org > alice.strongswan.org: ICMP echo request::YES
alice::tcpdump::IP alice.strongswan.org > dave1.strongswan.org: ICMP echo reply::YES
@@ -0,0 +1,26 @@
# /etc/ipsec.conf - strongSwan IPsec configuration file
config setup
strictcrlpolicy=yes
conn %default
ikelifetime=60m
keylife=20m
rekeymargin=3m
keyingtries=1
keyexchange=ikev2
ike=aes256-sha256-newhope128!
esp=aes256-sha256!
authby=pubkey
fragmentation=yes
conn home
left=PH_IP_CAROL
leftsourceip=%config
leftcert=carolCert.der
[email protected]
leftfirewall=yes
right=PH_IP_MOON
rightsubnet=10.1.0.0/16
rightid=moon.strongswan.org
auto=add

Some files were not shown because too many files have changed in this diff Show More