Implemented NIST SP 800-90A DRBG_HMAC with SHA-256

This commit is contained in:
Andreas Steffen
2013-11-27 20:21:41 +01:00
parent 798a36dc14
commit 98c6421674
16 changed files with 697 additions and 1541 deletions
+146 -7
View File
@@ -15,7 +15,8 @@
#include "test_suite.h"
#include <plugins/ntru/ntru_plugin.h>
#include <plugins/ntru/ntru_drbg.h>
#include <plugins/ntru/ntru_test_rng.h>
/**
* NTRU parameter sets to test
@@ -37,11 +38,145 @@ char *parameter_sets[] = {
"x9_98_speed", "x9_98_bandwidth", "x9_98_balance", "optimum"
};
START_TEST(test_ntru_entropy)
typedef struct {
u_int32_t requested;
u_int32_t standard;
}strength_t;
strength_t strengths[] = {
{ 80, 112 },
{ 112, 112 },
{ 120, 128 },
{ 128, 128 },
{ 150, 192 },
{ 192, 192 },
{ 200, 256 },
{ 256, 256 },
{ 512, 0 }
};
START_TEST(test_ntru_drbg_strength)
{
ck_assert(!ntru_plugin_get_entropy(GET_NUM_BYTES_PER_BYTE_OF_ENTROPY, NULL));
ck_assert(!ntru_plugin_get_entropy(GET_BYTE_OF_ENTROPY, NULL));
ck_assert(!ntru_plugin_get_entropy(10, NULL));
ntru_drbg_t *drbg;
rng_t *entropy;
entropy = lib->crypto->create_rng(lib->crypto, RNG_STRONG);
ck_assert(entropy != NULL);
drbg = ntru_drbg_create(strengths[_i].requested, chunk_empty, entropy);
if (strengths[_i].standard)
{
ck_assert(drbg != NULL);
ck_assert(drbg->get_strength(drbg) == strengths[_i].standard);
drbg->destroy(drbg);
}
else
{
ck_assert(drbg == NULL);
}
entropy->destroy(entropy);
}
END_TEST
START_TEST(test_ntru_dbrg)
{
typedef struct {
chunk_t pers_str;
chunk_t entropy;
chunk_t out;
} dbrg_test_t;
dbrg_test_t dbrg_tests[] = {
{ chunk_empty,
chunk_from_chars(0x06, 0x03, 0x2c, 0xd5, 0xee, 0xd3, 0x3f, 0x39,
0x26, 0x5f, 0x49, 0xec, 0xb1, 0x42, 0xc5, 0x11,
0xda, 0x9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0x40,
0xce, 0x9b, 0xd6, 0xa7, 0x0e, 0x7b, 0x8f, 0x93,
0x99, 0x2a, 0x16, 0xa7, 0x6f, 0xab, 0x6b, 0x5f,
0x16, 0x25, 0x68, 0xe0, 0x8e, 0xe6, 0xc3, 0xe8,
0x04, 0xae, 0xfd, 0x95, 0x2d, 0xdd, 0x3a, 0xcb,
0x79, 0x1c, 0x50, 0xf2, 0xad, 0x69, 0xe9, 0xa0,
0x40, 0x28, 0xa0, 0x6a, 0x9c, 0x01, 0xd3, 0xa6,
0x2a, 0xca, 0x2a, 0xaf, 0x6e, 0xfe, 0x69, 0xed,
0x97, 0xa0, 0x16, 0x21, 0x3a, 0x2d, 0xd6, 0x42,
0xb4, 0x88, 0x67, 0x64, 0x07, 0x2d, 0x9c, 0xbe)
}
};
ntru_drbg_t *drbg;
rng_t *entropy;
chunk_t in, out;
int i;
/* test ntru_test_rng */
in = chunk_from_chars(0x01, 0x02, 0x04, 0x04);
entropy = ntru_test_rng_create(in);
ck_assert(entropy->allocate_bytes(entropy, 4, &out));
ck_assert(chunk_equals(in, out));
chunk_free(&out);
ck_assert(!entropy->allocate_bytes(entropy, 4, &out));
entropy->destroy(entropy);
/* test DRBG with ntru_test_rng providing NIST test vectors */
out = chunk_alloc(128);
for (i = 0; i < countof(dbrg_tests); i++)
{
entropy = ntru_test_rng_create(dbrg_tests[i].entropy);
drbg = ntru_drbg_create(256, dbrg_tests[i].pers_str, entropy);
ck_assert(drbg != NULL);
ck_assert(drbg->reseed(drbg));
ck_assert(drbg->generate(drbg, 256, 128, out.ptr));
ck_assert(drbg->generate(drbg, 256, 128, out.ptr));
ck_assert(chunk_equals(out, dbrg_tests[i].out));
drbg->destroy(drbg);
entropy->destroy(entropy);
}
chunk_free(&out);
}
END_TEST
@@ -239,8 +374,12 @@ Suite *ntru_suite_create()
s = suite_create("ntru");
tc = tcase_create("entropy");
tcase_add_test(tc, test_ntru_entropy);
tc = tcase_create("dbrg_strength");
tcase_add_loop_test(tc, test_ntru_drbg_strength, 0, countof(strengths));
suite_add_tcase(s, tc);
tc = tcase_create("dbrg");
tcase_add_test(tc, test_ntru_dbrg);
suite_add_tcase(s, tc);
tc = tcase_create("ke");
+1 -1
View File
@@ -34,5 +34,5 @@ TEST_SUITE(host_suite_create)
TEST_SUITE(printf_suite_create)
TEST_SUITE(pen_suite_create)
TEST_SUITE(asn1_suite_create)
TEST_SUITE_DEPEND(ntru_suite_create, CUSTOM, "ntru-rng")
TEST_SUITE_DEPEND(ntru_suite_create, DH, NTRU_112_BIT)