drbg: Implemented NIST SP-800-90A DRBG

This commit is contained in:
Andreas Steffen
2019-10-16 16:46:24 +02:00
parent 2a7937f179
commit 737375a2d2
33 changed files with 2825 additions and 37 deletions
+2 -3
View File
@@ -2,8 +2,7 @@ check_LTLIBRARIES = libtest.la
libtest_la_SOURCES = \
test_suite.c test_suite.h \
test_runner.c test_runner.h \
utils/test_rng.c utils/test_rng.h
test_runner.c test_runner.h
libtest_la_CFLAGS = \
-I$(top_srcdir)/src/libstrongswan \
@@ -54,7 +53,7 @@ libstrongswan_tests_SOURCES = tests.h tests.c \
suites/test_asn1.c \
suites/test_asn1_parser.c \
suites/test_printf.c \
suites/test_test_rng.c \
suites/test_rng_tester.c \
suites/test_mgf1.c \
suites/test_ntru.c \
suites/test_ed25519.c \
@@ -15,7 +15,6 @@
#include "test_suite.h"
#include <tests/utils/test_rng.h>
#include <utils/test.h>
#include <crypto/xofs/xof.h>
#include <crypto/xofs/xof_bitspender.h>
@@ -15,10 +15,10 @@
#include "test_suite.h"
#include <tests/utils/test_rng.h>
#include <utils/test.h>
#include <crypto/rngs/rng_tester.h>
START_TEST(test_test_rng)
START_TEST(test_rng_tester)
{
rng_t *entropy;
chunk_t in, in1, in2, out;
@@ -27,7 +27,7 @@ START_TEST(test_test_rng)
in2 = chunk_from_chars(0x07, 0x08);
in = chunk_cat("cc", in1, in2);
entropy = test_rng_create(in);
entropy = rng_tester_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));
@@ -41,15 +41,15 @@ START_TEST(test_test_rng)
END_TEST
Suite *test_rng_suite_create()
Suite *rng_tester_suite_create()
{
Suite *s;
TCase *tc;
s = suite_create("test_rng");
s = suite_create("rng_tester");
tc = tcase_create("test_rng");
tcase_add_test(tc, test_test_rng);
tc = tcase_create("rng_tester");
tcase_add_test(tc, test_rng_tester);
suite_add_tcase(s, tc);
return s;
@@ -28,6 +28,8 @@ static transform_type_t tfs[] = {
INTEGRITY_ALGORITHM,
HASH_ALGORITHM,
PSEUDO_RANDOM_FUNCTION,
EXTENDED_OUTPUT_FUNCTION,
DETERMINISTIC_RANDOM_BIT_GENERATOR,
RANDOM_NUMBER_GENERATOR,
DIFFIE_HELLMAN_GROUP,
};
+1 -1
View File
@@ -46,7 +46,7 @@ TEST_SUITE_DEPEND(iv_gen_suite_create, RNG, RNG_STRONG)
TEST_SUITE(pen_suite_create)
TEST_SUITE(asn1_suite_create)
TEST_SUITE(asn1_parser_suite_create)
TEST_SUITE(test_rng_suite_create)
TEST_SUITE(rng_tester_suite_create)
TEST_SUITE_DEPEND(mgf1_sha1_suite_create, XOF, XOF_MGF1_SHA1)
TEST_SUITE_DEPEND(mgf1_sha256_suite_create, XOF, XOF_MGF1_SHA256)
TEST_SUITE_DEPEND(ntru_suite_create, DH, NTRU_112_BIT)
-86
View File
@@ -1,86 +0,0 @@
/*
* Copyright (C) 2013 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_rng.h"
typedef struct private_rng_t private_rng_t;
/**
* Private data.
*/
struct private_rng_t {
/**
* Public interface.
*/
rng_t public;
/**
* Entropy string.
*/
chunk_t entropy;
};
METHOD(rng_t, get_bytes, bool,
private_rng_t *this, size_t bytes, uint8_t *buffer)
{
if (bytes > this->entropy.len)
{
return FALSE;
}
memcpy(buffer, this->entropy.ptr, bytes);
this->entropy = chunk_skip(this->entropy, bytes);
return TRUE;
}
METHOD(rng_t, allocate_bytes, bool,
private_rng_t *this, size_t bytes, chunk_t *chunk)
{
if (bytes > this->entropy.len)
{
*chunk = chunk_empty;
return FALSE;
}
*chunk = chunk_alloc(bytes);
memcpy(chunk->ptr, this->entropy.ptr, bytes);
this->entropy = chunk_skip(this->entropy, bytes);
return TRUE;
}
METHOD(rng_t, destroy, void,
private_rng_t *this)
{
free(this);
}
/*
* Described in header.
*/
rng_t *test_rng_create(chunk_t entropy)
{
private_rng_t *this;
INIT(this,
.public = {
.get_bytes = _get_bytes,
.allocate_bytes = _allocate_bytes,
.destroy = _destroy,
},
.entropy = entropy,
);
return &this->public;
}
-36
View File
@@ -1,36 +0,0 @@
/*
* Copyright (C) 2013 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.
*/
/**
* rng_t providing NIST SP 800-90A entropy test vectors
*
* @defgroup test_rng test_rng
* @{ @ingroup test_utils
*/
#ifndef TEST_RNG_H_
#define TEST_RNG_H_
#include <library.h>
/**
* Creates a test_rng_t instance.
*
* @param entropy entropy test vector
* @return created test_rng_t
*/
rng_t *test_rng_create(chunk_t entropy);
#endif /** TEST_RNG_H_ @} */