2 * Copyright 2011-2021 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (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
10 #include <openssl/evp.h>
11 #include <openssl/rand.h>
12 #include "rand_local.h"
14 /* Implements the default OpenSSL RAND_add() method */
15 static int drbg_add(const void *buf
, int num
, double randomness
)
17 EVP_RAND_CTX
*drbg
= RAND_get0_primary(NULL
);
19 if (drbg
== NULL
|| num
<= 0)
22 return EVP_RAND_reseed(drbg
, 0, NULL
, 0, buf
, num
);
25 /* Implements the default OpenSSL RAND_seed() method */
26 static int drbg_seed(const void *buf
, int num
)
28 return drbg_add(buf
, num
, num
);
31 /* Implements the default OpenSSL RAND_status() method */
32 static int drbg_status(void)
34 EVP_RAND_CTX
*drbg
= RAND_get0_primary(NULL
);
39 return EVP_RAND_get_state(drbg
) == EVP_RAND_STATE_READY
? 1 : 0;
42 /* Implements the default OpenSSL RAND_bytes() method */
43 static int drbg_bytes(unsigned char *out
, int count
)
45 EVP_RAND_CTX
*drbg
= RAND_get0_public(NULL
);
50 return EVP_RAND_generate(drbg
, out
, count
, 0, 0, NULL
, 0);
53 RAND_METHOD ossl_rand_meth
= {
62 RAND_METHOD
*RAND_OpenSSL(void)
65 return &ossl_rand_meth
;