Use of DEVRANDOM must be #ifdef'ed (the #ifdef was commented out
[openssl.git] / crypto / rand / md_rand.c
index dbf13e686fe1525440228d5305130eae8cc9b97b..0ce390b5c015a61ec50ee52ba3dab20171db0904 100644 (file)
  */
 
 #include <stdio.h>
-#include <sys/types.h>
 #include <time.h>
 #include <string.h>
-#include "e_os.h"
-#include "crypto.h"
+
+#include "openssl/e_os.h"
+
+#include <openssl/crypto.h>
 
 #if !defined(USE_MD5_RAND) && !defined(USE_SHA1_RAND) && !defined(USE_MDC2_RAND) && !defined(USE_MD2_RAND)
-#ifndef NO_MD5
-#define USE_MD5_RAND
-#elif !defined(NO_SHA1)
+#if !defined(NO_SHA) && !defined(NO_SHA1)
 #define USE_SHA1_RAND
-#elif !defined(NO_MDC2)
+#elif !defined(NO_MD5)
+#define USE_MD5_RAND
+#elif !defined(NO_MDC2) && !defined(NO_DES)
 #define USE_MDC2_RAND
 #elif !defined(NO_MD2)
 #define USE_MD2_RAND
 #else
-We need a message digest of some type 
+#error No message digest algorithm available
 #endif
 #endif
 
@@ -84,7 +85,7 @@ We need a message digest of some type
  */
 
 #if defined(USE_MD5_RAND)
-#include "md5.h"
+#include <openssl/md5.h>
 #define MD_DIGEST_LENGTH       MD5_DIGEST_LENGTH
 #define MD_CTX                 MD5_CTX
 #define MD_Init(a)             MD5_Init(a)
@@ -92,7 +93,7 @@ We need a message digest of some type
 #define        MD_Final(a,b)           MD5_Final(a,b)
 #define        MD(a,b,c)               MD5(a,b,c)
 #elif defined(USE_SHA1_RAND)
-#include "sha.h"
+#include <openssl/sha.h>
 #define MD_DIGEST_LENGTH       SHA_DIGEST_LENGTH
 #define MD_CTX                 SHA_CTX
 #define MD_Init(a)             SHA1_Init(a)
@@ -100,7 +101,7 @@ We need a message digest of some type
 #define        MD_Final(a,b)           SHA1_Final(a,b)
 #define        MD(a,b,c)               SHA1(a,b,c)
 #elif defined(USE_MDC2_RAND)
-#include "mdc2.h"
+#include <openssl/mdc2.h>
 #define MD_DIGEST_LENGTH       MDC2_DIGEST_LENGTH
 #define MD_CTX                 MDC2_CTX
 #define MD_Init(a)             MDC2_Init(a)
@@ -108,7 +109,7 @@ We need a message digest of some type
 #define        MD_Final(a,b)           MDC2_Final(a,b)
 #define        MD(a,b,c)               MDC2(a,b,c)
 #elif defined(USE_MD2_RAND)
-#include "md2.h"
+#include <openssl/md2.h>
 #define MD_DIGEST_LENGTH       MD2_DIGEST_LENGTH
 #define MD_CTX                 MD2_CTX
 #define MD_Init(a)             MD2_Init(a)
@@ -117,7 +118,7 @@ We need a message digest of some type
 #define        MD(a,b,c)               MD2(a,b,c)
 #endif
 
-#include "rand.h"
+#include <openssl/rand.h>
 
 /* #define NORAND      1 */
 /* #define PREDICT     1 */
@@ -241,7 +242,6 @@ static void ssleay_rand_bytes(unsigned char *buf, int num)
 
        if (init)
                {
-               init=0;
                CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
                /* put in some default random data, we need more than
                 * just this */
@@ -255,7 +255,7 @@ static void ssleay_rand_bytes(unsigned char *buf, int num)
                l=time(NULL);
                RAND_seed(&l,sizeof(l));
 
-/* #ifdef DEVRANDOM */
+#ifdef DEVRANDOM
                /* 
                 * Use a random entropy pool device.
                 * Linux 1.3.x and FreeBSD-Current has 
@@ -275,12 +275,13 @@ static void ssleay_rand_bytes(unsigned char *buf, int num)
                        RAND_seed(tmpbuf,32);
                        memset(tmpbuf,0,32);
                        }
-/* #endif */
+#endif
 #ifdef PURIFY
                memset(state,0,STATE_SIZE);
                memset(md,0,MD_DIGEST_LENGTH);
 #endif
                CRYPTO_w_lock(CRYPTO_LOCK_RAND);
+               init=0;
                }
 
        st_idx=state_index;
@@ -330,7 +331,7 @@ static void ssleay_rand_bytes(unsigned char *buf, int num)
 
 #ifdef WINDOWS
 #include <windows.h>
-#include <rand.h>
+#include <openssl/rand.h>
 
 /*****************************************************************************
  * Initialisation function for the SSL random generator.  Takes the contents