2 * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 #include "internal/nelem.h"
12 #include <openssl/crypto.h>
13 #include <openssl/err.h>
14 #include <openssl/rand.h>
15 #include <openssl/obj_mac.h>
16 #include <openssl/evp.h>
17 #include <openssl/aes.h>
18 #include "../crypto/rand/rand_local.h"
21 #include "drbg_extra_test.h"
23 static unsigned char zerobuff[32];
25 static size_t kat_entropy(RAND_DRBG *drbg, unsigned char **pout,
26 int entropy, size_t min_len, size_t max_len,
27 int prediction_resistance)
30 return sizeof(zerobuff);
33 static size_t kat_nonce(RAND_DRBG *drbg, unsigned char **pout,
34 int entropy, size_t min_len, size_t max_len)
37 return sizeof(zerobuff);
40 static int run_extra_kat(const struct drbg_extra_kat *td)
43 RAND_DRBG *drbg = NULL;
44 unsigned char buff[BUFFSIZE];
45 unsigned int flags = 0;
48 if (!TEST_ptr(drbg = RAND_DRBG_new(td->nid, flags, NULL)))
51 /* Set deterministic entropy callback. */
52 if (!TEST_true(RAND_DRBG_set_callbacks(drbg, kat_entropy, NULL,
58 /* Set fixed reseed intervall. */
59 if (!TEST_true(RAND_DRBG_set_reseed_interval(drbg, RESEEDINTERVAL))) {
64 if (!TEST_true(RAND_DRBG_instantiate(drbg, NULL, 0)))
67 for (i = 0; i < td->ngen; i++) {
68 if(!TEST_true(RAND_DRBG_generate(drbg, buff, sizeof(buff), 0, NULL,
73 if (!TEST_true(RAND_DRBG_uninstantiate(drbg))
74 || !TEST_mem_eq(td->expected, sizeof(buff), buff, sizeof(buff)))
79 RAND_DRBG_uninstantiate(drbg);
85 static int test_extra_kats(int i)
87 return run_extra_kat(drbg_extra_test[i]);
92 ADD_ALL_TESTS(test_extra_kats, OSSL_NELEM(drbg_extra_test));