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.c39
1 files changed, 26 insertions, 13 deletions
diff --git a/src/lib/libcrypto/rand/randfile.c b/src/lib/libcrypto/rand/randfile.c
index f2b3746363..6829d4ec37 100644
--- a/src/lib/libcrypto/rand/randfile.c
+++ b/src/lib/libcrypto/rand/randfile.c
@@ -56,11 +56,17 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include <errno.h>
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include <stdlib.h>
62#include <string.h>
63#include <sys/types.h>
61#include <sys/stat.h> 64#include <sys/stat.h>
62#include <sys/types.h> 65#include <sys/types.h>
63#include "rand.h" 66
67#include "openssl/e_os.h"
68
69#include <openssl/rand.h>
64 70
65#undef BUFSIZE 71#undef BUFSIZE
66#define BUFSIZE 1024 72#define BUFSIZE 1024
@@ -68,9 +74,7 @@
68 74
69/* #define RFILE ".rand" - defined in ../../e_os.h */ 75/* #define RFILE ".rand" - defined in ../../e_os.h */
70 76
71int RAND_load_file(file,bytes) 77int RAND_load_file(const char *file, long bytes)
72char *file;
73long bytes;
74 { 78 {
75 MS_STATIC unsigned char buf[BUFSIZE]; 79 MS_STATIC unsigned char buf[BUFSIZE];
76 struct stat sb; 80 struct stat sb;
@@ -81,12 +85,12 @@ long bytes;
81 85
82 i=stat(file,&sb); 86 i=stat(file,&sb);
83 /* If the state fails, put some crap in anyway */ 87 /* If the state fails, put some crap in anyway */
84 RAND_seed((unsigned char *)&sb,sizeof(sb)); 88 RAND_seed(&sb,sizeof(sb));
85 ret+=sizeof(sb); 89 ret+=sizeof(sb);
86 if (i < 0) return(0); 90 if (i < 0) return(0);
87 if (bytes <= 0) return(ret); 91 if (bytes <= 0) return(ret);
88 92
89 in=fopen(file,"r"); 93 in=fopen(file,"rb");
90 if (in == NULL) goto err; 94 if (in == NULL) goto err;
91 for (;;) 95 for (;;)
92 { 96 {
@@ -105,15 +109,24 @@ err:
105 return(ret); 109 return(ret);
106 } 110 }
107 111
108int RAND_write_file(file) 112int RAND_write_file(const char *file)
109char *file;
110 { 113 {
111 unsigned char buf[BUFSIZE]; 114 unsigned char buf[BUFSIZE];
112 int i,ret=0; 115 int i,ret=0;
113 FILE *out; 116 FILE *out;
114 int n; 117 int n;
115 118
116 out=fopen(file,"w"); 119 /* Under VMS, fopen(file, "wb") will craete a new version of the
120 same file. This is not good, so let's try updating an existing
121 one, and create file only if it doesn't already exist. This
122 should be completely harmless on system that have no file
123 versions. -- Richard Levitte */
124 out=fopen(file,"rb+");
125 if (out == NULL && errno == ENOENT)
126 {
127 errno = 0;
128 out=fopen(file,"wb");
129 }
117 if (out == NULL) goto err; 130 if (out == NULL) goto err;
118 chmod(file,0600); 131 chmod(file,0600);
119 n=RAND_DATA; 132 n=RAND_DATA;
@@ -137,9 +150,7 @@ err:
137 return(ret); 150 return(ret);
138 } 151 }
139 152
140char *RAND_file_name(buf,size) 153char *RAND_file_name(char *buf, int size)
141char *buf;
142int size;
143 { 154 {
144 char *s; 155 char *s;
145 char *ret=NULL; 156 char *ret=NULL;
@@ -158,7 +169,9 @@ int size;
158 if (((int)(strlen(s)+strlen(RFILE)+2)) > size) 169 if (((int)(strlen(s)+strlen(RFILE)+2)) > size)
159 return(RFILE); 170 return(RFILE);
160 strcpy(buf,s); 171 strcpy(buf,s);
172#ifndef VMS
161 strcat(buf,"/"); 173 strcat(buf,"/");
174#endif
162 strcat(buf,RFILE); 175 strcat(buf,RFILE);
163 ret=buf; 176 ret=buf;
164 } 177 }