Patches from Vern Staats <staatsvr@asc.hpc.mil> to get Kerberos 5 in
[oweals/openssl.git] / crypto / rand / rand_lib.c
index 57eff0f132948bee10bd1110836cca76c8862beb..adbae32ce358633be5cfcd3bb93777ade4e7fa55 100644 (file)
@@ -58,6 +58,7 @@
 
 #include <stdio.h>
 #include <time.h>
+#include "cryptlib.h"
 #include <openssl/rand.h>
 #include <openssl/engine.h>
 
@@ -73,47 +74,51 @@ int RAND_set_rand_method(ENGINE *engine)
        {
        ENGINE *mtmp;
        mtmp = rand_engine;
-       if (!ENGINE_init(engine))
+       if (engine && !ENGINE_init(engine))
                return 0;
        rand_engine = engine;
        /* SHOULD ERROR CHECK THIS!!! */
-       ENGINE_finish(mtmp);
+       if(mtmp)
+               ENGINE_finish(mtmp);
        return 1;
        }
 #endif
 
-RAND_METHOD *RAND_get_rand_method(void)
+const RAND_METHOD *RAND_get_rand_method(void)
        {
        if (rand_engine == NULL
                && (rand_engine = ENGINE_get_default_RAND()) == NULL)
+               {
+               RANDerr(RAND_F_RAND_GET_RAND_METHOD,ERR_LIB_ENGINE);
                return NULL;
+               }
        return ENGINE_get_RAND(rand_engine);
        }
 
 void RAND_cleanup(void)
        {
-       RAND_METHOD *meth = RAND_get_rand_method();
+       const RAND_METHOD *meth = RAND_get_rand_method();
        if (meth && meth->cleanup)
                meth->cleanup();
        }
 
 void RAND_seed(const void *buf, int num)
        {
-       RAND_METHOD *meth = RAND_get_rand_method();
+       const RAND_METHOD *meth = RAND_get_rand_method();
        if (meth && meth->seed)
                meth->seed(buf,num);
        }
 
 void RAND_add(const void *buf, int num, double entropy)
        {
-       RAND_METHOD *meth = RAND_get_rand_method();
+       const RAND_METHOD *meth = RAND_get_rand_method();
        if (meth && meth->add)
                meth->add(buf,num,entropy);
        }
 
 int RAND_bytes(unsigned char *buf, int num)
        {
-       RAND_METHOD *meth = RAND_get_rand_method();
+       const RAND_METHOD *meth = RAND_get_rand_method();
        if (meth && meth->bytes)
                return meth->bytes(buf,num);
        return(-1);
@@ -121,7 +126,7 @@ int RAND_bytes(unsigned char *buf, int num)
 
 int RAND_pseudo_bytes(unsigned char *buf, int num)
        {
-       RAND_METHOD *meth = RAND_get_rand_method();
+       const RAND_METHOD *meth = RAND_get_rand_method();
        if (meth && meth->pseudorand)
                return meth->pseudorand(buf,num);
        return(-1);
@@ -129,7 +134,7 @@ int RAND_pseudo_bytes(unsigned char *buf, int num)
 
 int RAND_status(void)
        {
-       RAND_METHOD *meth = RAND_get_rand_method();
+       const RAND_METHOD *meth = RAND_get_rand_method();
        if (meth && meth->status)
                return meth->status();
        return 0;