Extended NIST SP 800-90A HMAC_DRBG test cases

This commit is contained in:
Andreas Steffen 2013-11-24 11:49:41 +01:00
parent a7047cda59
commit d993a567b7
1 changed files with 103 additions and 21 deletions

View File

@ -38,6 +38,28 @@ char *parameter_sets[] = {
"x9_98_speed", "x9_98_bandwidth", "x9_98_balance", "optimum"
};
START_TEST(test_ntru_test_rng)
{
rng_t *entropy;
chunk_t in, in1, in2, out;
in1 = chunk_from_chars(0x01, 0x02, 0x03, 0x04, 0x05, 0x06);
in2 = chunk_from_chars(0x07, 0x08);
in = chunk_cat("cc", in1, in2);
entropy = ntru_test_rng_create(in);
ck_assert(entropy->allocate_bytes(entropy, 6, &out));
ck_assert(chunk_equals(in1, out));
ck_assert(entropy->get_bytes(entropy, 2, out.ptr));
ck_assert(memeq(in2.ptr, out.ptr, in2.len));
ck_assert(!entropy->get_bytes(entropy, 4, out.ptr));
chunk_free(&out);
ck_assert(!entropy->allocate_bytes(entropy, 4, &out));
entropy->destroy(entropy);
chunk_free(&in);
}
END_TEST
typedef struct {
u_int32_t requested;
u_int32_t standard;
@ -78,15 +100,19 @@ START_TEST(test_ntru_drbg_strength)
}
END_TEST
START_TEST(test_ntru_dbrg)
START_TEST(test_ntru_drbg)
{
typedef struct {
chunk_t pers_str;
chunk_t entropy;
chunk_t out;
} dbrg_test_t;
} drbg_test_t;
dbrg_test_t dbrg_tests[] = {
/**
* NIST SP 800-90A Deterministic Random Generator Validation System (DRBGVS)
*/
drbg_test_t drbg_tests[] = {
/* SHA-256 test case 1 - count 0 */
{ chunk_empty,
chunk_from_chars(0x06, 0x03, 0x2c, 0xd5, 0xee, 0xd3, 0x3f, 0x39,
0x26, 0x5f, 0x49, 0xec, 0xb1, 0x42, 0xc5, 0x11,
@ -115,6 +141,7 @@ START_TEST(test_ntru_dbrg)
0x49, 0x9d, 0xc4, 0x3f, 0x7f, 0x2b, 0xd0, 0x9e,
0x1e, 0x0f, 0x8f, 0x58, 0x85, 0x93, 0x51, 0x24)
},
/* SHA-256 test case 3 - count 0 */
{ chunk_from_chars(0xf2, 0xe5, 0x8f, 0xe6, 0x0a, 0x3a, 0xfc, 0x59,
0xda, 0xd3, 0x75, 0x95, 0x41, 0x5f, 0xfd, 0x31,
0x8c, 0xcf, 0x69, 0xd6, 0x77, 0x80, 0xf6, 0xfa,
@ -145,34 +172,85 @@ START_TEST(test_ntru_dbrg)
0x2a, 0xca, 0x2a, 0xaf, 0x6e, 0xfe, 0x69, 0xed,
0x97, 0xa0, 0x16, 0x21, 0x3a, 0x2d, 0xd6, 0x42,
0xb4, 0x88, 0x67, 0x64, 0x07, 0x2d, 0x9c, 0xbe)
},
/* SHA-256 test case 5 - count 0 */
{ chunk_empty,
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,
0x8c, 0x02, 0x0a, 0x10, 0x53, 0xbd, 0xc7, 0x4a,
0x7b, 0xc0, 0x99, 0x28, 0x5a, 0xd5, 0x62, 0x19,
0x93, 0xb6, 0x39, 0xc4, 0xa9, 0x4c, 0x37, 0x6b,
0x14, 0xfc, 0x6c, 0x9b, 0x17, 0x8d, 0xb6, 0x44,
0xa8, 0xcd, 0x71, 0x30, 0xa4, 0xcf, 0x05, 0x16,
0x78, 0xc8, 0xf4, 0xfa, 0x8f, 0x24, 0xc2, 0x7b,
0x0a, 0x53, 0x13, 0x38, 0xa5, 0xce, 0x85, 0x89),
chunk_from_chars(0x2f, 0x26, 0x20, 0x34, 0x7b, 0xdd, 0xca, 0xa2,
0x94, 0x36, 0x85, 0x34, 0x6b, 0xbf, 0x31, 0xc4,
0x40, 0x81, 0xf8, 0x66, 0x5f, 0x3d, 0xdb, 0x2b,
0x42, 0xae, 0x14, 0x16, 0xa7, 0x4c, 0x4b, 0x77,
0xfa, 0xb3, 0xfa, 0x19, 0xae, 0xec, 0xc5, 0x47,
0xe7, 0x6c, 0x8c, 0xbe, 0x6a, 0xd1, 0xf1, 0x00,
0xa3, 0xfc, 0x8b, 0x2c, 0xe2, 0xa1, 0xea, 0x3a,
0x3d, 0xd7, 0xcf, 0xad, 0x46, 0xc1, 0xb2, 0x78,
0x30, 0xb9, 0x40, 0xba, 0x18, 0xd0, 0x9e, 0x9b,
0x7f, 0xa9, 0x02, 0xbb, 0x76, 0x06, 0x69, 0xb1,
0x73, 0x5c, 0xc7, 0xb7, 0xbd, 0x39, 0x05, 0x2d,
0xa7, 0xf2, 0x62, 0x6f, 0xa8, 0x70, 0x00, 0xcf,
0xfa, 0xda, 0x41, 0x00, 0x19, 0xd0, 0x53, 0x38,
0x6a, 0xd8, 0x08, 0xbd, 0x3c, 0x0c, 0xfc, 0xf5,
0x6b, 0x91, 0x87, 0x9e, 0xb8, 0xd3, 0xf9, 0x32,
0xee, 0x2d, 0x18, 0x5e, 0x54, 0xf3, 0x1b, 0x74)
},
/* SHA-256 test case 7 - count 0 */
{ chunk_from_chars(0x40, 0x93, 0x3f, 0xdc, 0xce, 0x41, 0x59, 0xb0,
0x95, 0x51, 0x11, 0xf8, 0x44, 0x47, 0x1b, 0x0d,
0xb8, 0x5b, 0x73, 0xbd, 0xd2, 0xb7, 0x8c, 0x46,
0x8d, 0xd3, 0x9e, 0x2a, 0x9b, 0x29, 0xae, 0xf2),
chunk_from_chars(0x28, 0xba, 0x1a, 0x66, 0x16, 0x32, 0xef, 0xc8,
0xec, 0xce, 0xd5, 0xf5, 0x1b, 0x79, 0x13, 0x00,
0xfb, 0x3b, 0x55, 0xb0, 0x5d, 0x04, 0x17, 0x08,
0x63, 0x8d, 0xe4, 0xbe, 0xb7, 0x57, 0xa9, 0xe5,
0x76, 0x82, 0x87, 0x96, 0xaf, 0xf0, 0x7f, 0x55,
0x79, 0x5c, 0xb5, 0x47, 0x13, 0xc7, 0x7e, 0xd4,
0xa5, 0xf5, 0x42, 0xb0, 0x4a, 0xaa, 0x5d, 0xbc,
0x93, 0x1e, 0x47, 0x01, 0x9f, 0xeb, 0x38, 0x96,
0x26, 0x16, 0xc5, 0x7a, 0xf0, 0x9b, 0x7c, 0x1d,
0xf8, 0x3f, 0x2b, 0x86, 0x0f, 0xf7, 0x65, 0x86),
chunk_from_chars(0x65, 0xe5, 0xaa, 0x47, 0xb3, 0x85, 0xf1, 0xea,
0x42, 0xb2, 0x31, 0xb9, 0xfe, 0x74, 0x42, 0x53,
0xb8, 0x59, 0x88, 0x59, 0xd7, 0x01, 0x1e, 0x52,
0x5f, 0x5a, 0x2a, 0x1a, 0xd3, 0x2a, 0x97, 0x2a,
0x85, 0x08, 0x02, 0xc6, 0x0a, 0x2b, 0xe1, 0x9b,
0xe2, 0x70, 0x06, 0x3a, 0x3c, 0xfb, 0xea, 0xae,
0x95, 0x4f, 0x10, 0xb1, 0x22, 0x35, 0x2d, 0xe6,
0xa0, 0x8a, 0xc4, 0x10, 0xe0, 0x99, 0x16, 0x53,
0xaa, 0xb2, 0x71, 0xb3, 0x60, 0xfe, 0x91, 0x91,
0xcf, 0x5a, 0xdd, 0xcc, 0xcc, 0xed, 0x8c, 0x4a,
0xcf, 0xb6, 0x14, 0x57, 0x04, 0x99, 0x92, 0x98,
0x8f, 0xd7, 0xa9, 0xac, 0xca, 0x1f, 0x1b, 0xca,
0x35, 0xf1, 0x47, 0x58, 0x13, 0x69, 0x4a, 0x39,
0x98, 0x8e, 0x5f, 0xac, 0x9f, 0x4a, 0xc0, 0x57,
0x22, 0x86, 0xbc, 0x46, 0x25, 0x82, 0xad, 0x0a,
0xf7, 0x8a, 0xb3, 0xb8, 0x5e, 0xc1, 0x7a, 0x25)
}
};
ntru_drbg_t *drbg;
rng_t *entropy;
chunk_t in, out;
chunk_t 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++)
for (i = 0; i < countof(drbg_tests); i++)
{
entropy = ntru_test_rng_create(dbrg_tests[i].entropy);
drbg = ntru_drbg_create(256, dbrg_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, dbrg_tests[i].out));
ck_assert(chunk_equals(out, drbg_tests[i].out));
drbg->destroy(drbg);
entropy->destroy(entropy);
}
@ -374,12 +452,16 @@ Suite *ntru_suite_create()
s = suite_create("ntru");
tc = tcase_create("dbrg_strength");
tc = tcase_create("test_rng");
tcase_add_test(tc, test_ntru_test_rng);
suite_add_tcase(s, tc);
tc = tcase_create("drbg_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);
tc = tcase_create("drbg");
tcase_add_test(tc, test_ntru_drbg);
suite_add_tcase(s, tc);
tc = tcase_create("ke");