Make EVPs allocate context memory, thus making them extensible. Rationalise
[openssl.git] / crypto / des / enc_writ.c
index 238c0a9c09e2b65c3b94dae1a526793c6771618c..ea9e4b48ca3d83b43a741dc6c996aa3458632a60 100644 (file)
@@ -61,6 +61,7 @@
 #include <stdio.h>
 #include "cryptlib.h"
 #include "des_locl.h"
+#include <openssl/rand.h>
 
 /*
  * WARNINGS:
  *  -  This code cannot handle non-blocking sockets.
  */
 
-int des_enc_write(int fd, const char *buf, int len, des_key_schedule sched,
-            des_cblock iv)
+int des_enc_write(int fd, const void *_buf, int len,
+                 des_key_schedule *sched, des_cblock *iv)
        {
 #ifdef _LIBC
-       extern int srandom();
        extern unsigned long time();
-       extern int random();
        extern int write();
 #endif
-
+       const unsigned char *buf=_buf;
        long rnum;
        int i,j,k,outnum;
-       static char *outbuf=NULL;
-       char shortbuf[8];
-       char *p;
-       const char *cp;
+       static unsigned char *outbuf=NULL;
+       unsigned char shortbuf[8];
+       unsigned char *p;
+       const unsigned char *cp;
        static int start=1;
 
        if (outbuf == NULL)
                {
-               outbuf=(char *)Malloc(BSIZE+HDRSIZE);
+               outbuf=OPENSSL_malloc(BSIZE+HDRSIZE);
                if (outbuf == NULL) return(-1);
                }
        /* If we are sending less than 8 bytes, the same char will look
@@ -104,7 +103,6 @@ int des_enc_write(int fd, const char *buf, int len, des_key_schedule sched,
        if (start)
                {
                start=0;
-               srandom((unsigned int)time(NULL));
                }
 
        /* lets recurse if we want to send the data in small chunks */
@@ -131,9 +129,8 @@ int des_enc_write(int fd, const char *buf, int len, des_key_schedule sched,
        if (len < 8)
                {
                cp=shortbuf;
-               memcpy(shortbuf,buf,(unsigned int)len);
-               for (i=len; i<8; i++)
-                       shortbuf[i]=random();
+               memcpy(shortbuf,buf,len);
+               RAND_pseudo_bytes(shortbuf+len, 8-len);
                rnum=8;
                }
        else
@@ -150,18 +147,21 @@ int des_enc_write(int fd, const char *buf, int len, des_key_schedule sched,
                                DES_ENCRYPT); 
 
        /* output */
-       outnum=(int)rnum+HDRSIZE;
+       outnum=rnum+HDRSIZE;
 
        for (j=0; j<outnum; j+=i)
                {
                /* eay 26/08/92 I was not doing writing from where we
-                * got upto. */
-               i=write(fd,&(outbuf[j]),(unsigned int)(outnum-j));
+                * got up to. */
+               i=write(fd,(void *)&(outbuf[j]),outnum-j);
                if (i == -1)
                        {
+#ifdef EINTR
                        if (errno == EINTR)
                                i=0;
-                       else    /* This is really a bad error - very bad
+                       else
+#endif
+                               /* This is really a bad error - very bad
                                 * It will stuff-up both ends. */
                                return(-1);
                        }