summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/rand/randfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/rand/randfile.c')
-rw-r--r--src/lib/libcrypto/rand/randfile.c53
1 files changed, 6 insertions, 47 deletions
diff --git a/src/lib/libcrypto/rand/randfile.c b/src/lib/libcrypto/rand/randfile.c
index c47d1f7224..23efa17388 100644
--- a/src/lib/libcrypto/rand/randfile.c
+++ b/src/lib/libcrypto/rand/randfile.c
@@ -74,10 +74,7 @@
74#define BUFSIZE 1024 74#define BUFSIZE 1024
75#define RAND_DATA 1024 75#define RAND_DATA 1024
76 76
77#define RFILE ".rnd" 77/* Note that these functions should not be used. */
78
79/* Note that these functions are intended for seed files only.
80 * Entropy devices and EGD sockets are handled in rand_unix.c */
81 78
82int RAND_load_file(const char *file, long bytes) 79int RAND_load_file(const char *file, long bytes)
83{ 80{
@@ -145,46 +142,8 @@ err:
145 } 142 }
146 143
147const char *RAND_file_name(char *buf, size_t size) 144const char *RAND_file_name(char *buf, size_t size)
148 { 145{
149 char *s=NULL; 146 if (BUF_strlcpy(buf,"/dev/urandom",size) >= size)
150 struct stat sb; 147 return(NULL);
151 148 return buf;
152 if (OPENSSL_issetugid() == 0) 149}
153 s=getenv("RANDFILE");
154 if (s != NULL && *s && strlen(s) + 1 < size)
155 {
156 if (BUF_strlcpy(buf,s,size) >= size)
157 return NULL;
158 }
159 else
160 {
161 if (OPENSSL_issetugid() == 0)
162 s=getenv("HOME");
163 if (s && *s && strlen(s)+strlen(RFILE)+2 < size)
164 {
165 BUF_strlcpy(buf,s,size);
166 BUF_strlcat(buf,"/",size);
167 BUF_strlcat(buf,RFILE,size);
168 }
169 else
170 buf[0] = '\0'; /* no file name */
171 }
172
173 /* given that all random loads just fail if the file can't be
174 * seen on a stat, we stat the file we're returning, if it
175 * fails, use /dev/arandom instead. this allows the user to
176 * use their own source for good random data, but defaults
177 * to something hopefully decent if that isn't available.
178 */
179
180 if (!buf[0])
181 if (BUF_strlcpy(buf,"/dev/arandom",size) >= size) {
182 return(NULL);
183 }
184 if (stat(buf,&sb) == -1)
185 if (BUF_strlcpy(buf,"/dev/arandom",size) >= size) {
186 return(NULL);
187 }
188
189 return(buf);
190 }