X-Git-Url: https://git.openssl.org/?p=openssl.git;a=blobdiff_plain;f=crypto%2Fdes%2Fenc_read.c;h=e7c853f5cc7be14b1b46deffa9d9fd6ea242446c;hp=3b254d0fd59d82140fc3580cc820616115c3f65e;hb=0089a9dfa8a3e783d27c74623081dfa8c4352c29;hpb=eda1f21f1af8b6f77327e7b37573af9c1ba73726 diff --git a/crypto/des/enc_read.c b/crypto/des/enc_read.c index 3b254d0fd5..e7c853f5cc 100644 --- a/crypto/des/enc_read.c +++ b/crypto/des/enc_read.c @@ -1,5 +1,5 @@ /* crypto/des/enc_read.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written @@ -58,46 +58,65 @@ #include #include +#include "cryptlib.h" #include "des_locl.h" /* This has some uglies in it but it works - even over sockets. */ /*extern int errno;*/ -int des_rw_mode=DES_PCBC_MODE; - -int des_enc_read(fd, buf, len, sched, iv) -int fd; -char *buf; -int len; -des_key_schedule sched; -des_cblock (*iv); +OPENSSL_IMPLEMENT_GLOBAL(int,DES_rw_mode,DES_PCBC_MODE) + + +/* + * WARNINGS: + * + * - The data format used by DES_enc_write() and DES_enc_read() + * has a cryptographic weakness: When asked to write more + * than MAXWRITE bytes, DES_enc_write will split the data + * into several chunks that are all encrypted + * using the same IV. So don't use these functions unless you + * are sure you know what you do (in which case you might + * not want to use them anyway). + * + * - This code cannot handle non-blocking sockets. + * + * - This function uses an internal state and thus cannot be + * used on multiple files. + */ + + +int DES_enc_read(int fd, void *buf, int len, DES_key_schedule *sched, + DES_cblock *iv) { +#if defined(OPENSSL_NO_POSIX_IO) + return(0); +#else /* data to be unencrypted */ int net_num=0; static unsigned char *net=NULL; /* extra unencrypted data * for when a block of 100 comes in but is des_read one byte at * a time. */ - static char *unnet=NULL; + static unsigned char *unnet=NULL; static int unnet_start=0; static int unnet_left=0; - static char *tmpbuf=NULL; + static unsigned char *tmpbuf=NULL; int i; long num=0,rnum; unsigned char *p; if (tmpbuf == NULL) { - tmpbuf=(char *)malloc(BSIZE); + tmpbuf=OPENSSL_malloc(BSIZE); if (tmpbuf == NULL) return(-1); } if (net == NULL) { - net=(unsigned char *)malloc(BSIZE); + net=OPENSSL_malloc(BSIZE); if (net == NULL) return(-1); } if (unnet == NULL) { - unnet=(char *)malloc(BSIZE); + unnet=OPENSSL_malloc(BSIZE); if (unnet == NULL) return(-1); } /* left over data from last decrypt */ @@ -109,7 +128,7 @@ des_cblock (*iv); * with the number of bytes we have - should always * check the return value */ memcpy(buf,&(unnet[unnet_start]), - (unsigned int)unnet_left); + unnet_left); /* eay 26/08/92 I had the next 2 lines * reversed :-( */ i=unnet_left; @@ -117,7 +136,7 @@ des_cblock (*iv); } else { - memcpy(buf,&(unnet[unnet_start]),(unsigned int)len); + memcpy(buf,&(unnet[unnet_start]),len); unnet_start+=len; unnet_left-=len; i=len; @@ -131,8 +150,14 @@ des_cblock (*iv); /* first - get the length */ while (net_num < HDRSIZE) { - i=read(fd,&(net[net_num]),(unsigned int)HDRSIZE-net_num); +#ifndef _WIN32 + i=read(fd,(void *)&(net[net_num]),HDRSIZE-net_num); +#else + i=_read(fd,(void *)&(net[net_num]),HDRSIZE-net_num); +#endif +#ifdef EINTR if ((i == -1) && (errno == EINTR)) continue; +#endif if (i <= 0) return(0); net_num+=i; } @@ -151,8 +176,14 @@ des_cblock (*iv); net_num=0; while (net_num < rnum) { - i=read(fd,&(net[net_num]),(unsigned int)rnum-net_num); +#ifndef OPENSSL_SYS_WIN32 + i=read(fd,(void *)&(net[net_num]),rnum-net_num); +#else + i=_read(fd,(void *)&(net[net_num]),rnum-net_num); +#endif +#ifdef EINTR if ((i == -1) && (errno == EINTR)) continue; +#endif if (i <= 0) return(0); net_num+=i; } @@ -160,15 +191,13 @@ des_cblock (*iv); /* Check if there will be data left over. */ if (len < num) { - if (des_rw_mode & DES_PCBC_MODE) - des_pcbc_encrypt((des_cblock *)net,(des_cblock *)unnet, - num,sched,iv,DES_DECRYPT); + if (DES_rw_mode & DES_PCBC_MODE) + DES_pcbc_encrypt(net,unnet,num,sched,iv,DES_DECRYPT); else - des_cbc_encrypt((des_cblock *)net,(des_cblock *)unnet, - num,sched,iv,DES_DECRYPT); - memcpy(buf,unnet,(unsigned int)len); + DES_cbc_encrypt(net,unnet,num,sched,iv,DES_DECRYPT); + memcpy(buf,unnet,len); unnet_start=len; - unnet_left=(int)num-len; + unnet_left=num-len; /* The following line is done because we return num * as the number of bytes read. */ @@ -184,31 +213,28 @@ des_cblock (*iv); if (len < rnum) { - if (des_rw_mode & DES_PCBC_MODE) - des_pcbc_encrypt((des_cblock *)net, - (des_cblock *)tmpbuf, - num,sched,iv,DES_DECRYPT); + if (DES_rw_mode & DES_PCBC_MODE) + DES_pcbc_encrypt(net,tmpbuf,num,sched,iv, + DES_DECRYPT); else - des_cbc_encrypt((des_cblock *)net, - (des_cblock *)tmpbuf, - num,sched,iv,DES_DECRYPT); + DES_cbc_encrypt(net,tmpbuf,num,sched,iv, + DES_DECRYPT); /* eay 26/08/92 fix a bug that returned more * bytes than you asked for (returned len bytes :-( */ - memcpy(buf,tmpbuf,(unsigned int)num); + memcpy(buf,tmpbuf,num); } else { - if (des_rw_mode & DES_PCBC_MODE) - des_pcbc_encrypt((des_cblock *)net, - (des_cblock *)buf,num,sched,iv, - DES_DECRYPT); + if (DES_rw_mode & DES_PCBC_MODE) + DES_pcbc_encrypt(net,buf,num,sched,iv, + DES_DECRYPT); else - des_cbc_encrypt((des_cblock *)net, - (des_cblock *)buf,num,sched,iv, - DES_DECRYPT); + DES_cbc_encrypt(net,buf,num,sched,iv, + DES_DECRYPT); } } - return((int)num); + return num; +#endif /* OPENSSL_NO_POSIX_IO */ }