summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/rand
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lib/libcrypto/rand/rand.h2
-rw-r--r--src/lib/libcrypto/rand/rand_lib.c10
-rw-r--r--src/lib/libcrypto/rand/randfile.c9
3 files changed, 17 insertions, 4 deletions
diff --git a/src/lib/libcrypto/rand/rand.h b/src/lib/libcrypto/rand/rand.h
index 66e39991ec..606382dd21 100644
--- a/src/lib/libcrypto/rand/rand.h
+++ b/src/lib/libcrypto/rand/rand.h
@@ -87,7 +87,9 @@ extern int rand_predictable;
87 87
88int RAND_set_rand_method(const RAND_METHOD *meth); 88int RAND_set_rand_method(const RAND_METHOD *meth);
89const RAND_METHOD *RAND_get_rand_method(void); 89const RAND_METHOD *RAND_get_rand_method(void);
90#ifndef OPENSSL_NO_ENGINE
90int RAND_set_rand_engine(ENGINE *engine); 91int RAND_set_rand_engine(ENGINE *engine);
92#endif
91RAND_METHOD *RAND_SSLeay(void); 93RAND_METHOD *RAND_SSLeay(void);
92void RAND_cleanup(void ); 94void RAND_cleanup(void );
93int RAND_bytes(unsigned char *buf,int num); 95int RAND_bytes(unsigned char *buf,int num);
diff --git a/src/lib/libcrypto/rand/rand_lib.c b/src/lib/libcrypto/rand/rand_lib.c
index 5cf5dc1188..513e338985 100644
--- a/src/lib/libcrypto/rand/rand_lib.c
+++ b/src/lib/libcrypto/rand/rand_lib.c
@@ -60,19 +60,25 @@
60#include <time.h> 60#include <time.h>
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include <openssl/rand.h> 62#include <openssl/rand.h>
63#ifndef OPENSSL_NO_ENGINE
63#include <openssl/engine.h> 64#include <openssl/engine.h>
65#endif
64 66
67#ifndef OPENSSL_NO_ENGINE
65/* non-NULL if default_RAND_meth is ENGINE-provided */ 68/* non-NULL if default_RAND_meth is ENGINE-provided */
66static ENGINE *funct_ref =NULL; 69static ENGINE *funct_ref =NULL;
70#endif
67static const RAND_METHOD *default_RAND_meth = NULL; 71static const RAND_METHOD *default_RAND_meth = NULL;
68 72
69int RAND_set_rand_method(const RAND_METHOD *meth) 73int RAND_set_rand_method(const RAND_METHOD *meth)
70 { 74 {
75#ifndef OPENSSL_NO_ENGINE
71 if(funct_ref) 76 if(funct_ref)
72 { 77 {
73 ENGINE_finish(funct_ref); 78 ENGINE_finish(funct_ref);
74 funct_ref = NULL; 79 funct_ref = NULL;
75 } 80 }
81#endif
76 default_RAND_meth = meth; 82 default_RAND_meth = meth;
77 return 1; 83 return 1;
78 } 84 }
@@ -81,6 +87,7 @@ const RAND_METHOD *RAND_get_rand_method(void)
81 { 87 {
82 if (!default_RAND_meth) 88 if (!default_RAND_meth)
83 { 89 {
90#ifndef OPENSSL_NO_ENGINE
84 ENGINE *e = ENGINE_get_default_RAND(); 91 ENGINE *e = ENGINE_get_default_RAND();
85 if(e) 92 if(e)
86 { 93 {
@@ -94,11 +101,13 @@ const RAND_METHOD *RAND_get_rand_method(void)
94 if(e) 101 if(e)
95 funct_ref = e; 102 funct_ref = e;
96 else 103 else
104#endif
97 default_RAND_meth = RAND_SSLeay(); 105 default_RAND_meth = RAND_SSLeay();
98 } 106 }
99 return default_RAND_meth; 107 return default_RAND_meth;
100 } 108 }
101 109
110#ifndef OPENSSL_NO_ENGINE
102int RAND_set_rand_engine(ENGINE *engine) 111int RAND_set_rand_engine(ENGINE *engine)
103 { 112 {
104 const RAND_METHOD *tmp_meth = NULL; 113 const RAND_METHOD *tmp_meth = NULL;
@@ -118,6 +127,7 @@ int RAND_set_rand_engine(ENGINE *engine)
118 funct_ref = engine; 127 funct_ref = engine;
119 return 1; 128 return 1;
120 } 129 }
130#endif
121 131
122void RAND_cleanup(void) 132void RAND_cleanup(void)
123 { 133 {
diff --git a/src/lib/libcrypto/rand/randfile.c b/src/lib/libcrypto/rand/randfile.c
index 982074c465..41574768ab 100644
--- a/src/lib/libcrypto/rand/randfile.c
+++ b/src/lib/libcrypto/rand/randfile.c
@@ -124,7 +124,7 @@ int RAND_load_file(const char *file, long bytes)
124 } 124 }
125 } 125 }
126 fclose(in); 126 fclose(in);
127 memset(buf,0,BUFSIZE); 127 OPENSSL_cleanse(buf,BUFSIZE);
128err: 128err:
129 return(ret); 129 return(ret);
130 } 130 }
@@ -189,7 +189,7 @@ int RAND_write_file(const char *file)
189#endif /* OPENSSL_SYS_VMS */ 189#endif /* OPENSSL_SYS_VMS */
190 190
191 fclose(out); 191 fclose(out);
192 memset(buf,0,BUFSIZE); 192 OPENSSL_cleanse(buf,BUFSIZE);
193err: 193err:
194 return (rand_err ? -1 : ret); 194 return (rand_err ? -1 : ret);
195 } 195 }
@@ -203,8 +203,9 @@ const char *RAND_file_name(char *buf, size_t size)
203 s=getenv("RANDFILE"); 203 s=getenv("RANDFILE");
204 if (s != NULL) 204 if (s != NULL)
205 { 205 {
206 strncpy(buf,s,size-1); 206 if(strlen(s) >= size)
207 buf[size-1]='\0'; 207 return NULL;
208 strcpy(buf,s);
208 ret=buf; 209 ret=buf;
209 } 210 }
210 else 211 else