From 4f947d680afa74c70cf3f206d4f05dcc3555aa90 Mon Sep 17 00:00:00 2001 From: markm Date: Sun, 19 Sep 1999 13:04:49 +0000 Subject: [PATCH] Big OpenSSL/KTH/FreeBSD merge, badly poisoned by $FreeBSD$'s. --- crypto/libdes/asm/dx86-cpp.s | 3 +- crypto/libdes/asm/win32.asm | 3 +- crypto/libdes/cbc3_enc.c | 14 +++--- crypto/libdes/des.c | 8 +-- crypto/libdes/des.h | 30 ++++++++--- crypto/libdes/des.org | 12 +++-- crypto/libdes/des_enc.c | 3 +- crypto/libdes/des_locl.h | 16 ++---- crypto/libdes/des_locl.org | 20 +++----- crypto/libdes/des_ver.h | 7 +-- crypto/libdes/ecb_enc.c | 7 +-- crypto/libdes/ede_enc.c | 12 +++-- crypto/libdes/enc_read.c | 97 ++++++++++++++++++++---------------- crypto/libdes/enc_writ.c | 72 ++++++++++++++------------ crypto/libdes/fcrypt.c | 61 ++++++++++++++++++++++- crypto/libdes/rand_key.c | 3 ++ crypto/libdes/read_pwd.c | 18 +------ crypto/libdes/rnd_keys.c | 80 ++++------------------------- crypto/libdes/set_key.c | 4 +- crypto/libdes/spr.h | 4 +- crypto/libdes/str2key.c | 4 +- crypto/libdes/version.h | 8 +-- 22 files changed, 259 insertions(+), 227 deletions(-) diff --git a/crypto/libdes/asm/dx86-cpp.s b/crypto/libdes/asm/dx86-cpp.s index 27d6ceea276..4741452640d 100644 --- a/crypto/libdes/asm/dx86-cpp.s +++ b/crypto/libdes/asm/dx86-cpp.s @@ -3,9 +3,10 @@ /* Which is a perl program used to generate the x86 assember for */ /* any of elf, a.out, Win32, or Solaris */ /* It can be found in SSLeay 0.6.5+ or in libdes 3.26+ */ - /* eric */ + /* eric */ /* The inner loop instruction sequence and the IP/FP modifications */ /* are from Svend Olaf Mikkelsen */ + /* $FreeBSD$ */ .file "dx86xxxx.s" .version "01.01" diff --git a/crypto/libdes/asm/win32.asm b/crypto/libdes/asm/win32.asm index 29c915f78f2..508b51148e2 100644 --- a/crypto/libdes/asm/win32.asm +++ b/crypto/libdes/asm/win32.asm @@ -3,9 +3,10 @@ ; Which is a perl program used to generate the x86 assember for ; any of elf, a.out, Win32, or Solaris ; It can be found in SSLeay 0.6.5+ or in libdes 3.26+ - ; eric + ; eric ; The inner loop instruction sequence and the IP/FP modifications ; are from Svend Olaf Mikkelsen + ; $FreeBSD$ ; TITLE dx86xxxx.asm diff --git a/crypto/libdes/cbc3_enc.c b/crypto/libdes/cbc3_enc.c index 3863a676d41..a96f23c5d27 100644 --- a/crypto/libdes/cbc3_enc.c +++ b/crypto/libdes/cbc3_enc.c @@ -54,6 +54,8 @@ * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] + * + * $FreeBSD$ */ #include "des_locl.h" @@ -69,11 +71,11 @@ void des_3cbc_encrypt(des_cblock *input, des_cblock *output, long length, if (enc == DES_ENCRYPT) { - des_cbc_encrypt(input,output,length,ks1,iv1,enc); + des_cbc_encrypt((void*)input,(void*)output,length,ks1,iv1,enc); if (length >= sizeof(des_cblock)) memcpy(niv1,output[off],sizeof(des_cblock)); - des_cbc_encrypt(output,output,l8,ks2,iv1,!enc); - des_cbc_encrypt(output,output,l8,ks1,iv2, enc); + des_cbc_encrypt((void*)output,(void*)output,l8,ks2,iv1,!enc); + des_cbc_encrypt((void*)output,(void*)output,l8,ks1,iv2, enc); if (length >= sizeof(des_cblock)) memcpy(niv2,output[off],sizeof(des_cblock)); } @@ -81,11 +83,11 @@ void des_3cbc_encrypt(des_cblock *input, des_cblock *output, long length, { if (length >= sizeof(des_cblock)) memcpy(niv2,input[off],sizeof(des_cblock)); - des_cbc_encrypt(input,output,l8,ks1,iv2,enc); - des_cbc_encrypt(output,output,l8,ks2,iv1,!enc); + des_cbc_encrypt((void*)input,(void*)output,l8,ks1,iv2,enc); + des_cbc_encrypt((void*)output,(void*)output,l8,ks2,iv1,!enc); if (length >= sizeof(des_cblock)) memcpy(niv1,output[off],sizeof(des_cblock)); - des_cbc_encrypt(output,output,length,ks1,iv1, enc); + des_cbc_encrypt((void*)output,(void*)output,length,ks1,iv1, enc); } memcpy(*iv1,niv1,sizeof(des_cblock)); memcpy(*iv2,niv2,sizeof(des_cblock)); diff --git a/crypto/libdes/des.c b/crypto/libdes/des.c index b2d7f0da783..eafadbcda21 100644 --- a/crypto/libdes/des.c +++ b/crypto/libdes/des.c @@ -54,6 +54,8 @@ * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] + * + * $FreeBSD$ */ #include @@ -377,8 +379,8 @@ void doencryption(void) if (buf == NULL) { - if ( (( buf=Malloc(BUFSIZE+8)) == NULL) || - ((obuf=Malloc(BUFSIZE+8)) == NULL)) + if ( (( buf=malloc(BUFSIZE+8)) == NULL) || + ((obuf=malloc(BUFSIZE+8)) == NULL)) { fputs("Not enough memory\n",stderr); Exit=10; @@ -484,7 +486,7 @@ void doencryption(void) if (feof(DES_IN)) { for (i=7-rem; i>0; i--) - RAND_bytes(buf + l++, 1); + des_rand_data(buf + l++, 1); buf[l++]=rem; ex=1; len+=rem; diff --git a/crypto/libdes/des.h b/crypto/libdes/des.h index 67f90aaf172..4f451dc27de 100644 --- a/crypto/libdes/des.h +++ b/crypto/libdes/des.h @@ -54,6 +54,8 @@ * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] + * + * $FreeBSD$ */ #ifndef HEADER_DES_H @@ -67,13 +69,17 @@ extern "C" { #error DES is disabled. #endif -#ifdef _KERBEROS_DES_H -#error replaces . +/* If this is set to 'unsigned int' on a DEC Alpha, this gives about a + * %20 speed up (longs are 8 bytes, int's are 4). */ +#ifndef DES_LONG +#if defined(__alpha) || defined(__sparcv9) +#define DES_LONG unsigned int +#else /* Not a 64 bit machine */ +#define DES_LONG unsigned long +#endif #endif #include -#include /* DES_LONG */ -#include /* OPENSSL_EXTERN */ typedef unsigned char des_cblock[8]; typedef /* const */ unsigned char const_des_cblock[8]; @@ -115,9 +121,16 @@ typedef struct des_ks_struct #define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \ des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n)) -OPENSSL_EXTERN int des_check_key; /* defaults to false */ -OPENSSL_EXTERN int des_rw_mode; /* defaults to DES_PCBC_MODE */ -OPENSSL_EXTERN int des_set_weak_key_flag; /* set the weak key flag */ +extern int des_check_key; /* defaults to false */ +extern int des_rw_mode; /* defaults to DES_PCBC_MODE */ +extern int des_set_weak_key_flag; /* set the weak key flag */ + +#define C_Block des_cblock +#define Key_schedule des_key_schedule +#ifdef KERBEROS +#define ENCRYPT DES_ENCRYPT +#define DECRYPT DES_DECRYPT +#endif const char *des_options(void); void des_ecb3_encrypt(const_des_cblock *input, des_cblock *output, @@ -187,6 +200,8 @@ DES_LONG des_quad_cksum(const unsigned char *input,des_cblock output[], long length,int out_count,des_cblock *seed); void des_random_seed(des_cblock *key); void des_random_key(des_cblock *ret); +void des_init_random_number_generator(des_cblock *seed); +void des_rand_data(unsigned char *data, int size); int des_read_password(des_cblock *key,const char *prompt,int verify); int des_read_2passwords(des_cblock *key1,des_cblock *key2, const char *prompt,int verify); @@ -205,6 +220,7 @@ void des_ofb64_encrypt(const unsigned char *in,unsigned char *out,long length, int des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify); /* Extra functions from Mark Murray */ +int des_new_random_key(des_cblock *key); void des_cblock_print_file(const_des_cblock *cb, FILE *fp); /* The following definitions provide compatibility with the MIT Kerberos diff --git a/crypto/libdes/des.org b/crypto/libdes/des.org index c1eef51bfe7..4743b9def3e 100644 --- a/crypto/libdes/des.org +++ b/crypto/libdes/des.org @@ -1,9 +1,9 @@ /* crypto/des/des.h */ -/* Copyright (C) 1995-1997 Eric Young (eay@mincom.oz.au) +/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written - * by Eric Young (eay@mincom.oz.au). + * by Eric Young (eay@cryptsoft.com). * The implementation was written so as to conform with Netscapes SSL. * * This library is free for commercial and non-commercial use as long as @@ -11,7 +11,7 @@ * apply to all code found in this distribution, be it the RC4, RSA, * lhash, DES, etc., code; not just the SSL code. The SSL documentation * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@mincom.oz.au). + * except that the holder is Tim Hudson (tjh@cryptsoft.com). * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. @@ -31,12 +31,12 @@ * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * "This product includes cryptographic software written by - * Eric Young (eay@mincom.oz.au)" + * Eric Young (eay@cryptsoft.com)" * The word 'cryptographic' can be left out if the rouines from the library * being used are not cryptographic related :-). * 4. If you include any Windows specific code (or a derivative thereof) from * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@mincom.oz.au)" + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -54,6 +54,8 @@ * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] + * + * $FreeBSD$ */ #ifndef HEADER_DES_H diff --git a/crypto/libdes/des_enc.c b/crypto/libdes/des_enc.c index 8311e106281..ed42ab6f34b 100644 --- a/crypto/libdes/des_enc.c +++ b/crypto/libdes/des_enc.c @@ -54,6 +54,8 @@ * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] + * + * $FreeBSD$ */ #include "des_locl.h" @@ -290,7 +292,6 @@ void des_decrypt3(DES_LONG *data, des_key_schedule ks1, des_key_schedule ks2, #ifndef DES_DEFAULT_OPTIONS #undef CBC_ENC_C__DONT_UPDATE_IV -#include "ncbc_enc.c" /* des_ncbc_encrypt */ void des_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output, long length, des_key_schedule ks1, des_key_schedule ks2, diff --git a/crypto/libdes/des_locl.h b/crypto/libdes/des_locl.h index d6ea17cb681..8514cd60ea2 100644 --- a/crypto/libdes/des_locl.h +++ b/crypto/libdes/des_locl.h @@ -54,6 +54,8 @@ * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] + * + * $FreeBSD$ */ #ifndef HEADER_DES_LOCL_H @@ -68,16 +70,6 @@ #include #include -#include - -#ifndef MSDOS -#if !defined(VMS) || defined(__DECC) -#include OPENSSL_UNISTD -#include -#endif -#endif -#include - #ifdef MSDOS /* Visual C++ 2.1 (Windows NT/95) */ #include #include @@ -89,6 +81,8 @@ #include #endif +#include "des.h" + #define ITERATIONS 16 #define HALF_ITERATIONS 8 @@ -401,7 +395,7 @@ PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \ } -OPENSSL_EXTERN const DES_LONG des_SPtrans[8][64]; +extern const DES_LONG des_SPtrans[8][64]; void fcrypt_body(DES_LONG *out,des_key_schedule ks, DES_LONG Eswap0, DES_LONG Eswap1); diff --git a/crypto/libdes/des_locl.org b/crypto/libdes/des_locl.org index 3853ddc8346..844d7654162 100644 --- a/crypto/libdes/des_locl.org +++ b/crypto/libdes/des_locl.org @@ -1,9 +1,9 @@ /* crypto/des/des_locl.h */ -/* Copyright (C) 1995-1997 Eric Young (eay@mincom.oz.au) +/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written - * by Eric Young (eay@mincom.oz.au). + * by Eric Young (eay@cryptsoft.com). * The implementation was written so as to conform with Netscapes SSL. * * This library is free for commercial and non-commercial use as long as @@ -11,7 +11,7 @@ * apply to all code found in this distribution, be it the RC4, RSA, * lhash, DES, etc., code; not just the SSL code. The SSL documentation * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@mincom.oz.au). + * except that the holder is Tim Hudson (tjh@cryptsoft.com). * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. @@ -31,12 +31,12 @@ * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * "This product includes cryptographic software written by - * Eric Young (eay@mincom.oz.au)" + * Eric Young (eay@cryptsoft.com)" * The word 'cryptographic' can be left out if the rouines from the library * being used are not cryptographic related :-). * 4. If you include any Windows specific code (or a derivative thereof) from * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@mincom.oz.au)" + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -54,14 +54,8 @@ * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] - */ - -/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING - * - * Always modify des_locl.org since des_locl.h is automatically generated from - * it during SSLeay configuration. - * - * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING + * + * $FreeBSD$ */ #ifndef HEADER_DES_LOCL_H diff --git a/crypto/libdes/des_ver.h b/crypto/libdes/des_ver.h index de3c02f110c..70477a71547 100644 --- a/crypto/libdes/des_ver.h +++ b/crypto/libdes/des_ver.h @@ -54,8 +54,9 @@ * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] + * + * $FreeBSD$ */ -#include -OPENSSL_EXTERN char *DES_version; /* SSLeay version string */ -OPENSSL_EXTERN char *libdes_version; /* old libdes version string */ +extern char *DES_version; /* SSLeay version string */ +extern char *libdes_version; /* old libdes version string */ diff --git a/crypto/libdes/ecb_enc.c b/crypto/libdes/ecb_enc.c index b261a8aad94..17e33faa29d 100644 --- a/crypto/libdes/ecb_enc.c +++ b/crypto/libdes/ecb_enc.c @@ -54,14 +54,15 @@ * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] + * + * $FreeBSD$ */ #include "des_locl.h" #include "spr.h" -#include -OPENSSL_GLOBAL const char *libdes_version="libdes" OPENSSL_VERSION_PTEXT; -OPENSSL_GLOBAL const char *DES_version="DES" OPENSSL_VERSION_PTEXT; +const char *libdes_version="libdes" " 0_9_4"; +const char *DES_version="DES" " 0_9_4"; const char *des_options(void) { diff --git a/crypto/libdes/ede_enc.c b/crypto/libdes/ede_enc.c index c62efac4e3c..50441db347e 100644 --- a/crypto/libdes/ede_enc.c +++ b/crypto/libdes/ede_enc.c @@ -1,9 +1,9 @@ /* crypto/des/ede_enc.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@mincom.oz.au) +/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written - * by Eric Young (eay@mincom.oz.au). + * by Eric Young (eay@cryptsoft.com). * The implementation was written so as to conform with Netscapes SSL. * * This library is free for commercial and non-commercial use as long as @@ -11,7 +11,7 @@ * apply to all code found in this distribution, be it the RC4, RSA, * lhash, DES, etc., code; not just the SSL code. The SSL documentation * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@mincom.oz.au). + * except that the holder is Tim Hudson (tjh@cryptsoft.com). * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. @@ -31,12 +31,12 @@ * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * "This product includes cryptographic software written by - * Eric Young (eay@mincom.oz.au)" + * Eric Young (eay@cryptsoft.com)" * The word 'cryptographic' can be left out if the rouines from the library * being used are not cryptographic related :-). * 4. If you include any Windows specific code (or a derivative thereof) from * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@mincom.oz.au)" + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -54,6 +54,8 @@ * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] + * + * $FreeBSD$ */ #include "des_locl.h" diff --git a/crypto/libdes/enc_read.c b/crypto/libdes/enc_read.c index ed3ee82f869..8bccda5aa26 100644 --- a/crypto/libdes/enc_read.c +++ b/crypto/libdes/enc_read.c @@ -1,9 +1,9 @@ /* crypto/des/enc_read.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@mincom.oz.au) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written - * by Eric Young (eay@mincom.oz.au). + * by Eric Young (eay@cryptsoft.com). * The implementation was written so as to conform with Netscapes SSL. * * This library is free for commercial and non-commercial use as long as @@ -11,7 +11,7 @@ * apply to all code found in this distribution, be it the RC4, RSA, * lhash, DES, etc., code; not just the SSL code. The SSL documentation * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@mincom.oz.au). + * except that the holder is Tim Hudson (tjh@cryptsoft.com). * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. @@ -31,12 +31,12 @@ * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * "This product includes cryptographic software written by - * Eric Young (eay@mincom.oz.au)" + * Eric Young (eay@cryptsoft.com)" * The word 'cryptographic' can be left out if the rouines from the library * being used are not cryptographic related :-). * 4. If you include any Windows specific code (or a derivative thereof) from * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@mincom.oz.au)" + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -54,26 +54,41 @@ * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] + * + * $FreeBSD$ */ #include #include #include #include -#include +#include #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); +/* + * 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) { /* data to be unencrypted */ int net_num=0; @@ -81,27 +96,27 @@ des_cblock (*iv); /* 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=malloc(BSIZE); if (tmpbuf == NULL) return(-1); } if (net == NULL) { - net=(unsigned char *)malloc(BSIZE); + net=malloc(BSIZE); if (net == NULL) return(-1); } if (unnet == NULL) { - unnet=(char *)malloc(BSIZE); + unnet=malloc(BSIZE); if (unnet == NULL) return(-1); } /* left over data from last decrypt */ @@ -113,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; @@ -121,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; @@ -135,8 +150,10 @@ des_cblock (*iv); /* first - get the length */ while (net_num < HDRSIZE) { - i=read(fd,&(net[net_num]),(unsigned int)HDRSIZE-net_num); + i=read(fd,&(net[net_num]),HDRSIZE-net_num); +#ifdef EINTR if ((i == -1) && (errno == EINTR)) continue; +#endif if (i <= 0) return(0); net_num+=i; } @@ -155,8 +172,10 @@ des_cblock (*iv); net_num=0; while (net_num < rnum) { - i=read(fd,&(net[net_num]),(unsigned int)rnum-net_num); + i=read(fd,&(net[net_num]),rnum-net_num); +#ifdef EINTR if ((i == -1) && (errno == EINTR)) continue; +#endif if (i <= 0) return(0); net_num+=i; } @@ -165,14 +184,12 @@ des_cblock (*iv); if (len < num) { if (des_rw_mode & DES_PCBC_MODE) - des_pcbc_encrypt((des_cblock *)net,(des_cblock *)unnet, - num,sched,iv,DES_DECRYPT); + 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. */ @@ -189,30 +206,26 @@ des_cblock (*iv); { if (des_rw_mode & DES_PCBC_MODE) - des_pcbc_encrypt((des_cblock *)net, - (des_cblock *)tmpbuf, - num,sched,iv,DES_DECRYPT); + 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); + 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; } diff --git a/crypto/libdes/enc_writ.c b/crypto/libdes/enc_writ.c index 128b151a639..302baaa8c87 100644 --- a/crypto/libdes/enc_writ.c +++ b/crypto/libdes/enc_writ.c @@ -1,9 +1,9 @@ /* crypto/des/enc_writ.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@mincom.oz.au) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written - * by Eric Young (eay@mincom.oz.au). + * by Eric Young (eay@cryptsoft.com). * The implementation was written so as to conform with Netscapes SSL. * * This library is free for commercial and non-commercial use as long as @@ -11,7 +11,7 @@ * apply to all code found in this distribution, be it the RC4, RSA, * lhash, DES, etc., code; not just the SSL code. The SSL documentation * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@mincom.oz.au). + * except that the holder is Tim Hudson (tjh@cryptsoft.com). * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. @@ -31,12 +31,12 @@ * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * "This product includes cryptographic software written by - * Eric Young (eay@mincom.oz.au)" + * Eric Young (eay@cryptsoft.com)" * The word 'cryptographic' can be left out if the rouines from the library * being used are not cryptographic related :-). * 4. If you include any Windows specific code (or a derivative thereof) from * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@mincom.oz.au)" + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -54,40 +54,52 @@ * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] + * + * $FreeBSD$ */ #include #include #include +#include #include #include #include "des_locl.h" -int des_enc_write(fd, buf, len, sched, iv) -int fd; -char *buf; -int len; -des_key_schedule sched; -des_cblock (*iv); +/* + * 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. + */ + +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; - char *outbuf=NULL; - char shortbuf[8]; - char *p; + 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=malloc(BSIZE+HDRSIZE); if (outbuf == NULL) return(-1); } /* If we are sending less than 8 bytes, the same char will look @@ -95,7 +107,6 @@ des_cblock (*iv); if (start) { start=0; - srandom((unsigned int)time(NULL)); } /* lets recurse if we want to send the data in small chunks */ @@ -121,35 +132,32 @@ des_cblock (*iv); /* pad short strings */ if (len < 8) { - p=shortbuf; - memcpy(shortbuf,buf,(unsigned int)len); - for (i=len; i<8; i++) - shortbuf[i]=random(); + cp=shortbuf; + memcpy(shortbuf,buf,len); + des_rand_data(shortbuf+len, 8-len); rnum=8; } else { - p=buf; + cp=(unsigned char*)buf; rnum=((len+7)/8*8); /* round up to nearest eight */ } if (des_rw_mode & DES_PCBC_MODE) - des_pcbc_encrypt((des_cblock *)p, - (des_cblock *)&(outbuf[HDRSIZE]), - (long)((len<8)?8:len),sched,iv,DES_ENCRYPT); + des_pcbc_encrypt(cp,&(outbuf[HDRSIZE]),(len<8)?8:len,sched,iv, + DES_ENCRYPT); else - des_cbc_encrypt((des_cblock *)p, - (des_cblock *)&(outbuf[HDRSIZE]), - (long)((len<8)?8:len),sched,iv,DES_ENCRYPT); + des_cbc_encrypt(cp,&(outbuf[HDRSIZE]),(len<8)?8:len,sched,iv, + DES_ENCRYPT); /* output */ - outnum=(int)rnum+HDRSIZE; + outnum=rnum+HDRSIZE; for (j=0; j #ifdef _OSD_POSIX #ifndef CHARSET_EBCDIC diff --git a/crypto/libdes/rand_key.c b/crypto/libdes/rand_key.c index fc11792cdaa..4e89dbcaeb4 100644 --- a/crypto/libdes/rand_key.c +++ b/crypto/libdes/rand_key.c @@ -54,10 +54,13 @@ * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] + * + * $FreeBSD$ */ #include "des_locl.h" #include +#include static int seed=0; static des_cblock init; diff --git a/crypto/libdes/read_pwd.c b/crypto/libdes/read_pwd.c index fed49652c0d..29d60a108fb 100644 --- a/crypto/libdes/read_pwd.c +++ b/crypto/libdes/read_pwd.c @@ -54,23 +54,10 @@ * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] + * + * $FreeBSD$ */ -#if !defined(MSDOS) && !defined(VMS) && !defined(WIN32) -#include -#include OPENSSL_UNISTD -/* If unistd.h defines _POSIX_VERSION, we conclude that we - * are on a POSIX system and have sigaction and termios. */ -#if defined(_POSIX_VERSION) - -# define SIGACTION -# if !defined(TERMIOS) && !defined(TERMIO) && !defined(SGTTY) -# define TERMIOS -# endif - -#endif -#endif - /* #define SIGACTION */ /* Define this if you have sigaction() */ #ifdef WIN16TTY @@ -81,7 +68,6 @@ /* 06-Apr-92 Luke Brennan Support for VMS */ #include "des_locl.h" -#include "cryptlib.h" #include #include #include diff --git a/crypto/libdes/rnd_keys.c b/crypto/libdes/rnd_keys.c index da86b8951b8..3acc9f85c8e 100644 --- a/crypto/libdes/rnd_keys.c +++ b/crypto/libdes/rnd_keys.c @@ -34,49 +34,22 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * + * $Id$ + * $FreeBSD$ */ -#ifdef HAVE_CONFIG_H -#include "config.h" - -RCSID("$Id$"); -#endif - #include +#include #include +#include #include #include #include #include #include #include - -#ifdef TIME_WITH_SYS_TIME -#include -#include -#elif defined(HAVE_SYS_TIME_H) -#include -#else -#include -#endif - -#ifdef HAVE_SYS_TYPES_H -#include -#endif - -#ifdef HAVE_UNISTD_H #include -#endif -#ifdef HAVE_IO_H -#include -#endif - -#ifdef HAVE_SIGNAL_H -#include -#endif -#ifdef HAVE_FCNTL_H -#include -#endif #ifdef HAVE_WINSOCK_H #include @@ -128,37 +101,6 @@ sumFile (const char *name, int len, void *res) return 0; } -#if 0 -static -int -md5sumFile (const char *name, int len, int32_t sum[4]) -{ - int32_t buf[1024*2]; - int fd, cnt; - struct md5 md5; - - fd = open (name, 0); - if (fd < 0) - return -1; - - md5_init(&md5); - while (len > 0) - { - int n = read(fd, buf, sizeof(buf)); - if (n < 0) - { - close(fd); - return n; - } - md5_update(&md5, buf, n); - len -= n; - } - md5_finito(&md5, (unsigned char *)sum); - close (fd); - return 0; -} -#endif - /* * Create a sequence of random 64 bit blocks. * The sequence is indexed with a long long and @@ -257,7 +199,10 @@ static RETSIGTYPE void des_rand_data(unsigned char *data, int size) { - struct itimerval tv, otv; + struct itimerval tv; +#ifdef HAVE_SETITIMER + struct itimerval otv; +#endif RETSIGTYPE (*osa)(int); int i, j; #ifndef HAVE_SETITIMER @@ -467,13 +412,6 @@ des_init_random_number_generator(des_cblock *seed) des_set_random_generator_seed(&new_key); } -/* This is for backwards compatibility. */ -void -des_random_key(des_cblock ret) -{ - des_new_random_key((des_cblock *)ret); -} - #ifdef TESTRUN int main() diff --git a/crypto/libdes/set_key.c b/crypto/libdes/set_key.c index 52553a4c166..f4ae6d7d8c0 100644 --- a/crypto/libdes/set_key.c +++ b/crypto/libdes/set_key.c @@ -54,6 +54,8 @@ * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] + * + * $FreeBSD$ */ /* set_key.c v 1.4 eay 24/9/91 @@ -68,7 +70,7 @@ #include "sk.h" static int check_parity(const_des_cblock *key); -OPENSSL_GLOBAL int des_check_key=0; +int des_check_key=0; void des_set_odd_parity(des_cblock *key) { diff --git a/crypto/libdes/spr.h b/crypto/libdes/spr.h index b8fbdcf8d32..0200b5e0b04 100644 --- a/crypto/libdes/spr.h +++ b/crypto/libdes/spr.h @@ -54,9 +54,11 @@ * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] + * + * $FreeBSD$ */ -OPENSSL_GLOBAL const DES_LONG des_SPtrans[8][64]={ +const DES_LONG des_SPtrans[8][64]={ { /* nibble 0 */ 0x02080800L, 0x00080000L, 0x02000002L, 0x02080802L, diff --git a/crypto/libdes/str2key.c b/crypto/libdes/str2key.c index 24841452f1f..afdf59a144e 100644 --- a/crypto/libdes/str2key.c +++ b/crypto/libdes/str2key.c @@ -54,11 +54,13 @@ * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] + * + * $FreeBSD$ */ #include "des_locl.h" -OPENSSL_EXTERN int des_check_key; +extern int des_check_key; void des_string_to_key(const char *str, des_cblock *key) { diff --git a/crypto/libdes/version.h b/crypto/libdes/version.h index aee11903f30..0088f422369 100644 --- a/crypto/libdes/version.h +++ b/crypto/libdes/version.h @@ -1,9 +1,9 @@ /* lib/des/version.h */ -/* Copyright (C) 1995 Eric Young (eay@mincom.oz.au) +/* Copyright (C) 1995 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This file is part of an SSL implementation written - * by Eric Young (eay@mincom.oz.au). + * by Eric Young (eay@cryptsoft.com). * The implementation was written so as to conform with Netscapes SSL * specification. This library and applications are * FREE FOR COMMERCIAL AND NON-COMMERCIAL USE @@ -25,7 +25,7 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by Eric Young (eay@mincom.oz.au) + * This product includes software developed by Eric Young (eay@cryptsoft.com) * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -43,6 +43,8 @@ * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] + * + * $FreeBSD$ */ extern char *DES_version; -- 2.45.2