As ftruncate is not availabe on all platforms, switch back to
[oweals/openssl.git] / crypto / des / des.c
index 91d7967e31e8e298f1118cd148dc6bfc4182af33..aabd01cc8a6aa8e79ffff50ede81ae5770776819 100644 (file)
 #include <stdlib.h>
 #ifndef MSDOS
 #ifndef VMS
-#include <unistd.h>
+#include <openssl/opensslconf.h>
+#include OPENSSL_UNISTD
 #else /* VMS */
 #ifdef __DECC
 #include <unistd.h>
-#if __CRTL_VER < 70000000
-#define RAND
-#endif
 #else /* not __DECC */
 #include <math.h>
-#define RAND
 #endif /* __DECC */
 #endif /* VMS */
 #else
 #include <io.h>
-#define RAND
 #endif
 
 #include <time.h>
 #include <sys/stat.h>
 #endif
 #include <openssl/des.h>
+#include <openssl/rand.h>
 
 #if defined(__STDC__) || defined(VMS) || defined(M_XENIX) || defined(MSDOS)
 #include <string.h>
 #endif
 
-#ifdef RAND
-#define random rand
-#define srandom(s) srand(s)
-#endif
-
 void usage(void);
 void doencryption(void);
 int uufwrite(unsigned char *data, int size, unsigned int num, FILE *fp);
@@ -344,7 +336,7 @@ void usage(void)
 "             in conjunction with -[eEdD].",
 "-C[ckname] : generate a cbc_cksum as for -c but compatible with -[ED].",
 "-k key     : use key 'key'",
-"-h         : the key that is entered will be a hexidecimal number",
+"-h         : the key that is entered will be a hexadecimal number",
 "             that is used directly as the des key",
 "-u[uuname] : input file is uudecoded if -[dD] or output uuencoded data if -[eE]",
 "             (uuname is the filename to put in the uuencode header).",
@@ -367,8 +359,6 @@ NULL
 void doencryption(void)
        {
 #ifdef _LIBC
-       extern int srandom();
-       extern int random();
        extern unsigned long time();
 #endif
 
@@ -435,7 +425,7 @@ void doencryption(void)
                        else
                                k2[i-8]=k;
                        }
-               des_set_key(&k2,ks2);
+               des_set_key_unchecked(&k2,ks2);
                memset(k2,0,sizeof(k2));
                }
        else if (longk || flag3)
@@ -443,7 +433,7 @@ void doencryption(void)
                if (flag3)
                        {
                        des_string_to_2keys(key,&kk,&k2);
-                       des_set_key(&k2,ks2);
+                       des_set_key_unchecked(&k2,ks2);
                        memset(k2,0,sizeof(k2));
                        }
                else
@@ -465,7 +455,7 @@ void doencryption(void)
                                kk[i]=key[i]|0x80;
                        }
 
-       des_set_key(&kk,ks);
+       des_set_key_unchecked(&kk,ks);
        memset(key,0,sizeof(key));
        memset(kk,0,sizeof(kk));
        /* woops - A bug that does not showup under unix :-( */
@@ -493,9 +483,8 @@ void doencryption(void)
                        len=l-rem;
                        if (feof(DES_IN))
                                {
-                               srandom((unsigned int)time(NULL));
                                for (i=7-rem; i>0; i--)
-                                       buf[l++]=random()&0xff;
+                                       RAND_pseudo_bytes(buf + l++, 1);
                                buf[l++]=rem;
                                ex=1;
                                len+=rem;