fips/fips_[canister|premain].c: make it work with VC6 and add sentinels
[openssl.git] / fips / rand / fips_drbg_rand.c
index f179bd82a9259c48675123a797f45fe3e8dea688..764a78cbfd410dc4e9707651792e5a958ca9c175 100644 (file)
@@ -55,8 +55,6 @@
 
 #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>
@@ -65,7 +63,7 @@
 /* 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;
@@ -94,11 +92,11 @@ static int fips_drbg_bytes(unsigned char *out, int count)
                        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)
@@ -117,6 +115,13 @@ static int fips_drbg_bytes(unsigned char *out, int count)
        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;
@@ -138,28 +143,18 @@ static void fips_drbg_cleanup(void)
 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 =
@@ -168,7 +163,7 @@ 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
        };