RT3544: Restore MWERKS for NetWare
[openssl.git] / crypto / rand / rand_lib.c
index c653d38c8a03950829736a3f988149e3f31f3b19..4aa6486c8102c9e07d64cfd29ca57c76db0ba9ff 100644 (file)
@@ -78,10 +78,6 @@ static const RAND_METHOD *default_RAND_meth = NULL;
 
 int RAND_set_rand_method(const RAND_METHOD *meth)
        {
-#ifdef OPENSSL_FIPS
-       if (!FIPS_rand_set_method(meth))
-               return 0;
-#endif
 #ifndef OPENSSL_NO_ENGINE
        if(funct_ref)
                {
@@ -198,6 +194,8 @@ int RAND_status(void)
 static size_t drbg_get_entropy(DRBG_CTX *ctx, unsigned char **pout,
                                 int entropy, size_t min_len, size_t max_len)
         {
+       /* Round up request to multiple of block size */
+       min_len = ((min_len + 19) / 20) * 20;
        *pout = OPENSSL_malloc(min_len);
        if (!*pout)
                return 0;
@@ -212,8 +210,11 @@ static size_t drbg_get_entropy(DRBG_CTX *ctx, unsigned char **pout,
 
 static void drbg_free_entropy(DRBG_CTX *ctx, unsigned char *out, size_t olen)
        {
-       OPENSSL_cleanse(out, olen);
-       OPENSSL_free(out);
+       if (out)
+               {
+               OPENSSL_cleanse(out, olen);
+               OPENSSL_free(out);
+               }
        }
 
 /* Set "additional input" when generating random data. This uses the
@@ -226,6 +227,7 @@ static size_t drbg_get_adin(DRBG_CTX *ctx, unsigned char **pout)
        static unsigned char buf[16];
        static unsigned long counter;
        FIPS_get_timevec(buf, &counter);
+       rand_hw_xor(buf, sizeof(buf));
        *pout = buf;
        return sizeof(buf);
        }
@@ -253,7 +255,7 @@ int RAND_init_fips(void)
        dctx = FIPS_get_default_drbg();
         FIPS_drbg_init(dctx, NID_aes_256_ctr, DRBG_FLAG_CTR_USE_DF);
         FIPS_drbg_set_callbacks(dctx,
-                               drbg_get_entropy, drbg_free_entropy,
+                               drbg_get_entropy, drbg_free_entropy, 20,
                                drbg_get_entropy, drbg_free_entropy);
        FIPS_drbg_set_rand_callbacks(dctx, drbg_get_adin, 0,
                                        drbg_rand_seed, drbg_rand_add);