mirror of
https://github.com/strongswan/strongswan.git
synced 2025-10-05 00:00:45 -04:00
Added DRBG automatic reseeding tests
This commit is contained in:
parent
5443762491
commit
7d5b9e81a4
@ -867,6 +867,10 @@ Enable logging of SQL IP pool leases
|
||||
.BR libstrongswan.plugins.gcrypt.quick_random " [no]"
|
||||
Use faster random numbers in gcrypt; for testing only, produces weak keys!
|
||||
.TP
|
||||
.BR libstrongswan.plugins.ntru.max_drbg_requests " [4294967294]"
|
||||
Number of pseudo-random bit requests from the DRBG before an automatic
|
||||
reseeding occurs.
|
||||
.TP
|
||||
.BR libstrongswan.plugins.ntru.parameter_set " [optimum]"
|
||||
The following parameter sets are available: 'x9_98_speed', 'x9_98_bandwidth',
|
||||
'x9_98_balance' and 'optimum', the last set not being part of the X9.98
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include <utils/debug.h>
|
||||
|
||||
#define MAX_STRENGTH_BITS 256
|
||||
#define MAX_DRBG_REQUESTS 0xffffffff
|
||||
#define MAX_DRBG_REQUESTS 0xfffffffe
|
||||
|
||||
typedef struct private_ntru_drbg_t private_ntru_drbg_t;
|
||||
|
||||
@ -149,7 +149,7 @@ METHOD(ntru_drbg_t, generate, bool,
|
||||
}
|
||||
output = chunk_create(out, len);
|
||||
|
||||
if (this->reseed_counter >= this->max_requests)
|
||||
if (this->reseed_counter > this->max_requests)
|
||||
{
|
||||
if (!reseed(this))
|
||||
{
|
||||
|
@ -100,20 +100,18 @@ START_TEST(test_ntru_drbg_strength)
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_ntru_drbg)
|
||||
{
|
||||
typedef struct {
|
||||
typedef struct {
|
||||
chunk_t pers_str;
|
||||
chunk_t entropy;
|
||||
chunk_t out;
|
||||
} drbg_test_t;
|
||||
} drbg_test_t;
|
||||
|
||||
/**
|
||||
/**
|
||||
* NIST SP 800-90A Deterministic Random Generator Validation System (DRBGVS)
|
||||
*/
|
||||
drbg_test_t drbg_tests[] = {
|
||||
drbg_test_t drbg_tests[] = {
|
||||
/* SHA-256 test case 1 - count 0 */
|
||||
{ chunk_empty,
|
||||
{ { NULL, 0 },
|
||||
chunk_from_chars(0x06, 0x03, 0x2c, 0xd5, 0xee, 0xd3, 0x3f, 0x39,
|
||||
0x26, 0x5f, 0x49, 0xec, 0xb1, 0x42, 0xc5, 0x11,
|
||||
0xda, 0x9a, 0xff, 0x2a, 0xf7, 0x12, 0x03, 0xbf,
|
||||
@ -174,7 +172,7 @@ START_TEST(test_ntru_drbg)
|
||||
0xb4, 0x88, 0x67, 0x64, 0x07, 0x2d, 0x9c, 0xbe)
|
||||
},
|
||||
/* SHA-256 test case 5 - count 0 */
|
||||
{ chunk_empty,
|
||||
{ { NULL, 0 },
|
||||
chunk_from_chars(0xff, 0x0c, 0xdd, 0x55, 0x5c, 0x60, 0x46, 0x47,
|
||||
0x60, 0xb2, 0x89, 0xb7, 0xbc, 0x1f, 0x81, 0x1a,
|
||||
0x41, 0xff, 0xf7, 0x2d, 0xe5, 0x90, 0x83, 0x85,
|
||||
@ -234,30 +232,78 @@ START_TEST(test_ntru_drbg)
|
||||
0x22, 0x86, 0xbc, 0x46, 0x25, 0x82, 0xad, 0x0a,
|
||||
0xf7, 0x8a, 0xb3, 0xb8, 0x5e, 0xc1, 0x7a, 0x25)
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
START_TEST(test_ntru_drbg)
|
||||
{
|
||||
ntru_drbg_t *drbg;
|
||||
rng_t *entropy;
|
||||
chunk_t out;
|
||||
int i;
|
||||
|
||||
out = chunk_alloc(128);
|
||||
for (i = 0; i < countof(drbg_tests); i++)
|
||||
{
|
||||
entropy = ntru_test_rng_create(drbg_tests[i].entropy);
|
||||
drbg = ntru_drbg_create(256, drbg_tests[i].pers_str, entropy);
|
||||
entropy = ntru_test_rng_create(drbg_tests[_i].entropy);
|
||||
drbg = ntru_drbg_create(256, drbg_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, drbg_tests[i].out));
|
||||
ck_assert(chunk_equals(out, drbg_tests[_i].out));
|
||||
drbg->destroy(drbg);
|
||||
entropy->destroy(entropy);
|
||||
}
|
||||
chunk_free(&out);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_ntru_drbg_reseed)
|
||||
{
|
||||
ntru_drbg_t *drbg;
|
||||
rng_t *entropy;
|
||||
chunk_t out;
|
||||
|
||||
lib->settings->set_int(lib->settings,
|
||||
"libstrongswan.plugins.ntru.max_drbg_requests", 2);
|
||||
out = chunk_alloc(128);
|
||||
entropy = ntru_test_rng_create(drbg_tests[0].entropy);
|
||||
drbg = ntru_drbg_create(256, chunk_empty, entropy);
|
||||
|
||||
/* bad output parameters */
|
||||
ck_assert(!drbg->generate(drbg, 256, 0, out.ptr));
|
||||
ck_assert(!drbg->generate(drbg, 256, 128, NULL));
|
||||
|
||||
/* no reseeding occurs */
|
||||
ck_assert(drbg->generate(drbg, 256, 128, out.ptr));
|
||||
ck_assert(drbg->generate(drbg, 256, 128, out.ptr));
|
||||
|
||||
/* consuming remaining entropy */
|
||||
ck_assert(entropy->get_bytes(entropy, 32, out.ptr));
|
||||
|
||||
/* no entropy available for automatic reseeding */
|
||||
ck_assert(!drbg->generate(drbg, 256, 128, out.ptr));
|
||||
drbg->destroy(drbg);
|
||||
|
||||
/* no entropy available for DRBG instantiation */
|
||||
drbg = ntru_drbg_create(256, chunk_empty, entropy);
|
||||
ck_assert(drbg == NULL);
|
||||
entropy->destroy(entropy);
|
||||
|
||||
/* one automatic reseeding occurs */
|
||||
entropy = ntru_test_rng_create(drbg_tests[0].entropy);
|
||||
drbg = ntru_drbg_create(256, chunk_empty, entropy);
|
||||
ck_assert(drbg->generate(drbg, 256, 128, out.ptr));
|
||||
ck_assert(drbg->generate(drbg, 256, 128, out.ptr));
|
||||
ck_assert(drbg->generate(drbg, 256, 128, out.ptr));
|
||||
|
||||
/* no entropy left */
|
||||
ck_assert(!entropy->get_bytes(entropy, 32, out.ptr));
|
||||
|
||||
drbg->destroy(drbg);
|
||||
entropy->destroy(entropy);
|
||||
chunk_free(&out);
|
||||
lib->settings->set_int(lib->settings,
|
||||
"libstrongswan.plugins.ntru.max_drbg_requests", 2000);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_ntru_ke)
|
||||
{
|
||||
chunk_t pub_key, cipher_text, i_shared_secret, r_shared_secret;
|
||||
@ -333,10 +379,8 @@ START_TEST(test_ntru_retransmission)
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_ntru_pubkey_oid)
|
||||
{
|
||||
chunk_t test[] = {
|
||||
chunk_empty,
|
||||
chunk_t oid_tests[] = {
|
||||
{ NULL, 0 },
|
||||
chunk_from_chars(0x00),
|
||||
chunk_from_chars(0x01),
|
||||
chunk_from_chars(0x02),
|
||||
@ -344,20 +388,18 @@ START_TEST(test_ntru_pubkey_oid)
|
||||
chunk_from_chars(0x01, 0x04, 0x00, 0x03, 0x10),
|
||||
chunk_from_chars(0x01, 0x03, 0x00, 0x03, 0x10),
|
||||
chunk_from_chars(0x01, 0x03, 0xff, 0x03, 0x10),
|
||||
};
|
||||
};
|
||||
|
||||
START_TEST(test_ntru_pubkey_oid)
|
||||
{
|
||||
diffie_hellman_t *r_ntru;
|
||||
chunk_t cipher_text;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < countof(test); i++)
|
||||
{
|
||||
r_ntru = lib->crypto->create_dh(lib->crypto, NTRU_128_BIT);
|
||||
r_ntru->set_other_public_value(r_ntru, test[i]);
|
||||
r_ntru->set_other_public_value(r_ntru, oid_tests[_i]);
|
||||
r_ntru->get_my_public_value(r_ntru, &cipher_text);
|
||||
ck_assert(cipher_text.len == 0);
|
||||
r_ntru->destroy(r_ntru);
|
||||
}
|
||||
}
|
||||
END_TEST
|
||||
|
||||
@ -461,7 +503,11 @@ Suite *ntru_suite_create()
|
||||
suite_add_tcase(s, tc);
|
||||
|
||||
tc = tcase_create("drbg");
|
||||
tcase_add_test(tc, test_ntru_drbg);
|
||||
tcase_add_loop_test(tc, test_ntru_drbg, 0, countof(drbg_tests));
|
||||
suite_add_tcase(s, tc);
|
||||
|
||||
tc = tcase_create("drgb_reseed");
|
||||
tcase_add_test(tc, test_ntru_drbg_reseed);
|
||||
suite_add_tcase(s, tc);
|
||||
|
||||
tc = tcase_create("ke");
|
||||
@ -473,7 +519,7 @@ Suite *ntru_suite_create()
|
||||
suite_add_tcase(s, tc);
|
||||
|
||||
tc = tcase_create("pubkey_oid");
|
||||
tcase_add_test(tc, test_ntru_pubkey_oid);
|
||||
tcase_add_loop_test(tc, test_ntru_pubkey_oid, 0, countof(oid_tests));
|
||||
suite_add_tcase(s, tc);
|
||||
|
||||
tc = tcase_create("wrong_set");
|
||||
|
Loading…
x
Reference in New Issue
Block a user