#include <string.h>
#include <openssl/crypto.h>
-#include <openssl/evp.h>
-#include <openssl/aes.h>
#include <openssl/err.h>
#include <openssl/rand.h>
#include <openssl/fips_rand.h>
/* Mapping of SP800-90 DRBGs to OpenSSL RAND_METHOD */
/* Since we only have one global PRNG used at any time in OpenSSL use a global
- * variable to store contexts.
+ * variable to store context.
*/
static DRBG_CTX ossl_dctx;
adinlen = dctx->get_adin(dctx, &adin);
if (adinlen && !adin)
{
- /* ERROR */
+ FIPSerr(FIPS_F_FIPS_DRBG_BYTES, FIPS_R_ERROR_RETRIEVING_ADDITIONAL_INPUT);
goto err;
}
}
- rv = FIPS_drbg_generate(dctx, out, rcnt, 0, 0, adin, adinlen);
+ rv = FIPS_drbg_generate(dctx, out, rcnt, 0, adin, adinlen);
if (adin)
{
if (dctx->cleanup_adin)
return rv;
}
+static int fips_drbg_pseudo(unsigned char *out, int count)
+ {
+ if (fips_drbg_bytes(out, count) <= 0)
+ return -1;
+ return 1;
+ }
+
static int fips_drbg_status(void)
{
DRBG_CTX *dctx = &ossl_dctx;
static int fips_drbg_seed(const void *seed, int seedlen)
{
DRBG_CTX *dctx = &ossl_dctx;
- int rv = 1;
if (dctx->rand_seed_cb)
- {
- CRYPTO_w_lock(CRYPTO_LOCK_RAND);
- rv = dctx->rand_seed_cb(dctx, seed, seedlen);
- CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
- }
- return rv;
+ return dctx->rand_seed_cb(dctx, seed, seedlen);
+ return 1;
}
static int fips_drbg_add(const void *seed, int seedlen,
double add_entropy)
{
DRBG_CTX *dctx = &ossl_dctx;
- int rv = 1;
if (dctx->rand_add_cb)
- {
- CRYPTO_w_lock(CRYPTO_LOCK_RAND);
- rv = dctx->rand_add_cb(dctx, seed, seedlen, add_entropy);
- CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
- }
- return rv;
+ return dctx->rand_add_cb(dctx, seed, seedlen, add_entropy);
+ return 1;
}
static const RAND_METHOD rand_drbg_meth =
fips_drbg_bytes,
fips_drbg_cleanup,
fips_drbg_add,
- fips_drbg_bytes,
+ fips_drbg_pseudo,
fips_drbg_status
};