From ae5c8664e587f2445c8e4eb436cffbb64af4f6b8 Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Thu, 22 Jan 2015 03:29:12 +0000 Subject: Run util/openssl-format-source -v -c . Reviewed-by: Tim Hudson --- crypto/des/cbc3_enc.c | 80 +-- crypto/des/cbc_cksm.c | 97 ++- crypto/des/cbc_enc.c | 14 +- crypto/des/cfb64ede.c | 363 +++++----- crypto/des/cfb64enc.c | 127 ++-- crypto/des/cfb_enc.c | 244 +++---- crypto/des/des.c | 1563 ++++++++++++++++++++--------------------- crypto/des/des.h | 315 +++++---- crypto/des/des_enc.c | 611 ++++++++-------- crypto/des/des_locl.h | 720 +++++++++---------- crypto/des/des_old.c | 443 +++++++----- crypto/des/des_old.h | 654 +++++++++-------- crypto/des/des_old2.c | 36 +- crypto/des/des_opts.c | 913 ++++++++++++------------ crypto/des/des_ver.h | 12 +- crypto/des/destest.c | 1699 ++++++++++++++++++++++----------------------- crypto/des/ecb3_enc.c | 53 +- crypto/des/ecb_enc.c | 100 +-- crypto/des/ede_cbcm_enc.c | 250 ++++--- crypto/des/enc_read.c | 320 +++++---- crypto/des/enc_writ.c | 188 +++-- crypto/des/fcrypt.c | 265 ++++--- crypto/des/fcrypt_b.c | 123 ++-- crypto/des/ncbc_enc.c | 162 ++--- crypto/des/ofb64ede.c | 126 ++-- crypto/des/ofb64enc.c | 105 ++- crypto/des/ofb_enc.c | 146 ++-- crypto/des/pcbc_enc.c | 124 ++-- crypto/des/qud_cksm.c | 136 ++-- crypto/des/rand_key.c | 19 +- crypto/des/read2pwd.c | 54 +- crypto/des/read_pwd.c | 723 +++++++++---------- crypto/des/rpc_des.h | 61 +- crypto/des/rpc_enc.c | 72 +- crypto/des/rpw.c | 75 +- crypto/des/set_key.c | 636 +++++++++-------- crypto/des/speed.c | 349 +++++----- crypto/des/spr.h | 321 +++++---- crypto/des/str2key.c | 192 +++-- crypto/des/xcbc_enc.c | 279 ++++---- 40 files changed, 6428 insertions(+), 6342 deletions(-) (limited to 'crypto/des') diff --git a/crypto/des/cbc3_enc.c b/crypto/des/cbc3_enc.c index b5db4e14f7..249518a6a6 100644 --- a/crypto/des/cbc3_enc.c +++ b/crypto/des/cbc3_enc.c @@ -5,21 +5,21 @@ * This package is an SSL implementation written * 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 * the following conditions are aheared to. The following conditions * 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@cryptsoft.com). - * + * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. * If this package is used in a product, Eric Young should be given attribution * as the author of the parts of the library used. * This can be in the form of a textual message at program startup or * in documentation (online or textual) provided with the package. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -34,10 +34,10 @@ * 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 + * 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@cryptsoft.com)" - * + * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -49,7 +49,7 @@ * 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. - * + * * The licence and distribution terms for any publically available version or * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence @@ -60,40 +60,36 @@ /* HAS BUGS! DON'T USE - this is only present for use in des.c */ void DES_3cbc_encrypt(DES_cblock *input, DES_cblock *output, long length, - DES_key_schedule ks1, DES_key_schedule ks2, DES_cblock *iv1, - DES_cblock *iv2, int enc) - { - int off=((int)length-1)/8; - long l8=((length+7)/8)*8; - DES_cblock niv1,niv2; - - if (enc == DES_ENCRYPT) - { - DES_cbc_encrypt((unsigned char*)input, - (unsigned char*)output,length,&ks1,iv1,enc); - if (length >= sizeof(DES_cblock)) - memcpy(niv1,output[off],sizeof(DES_cblock)); - DES_cbc_encrypt((unsigned char*)output, - (unsigned char*)output,l8,&ks2,iv1,!enc); - DES_cbc_encrypt((unsigned char*)output, - (unsigned char*)output,l8,&ks1,iv2,enc); - if (length >= sizeof(DES_cblock)) - memcpy(niv2,output[off],sizeof(DES_cblock)); - } - else - { - if (length >= sizeof(DES_cblock)) - memcpy(niv2,input[off],sizeof(DES_cblock)); - DES_cbc_encrypt((unsigned char*)input, - (unsigned char*)output,l8,&ks1,iv2,enc); - DES_cbc_encrypt((unsigned char*)output, - (unsigned char*)output,l8,&ks2,iv1,!enc); - if (length >= sizeof(DES_cblock)) - memcpy(niv1,output[off],sizeof(DES_cblock)); - DES_cbc_encrypt((unsigned char*)output, - (unsigned char*)output,length,&ks1,iv1,enc); - } - memcpy(*iv1,niv1,sizeof(DES_cblock)); - memcpy(*iv2,niv2,sizeof(DES_cblock)); - } + DES_key_schedule ks1, DES_key_schedule ks2, + DES_cblock *iv1, DES_cblock *iv2, int enc) +{ + int off = ((int)length - 1) / 8; + long l8 = ((length + 7) / 8) * 8; + DES_cblock niv1, niv2; + if (enc == DES_ENCRYPT) { + DES_cbc_encrypt((unsigned char *)input, + (unsigned char *)output, length, &ks1, iv1, enc); + if (length >= sizeof(DES_cblock)) + memcpy(niv1, output[off], sizeof(DES_cblock)); + DES_cbc_encrypt((unsigned char *)output, + (unsigned char *)output, l8, &ks2, iv1, !enc); + DES_cbc_encrypt((unsigned char *)output, + (unsigned char *)output, l8, &ks1, iv2, enc); + if (length >= sizeof(DES_cblock)) + memcpy(niv2, output[off], sizeof(DES_cblock)); + } else { + if (length >= sizeof(DES_cblock)) + memcpy(niv2, input[off], sizeof(DES_cblock)); + DES_cbc_encrypt((unsigned char *)input, + (unsigned char *)output, l8, &ks1, iv2, enc); + DES_cbc_encrypt((unsigned char *)output, + (unsigned char *)output, l8, &ks2, iv1, !enc); + if (length >= sizeof(DES_cblock)) + memcpy(niv1, output[off], sizeof(DES_cblock)); + DES_cbc_encrypt((unsigned char *)output, + (unsigned char *)output, length, &ks1, iv1, enc); + } + memcpy(*iv1, niv1, sizeof(DES_cblock)); + memcpy(*iv2, niv2, sizeof(DES_cblock)); +} diff --git a/crypto/des/cbc_cksm.c b/crypto/des/cbc_cksm.c index 09a7ba56aa..f89b5b98e4 100644 --- a/crypto/des/cbc_cksm.c +++ b/crypto/des/cbc_cksm.c @@ -5,21 +5,21 @@ * This package is an SSL implementation written * 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 * the following conditions are aheared to. The following conditions * 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@cryptsoft.com). - * + * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. * If this package is used in a product, Eric Young should be given attribution * as the author of the parts of the library used. * This can be in the form of a textual message at program startup or * in documentation (online or textual) provided with the package. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -34,10 +34,10 @@ * 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 + * 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@cryptsoft.com)" - * + * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -49,7 +49,7 @@ * 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. - * + * * The licence and distribution terms for any publically available version or * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence @@ -59,48 +59,45 @@ #include "des_locl.h" DES_LONG DES_cbc_cksum(const unsigned char *in, DES_cblock *output, - long length, DES_key_schedule *schedule, - const_DES_cblock *ivec) - { - register DES_LONG tout0,tout1,tin0,tin1; - register long l=length; - DES_LONG tin[2]; - unsigned char *out = &(*output)[0]; - const unsigned char *iv = &(*ivec)[0]; + long length, DES_key_schedule *schedule, + const_DES_cblock *ivec) +{ + register DES_LONG tout0, tout1, tin0, tin1; + register long l = length; + DES_LONG tin[2]; + unsigned char *out = &(*output)[0]; + const unsigned char *iv = &(*ivec)[0]; + + c2l(iv, tout0); + c2l(iv, tout1); + for (; l > 0; l -= 8) { + if (l >= 8) { + c2l(in, tin0); + c2l(in, tin1); + } else + c2ln(in, tin0, tin1, l); - c2l(iv,tout0); - c2l(iv,tout1); - for (; l>0; l-=8) - { - if (l >= 8) - { - c2l(in,tin0); - c2l(in,tin1); - } - else - c2ln(in,tin0,tin1,l); - - tin0^=tout0; tin[0]=tin0; - tin1^=tout1; tin[1]=tin1; - DES_encrypt1((DES_LONG *)tin,schedule,DES_ENCRYPT); - /* fix 15/10/91 eay - thanks to keithr@sco.COM */ - tout0=tin[0]; - tout1=tin[1]; - } - if (out != NULL) - { - l2c(tout0,out); - l2c(tout1,out); - } - tout0=tin0=tin1=tin[0]=tin[1]=0; - /* - Transform the data in tout1 so that it will - match the return value that the MIT Kerberos - mit_des_cbc_cksum API returns. - */ - tout1 = ((tout1 >> 24L) & 0x000000FF) - | ((tout1 >> 8L) & 0x0000FF00) - | ((tout1 << 8L) & 0x00FF0000) - | ((tout1 << 24L) & 0xFF000000); - return(tout1); - } + tin0 ^= tout0; + tin[0] = tin0; + tin1 ^= tout1; + tin[1] = tin1; + DES_encrypt1((DES_LONG *)tin, schedule, DES_ENCRYPT); + /* fix 15/10/91 eay - thanks to keithr@sco.COM */ + tout0 = tin[0]; + tout1 = tin[1]; + } + if (out != NULL) { + l2c(tout0, out); + l2c(tout1, out); + } + tout0 = tin0 = tin1 = tin[0] = tin[1] = 0; + /* + * Transform the data in tout1 so that it will match the return value + * that the MIT Kerberos mit_des_cbc_cksum API returns. + */ + tout1 = ((tout1 >> 24L) & 0x000000FF) + | ((tout1 >> 8L) & 0x0000FF00) + | ((tout1 << 8L) & 0x00FF0000) + | ((tout1 << 24L) & 0xFF000000); + return (tout1); +} diff --git a/crypto/des/cbc_enc.c b/crypto/des/cbc_enc.c index 677903ae4e..7ee359928c 100644 --- a/crypto/des/cbc_enc.c +++ b/crypto/des/cbc_enc.c @@ -5,21 +5,21 @@ * This package is an SSL implementation written * 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 * the following conditions are aheared to. The following conditions * 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@cryptsoft.com). - * + * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. * If this package is used in a product, Eric Young should be given attribution * as the author of the parts of the library used. * This can be in the form of a textual message at program startup or * in documentation (online or textual) provided with the package. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -34,10 +34,10 @@ * 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 + * 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@cryptsoft.com)" - * + * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -49,7 +49,7 @@ * 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. - * + * * The licence and distribution terms for any publically available version or * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence @@ -58,4 +58,4 @@ #define CBC_ENC_C__DONT_UPDATE_IV -#include "ncbc_enc.c" /* des_cbc_encrypt */ +#include "ncbc_enc.c" /* des_cbc_encrypt */ diff --git a/crypto/des/cfb64ede.c b/crypto/des/cfb64ede.c index de34ecceb9..5d709c12d3 100644 --- a/crypto/des/cfb64ede.c +++ b/crypto/des/cfb64ede.c @@ -5,21 +5,21 @@ * This package is an SSL implementation written * 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 * the following conditions are aheared to. The following conditions * 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@cryptsoft.com). - * + * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. * If this package is used in a product, Eric Young should be given attribution * as the author of the parts of the library used. * This can be in the form of a textual message at program startup or * in documentation (online or textual) provided with the package. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -34,10 +34,10 @@ * 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 + * 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@cryptsoft.com)" - * + * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -49,7 +49,7 @@ * 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. - * + * * The licence and distribution terms for any publically available version or * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence @@ -59,196 +59,191 @@ #include "des_locl.h" #include "e_os.h" -/* The input and output encrypted as though 64bit cfb mode is being - * used. The extra state information to record how much of the - * 64bit block we have used is contained in *num; +/* + * The input and output encrypted as though 64bit cfb mode is being used. + * The extra state information to record how much of the 64bit block we have + * used is contained in *num; */ void DES_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out, - long length, DES_key_schedule *ks1, - DES_key_schedule *ks2, DES_key_schedule *ks3, - DES_cblock *ivec, int *num, int enc) - { - register DES_LONG v0,v1; - register long l=length; - register int n= *num; - DES_LONG ti[2]; - unsigned char *iv,c,cc; + long length, DES_key_schedule *ks1, + DES_key_schedule *ks2, DES_key_schedule *ks3, + DES_cblock *ivec, int *num, int enc) +{ + register DES_LONG v0, v1; + register long l = length; + register int n = *num; + DES_LONG ti[2]; + unsigned char *iv, c, cc; - iv=&(*ivec)[0]; - if (enc) - { - while (l--) - { - if (n == 0) - { - c2l(iv,v0); - c2l(iv,v1); + iv = &(*ivec)[0]; + if (enc) { + while (l--) { + if (n == 0) { + c2l(iv, v0); + c2l(iv, v1); - ti[0]=v0; - ti[1]=v1; - DES_encrypt3(ti,ks1,ks2,ks3); - v0=ti[0]; - v1=ti[1]; + ti[0] = v0; + ti[1] = v1; + DES_encrypt3(ti, ks1, ks2, ks3); + v0 = ti[0]; + v1 = ti[1]; - iv = &(*ivec)[0]; - l2c(v0,iv); - l2c(v1,iv); - iv = &(*ivec)[0]; - } - c= *(in++)^iv[n]; - *(out++)=c; - iv[n]=c; - n=(n+1)&0x07; - } - } - else - { - while (l--) - { - if (n == 0) - { - c2l(iv,v0); - c2l(iv,v1); + iv = &(*ivec)[0]; + l2c(v0, iv); + l2c(v1, iv); + iv = &(*ivec)[0]; + } + c = *(in++) ^ iv[n]; + *(out++) = c; + iv[n] = c; + n = (n + 1) & 0x07; + } + } else { + while (l--) { + if (n == 0) { + c2l(iv, v0); + c2l(iv, v1); - ti[0]=v0; - ti[1]=v1; - DES_encrypt3(ti,ks1,ks2,ks3); - v0=ti[0]; - v1=ti[1]; + ti[0] = v0; + ti[1] = v1; + DES_encrypt3(ti, ks1, ks2, ks3); + v0 = ti[0]; + v1 = ti[1]; - iv = &(*ivec)[0]; - l2c(v0,iv); - l2c(v1,iv); - iv = &(*ivec)[0]; - } - cc= *(in++); - c=iv[n]; - iv[n]=cc; - *(out++)=c^cc; - n=(n+1)&0x07; - } - } - v0=v1=ti[0]=ti[1]=c=cc=0; - *num=n; - } + iv = &(*ivec)[0]; + l2c(v0, iv); + l2c(v1, iv); + iv = &(*ivec)[0]; + } + cc = *(in++); + c = iv[n]; + iv[n] = cc; + *(out++) = c ^ cc; + n = (n + 1) & 0x07; + } + } + v0 = v1 = ti[0] = ti[1] = c = cc = 0; + *num = n; +} -#ifdef undef /* MACRO */ -void DES_ede2_cfb64_encrypt(unsigned char *in, unsigned char *out, long length, - DES_key_schedule ks1, DES_key_schedule ks2, DES_cblock (*ivec), - int *num, int enc) - { - DES_ede3_cfb64_encrypt(in,out,length,ks1,ks2,ks1,ivec,num,enc); - } +#ifdef undef /* MACRO */ +void DES_ede2_cfb64_encrypt(unsigned char *in, unsigned char *out, + long length, DES_key_schedule ks1, + DES_key_schedule ks2, DES_cblock (*ivec), + int *num, int enc) +{ + DES_ede3_cfb64_encrypt(in, out, length, ks1, ks2, ks1, ivec, num, enc); +} #endif -/* This is compatible with the single key CFB-r for DES, even thought that's +/* + * This is compatible with the single key CFB-r for DES, even thought that's * not what EVP needs. */ -void DES_ede3_cfb_encrypt(const unsigned char *in,unsigned char *out, - int numbits,long length,DES_key_schedule *ks1, - DES_key_schedule *ks2,DES_key_schedule *ks3, - DES_cblock *ivec,int enc) - { - register DES_LONG d0,d1,v0,v1; - register unsigned long l=length,n=((unsigned int)numbits+7)/8; - register int num=numbits,i; - DES_LONG ti[2]; - unsigned char *iv; - unsigned char ovec[16]; - - if (num > 64) return; - iv = &(*ivec)[0]; - c2l(iv,v0); - c2l(iv,v1); - if (enc) - { - while (l >= n) - { - l-=n; - ti[0]=v0; - ti[1]=v1; - DES_encrypt3(ti,ks1,ks2,ks3); - c2ln(in,d0,d1,n); - in+=n; - d0^=ti[0]; - d1^=ti[1]; - l2cn(d0,d1,out,n); - out+=n; - /* 30-08-94 - eay - changed because l>>32 and - * l<<32 are bad under gcc :-( */ - if (num == 32) - { v0=v1; v1=d0; } - else if (num == 64) - { v0=d0; v1=d1; } - else - { - iv=&ovec[0]; - l2c(v0,iv); - l2c(v1,iv); - l2c(d0,iv); - l2c(d1,iv); - /* shift ovec left most of the bits... */ - memmove(ovec,ovec+num/8,8+(num%8 ? 1 : 0)); - /* now the remaining bits */ - if(num%8 != 0) - for(i=0 ; i < 8 ; ++i) - { - ovec[i]<<=num%8; - ovec[i]|=ovec[i+1]>>(8-num%8); - } - iv=&ovec[0]; - c2l(iv,v0); - c2l(iv,v1); - } - } - } - else - { - while (l >= n) - { - l-=n; - ti[0]=v0; - ti[1]=v1; - DES_encrypt3(ti,ks1,ks2,ks3); - c2ln(in,d0,d1,n); - in+=n; - /* 30-08-94 - eay - changed because l>>32 and - * l<<32 are bad under gcc :-( */ - if (num == 32) - { v0=v1; v1=d0; } - else if (num == 64) - { v0=d0; v1=d1; } - else - { - iv=&ovec[0]; - l2c(v0,iv); - l2c(v1,iv); - l2c(d0,iv); - l2c(d1,iv); - /* shift ovec left most of the bits... */ - memmove(ovec,ovec+num/8,8+(num%8 ? 1 : 0)); - /* now the remaining bits */ - if(num%8 != 0) - for(i=0 ; i < 8 ; ++i) - { - ovec[i]<<=num%8; - ovec[i]|=ovec[i+1]>>(8-num%8); - } - iv=&ovec[0]; - c2l(iv,v0); - c2l(iv,v1); - } - d0^=ti[0]; - d1^=ti[1]; - l2cn(d0,d1,out,n); - out+=n; - } - } - iv = &(*ivec)[0]; - l2c(v0,iv); - l2c(v1,iv); - v0=v1=d0=d1=ti[0]=ti[1]=0; - } +void DES_ede3_cfb_encrypt(const unsigned char *in, unsigned char *out, + int numbits, long length, DES_key_schedule *ks1, + DES_key_schedule *ks2, DES_key_schedule *ks3, + DES_cblock *ivec, int enc) +{ + register DES_LONG d0, d1, v0, v1; + register unsigned long l = length, n = ((unsigned int)numbits + 7) / 8; + register int num = numbits, i; + DES_LONG ti[2]; + unsigned char *iv; + unsigned char ovec[16]; + if (num > 64) + return; + iv = &(*ivec)[0]; + c2l(iv, v0); + c2l(iv, v1); + if (enc) { + while (l >= n) { + l -= n; + ti[0] = v0; + ti[1] = v1; + DES_encrypt3(ti, ks1, ks2, ks3); + c2ln(in, d0, d1, n); + in += n; + d0 ^= ti[0]; + d1 ^= ti[1]; + l2cn(d0, d1, out, n); + out += n; + /* + * 30-08-94 - eay - changed because l>>32 and l<<32 are bad under + * gcc :-( + */ + if (num == 32) { + v0 = v1; + v1 = d0; + } else if (num == 64) { + v0 = d0; + v1 = d1; + } else { + iv = &ovec[0]; + l2c(v0, iv); + l2c(v1, iv); + l2c(d0, iv); + l2c(d1, iv); + /* shift ovec left most of the bits... */ + memmove(ovec, ovec + num / 8, 8 + (num % 8 ? 1 : 0)); + /* now the remaining bits */ + if (num % 8 != 0) + for (i = 0; i < 8; ++i) { + ovec[i] <<= num % 8; + ovec[i] |= ovec[i + 1] >> (8 - num % 8); + } + iv = &ovec[0]; + c2l(iv, v0); + c2l(iv, v1); + } + } + } else { + while (l >= n) { + l -= n; + ti[0] = v0; + ti[1] = v1; + DES_encrypt3(ti, ks1, ks2, ks3); + c2ln(in, d0, d1, n); + in += n; + /* + * 30-08-94 - eay - changed because l>>32 and l<<32 are bad under + * gcc :-( + */ + if (num == 32) { + v0 = v1; + v1 = d0; + } else if (num == 64) { + v0 = d0; + v1 = d1; + } else { + iv = &ovec[0]; + l2c(v0, iv); + l2c(v1, iv); + l2c(d0, iv); + l2c(d1, iv); + /* shift ovec left most of the bits... */ + memmove(ovec, ovec + num / 8, 8 + (num % 8 ? 1 : 0)); + /* now the remaining bits */ + if (num % 8 != 0) + for (i = 0; i < 8; ++i) { + ovec[i] <<= num % 8; + ovec[i] |= ovec[i + 1] >> (8 - num % 8); + } + iv = &ovec[0]; + c2l(iv, v0); + c2l(iv, v1); + } + d0 ^= ti[0]; + d1 ^= ti[1]; + l2cn(d0, d1, out, n); + out += n; + } + } + iv = &(*ivec)[0]; + l2c(v0, iv); + l2c(v1, iv); + v0 = v1 = d0 = d1 = ti[0] = ti[1] = 0; +} diff --git a/crypto/des/cfb64enc.c b/crypto/des/cfb64enc.c index 5ec8683e40..7346774eb2 100644 --- a/crypto/des/cfb64enc.c +++ b/crypto/des/cfb64enc.c @@ -5,21 +5,21 @@ * This package is an SSL implementation written * 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 * the following conditions are aheared to. The following conditions * 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@cryptsoft.com). - * + * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. * If this package is used in a product, Eric Young should be given attribution * as the author of the parts of the library used. * This can be in the form of a textual message at program startup or * in documentation (online or textual) provided with the package. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -34,10 +34,10 @@ * 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 + * 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@cryptsoft.com)" - * + * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -49,7 +49,7 @@ * 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. - * + * * The licence and distribution terms for any publically available version or * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence @@ -58,64 +58,65 @@ #include "des_locl.h" -/* The input and output encrypted as though 64bit cfb mode is being - * used. The extra state information to record how much of the - * 64bit block we have used is contained in *num; +/* + * The input and output encrypted as though 64bit cfb mode is being used. + * The extra state information to record how much of the 64bit block we have + * used is contained in *num; */ void DES_cfb64_encrypt(const unsigned char *in, unsigned char *out, - long length, DES_key_schedule *schedule, - DES_cblock *ivec, int *num, int enc) - { - register DES_LONG v0,v1; - register long l=length; - register int n= *num; - DES_LONG ti[2]; - unsigned char *iv,c,cc; - - iv = &(*ivec)[0]; - if (enc) - { - while (l--) - { - if (n == 0) - { - c2l(iv,v0); ti[0]=v0; - c2l(iv,v1); ti[1]=v1; - DES_encrypt1(ti,schedule,DES_ENCRYPT); - iv = &(*ivec)[0]; - v0=ti[0]; l2c(v0,iv); - v0=ti[1]; l2c(v0,iv); - iv = &(*ivec)[0]; - } - c= *(in++)^iv[n]; - *(out++)=c; - iv[n]=c; - n=(n+1)&0x07; - } - } - else - { - while (l--) - { - if (n == 0) - { - c2l(iv,v0); ti[0]=v0; - c2l(iv,v1); ti[1]=v1; - DES_encrypt1(ti,schedule,DES_ENCRYPT); - iv = &(*ivec)[0]; - v0=ti[0]; l2c(v0,iv); - v0=ti[1]; l2c(v0,iv); - iv = &(*ivec)[0]; - } - cc= *(in++); - c=iv[n]; - iv[n]=cc; - *(out++)=c^cc; - n=(n+1)&0x07; - } - } - v0=v1=ti[0]=ti[1]=c=cc=0; - *num=n; - } + long length, DES_key_schedule *schedule, + DES_cblock *ivec, int *num, int enc) +{ + register DES_LONG v0, v1; + register long l = length; + register int n = *num; + DES_LONG ti[2]; + unsigned char *iv, c, cc; + iv = &(*ivec)[0]; + if (enc) { + while (l--) { + if (n == 0) { + c2l(iv, v0); + ti[0] = v0; + c2l(iv, v1); + ti[1] = v1; + DES_encrypt1(ti, schedule, DES_ENCRYPT); + iv = &(*ivec)[0]; + v0 = ti[0]; + l2c(v0, iv); + v0 = ti[1]; + l2c(v0, iv); + iv = &(*ivec)[0]; + } + c = *(in++) ^ iv[n]; + *(out++) = c; + iv[n] = c; + n = (n + 1) & 0x07; + } + } else { + while (l--) { + if (n == 0) { + c2l(iv, v0); + ti[0] = v0; + c2l(iv, v1); + ti[1] = v1; + DES_encrypt1(ti, schedule, DES_ENCRYPT); + iv = &(*ivec)[0]; + v0 = ti[0]; + l2c(v0, iv); + v0 = ti[1]; + l2c(v0, iv); + iv = &(*ivec)[0]; + } + cc = *(in++); + c = iv[n]; + iv[n] = cc; + *(out++) = c ^ cc; + n = (n + 1) & 0x07; + } + } + v0 = v1 = ti[0] = ti[1] = c = cc = 0; + *num = n; +} diff --git a/crypto/des/cfb_enc.c b/crypto/des/cfb_enc.c index 720f29a28e..bd0e299716 100644 --- a/crypto/des/cfb_enc.c +++ b/crypto/des/cfb_enc.c @@ -5,21 +5,21 @@ * This package is an SSL implementation written * 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 * the following conditions are aheared to. The following conditions * 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@cryptsoft.com). - * + * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. * If this package is used in a product, Eric Young should be given attribution * as the author of the parts of the library used. * This can be in the form of a textual message at program startup or * in documentation (online or textual) provided with the package. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -34,10 +34,10 @@ * 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 + * 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@cryptsoft.com)" - * + * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -49,7 +49,7 @@ * 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. - * + * * The licence and distribution terms for any publically available version or * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence @@ -60,136 +60,140 @@ #include "des_locl.h" #include -/* The input and output are loaded in multiples of 8 bits. - * What this means is that if you hame numbits=12 and length=2 - * the first 12 bits will be retrieved from the first byte and half - * the second. The second 12 bits will come from the 3rd and half the 4th - * byte. +/* + * The input and output are loaded in multiples of 8 bits. What this means is + * that if you hame numbits=12 and length=2 the first 12 bits will be + * retrieved from the first byte and half the second. The second 12 bits + * will come from the 3rd and half the 4th byte. + */ +/* + * Until Aug 1 2003 this function did not correctly implement CFB-r, so it + * will not be compatible with any encryption prior to that date. Ben. */ -/* Until Aug 1 2003 this function did not correctly implement CFB-r, so it - * will not be compatible with any encryption prior to that date. Ben. */ void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits, - long length, DES_key_schedule *schedule, DES_cblock *ivec, - int enc) - { - register DES_LONG d0,d1,v0,v1; - register unsigned long l=length; - register int num=numbits/8,n=(numbits+7)/8,i,rem=numbits%8; - DES_LONG ti[2]; - unsigned char *iv; + long length, DES_key_schedule *schedule, + DES_cblock *ivec, int enc) +{ + register DES_LONG d0, d1, v0, v1; + register unsigned long l = length; + register int num = numbits / 8, n = (numbits + 7) / 8, i, rem = + numbits % 8; + DES_LONG ti[2]; + unsigned char *iv; #ifndef L_ENDIAN - unsigned char ovec[16]; + unsigned char ovec[16]; #else - unsigned int sh[4]; - unsigned char *ovec=(unsigned char *)sh; + unsigned int sh[4]; + unsigned char *ovec = (unsigned char *)sh; + + /* I kind of count that compiler optimizes away this assertioni, */ + assert(sizeof(sh[0]) == 4); /* as this holds true for all, */ + /* but 16-bit platforms... */ - /* I kind of count that compiler optimizes away this assertioni,*/ - assert (sizeof(sh[0])==4); /* as this holds true for all, */ - /* but 16-bit platforms... */ - #endif - if (numbits<=0 || numbits > 64) return; - iv = &(*ivec)[0]; - c2l(iv,v0); - c2l(iv,v1); - if (enc) - { - while (l >= (unsigned long)n) - { - l-=n; - ti[0]=v0; - ti[1]=v1; - DES_encrypt1((DES_LONG *)ti,schedule,DES_ENCRYPT); - c2ln(in,d0,d1,n); - in+=n; - d0^=ti[0]; - d1^=ti[1]; - l2cn(d0,d1,out,n); - out+=n; - /* 30-08-94 - eay - changed because l>>32 and - * l<<32 are bad under gcc :-( */ - if (numbits == 32) - { v0=v1; v1=d0; } - else if (numbits == 64) - { v0=d0; v1=d1; } - else - { + if (numbits <= 0 || numbits > 64) + return; + iv = &(*ivec)[0]; + c2l(iv, v0); + c2l(iv, v1); + if (enc) { + while (l >= (unsigned long)n) { + l -= n; + ti[0] = v0; + ti[1] = v1; + DES_encrypt1((DES_LONG *)ti, schedule, DES_ENCRYPT); + c2ln(in, d0, d1, n); + in += n; + d0 ^= ti[0]; + d1 ^= ti[1]; + l2cn(d0, d1, out, n); + out += n; + /* + * 30-08-94 - eay - changed because l>>32 and l<<32 are bad under + * gcc :-( + */ + if (numbits == 32) { + v0 = v1; + v1 = d0; + } else if (numbits == 64) { + v0 = d0; + v1 = d1; + } else { #ifndef L_ENDIAN - iv=&ovec[0]; - l2c(v0,iv); - l2c(v1,iv); - l2c(d0,iv); - l2c(d1,iv); + iv = &ovec[0]; + l2c(v0, iv); + l2c(v1, iv); + l2c(d0, iv); + l2c(d1, iv); #else - sh[0]=v0, sh[1]=v1, sh[2]=d0, sh[3]=d1; + sh[0] = v0, sh[1] = v1, sh[2] = d0, sh[3] = d1; #endif - if (rem==0) - memmove(ovec,ovec+num,8); - else - for(i=0 ; i < 8 ; ++i) - ovec[i]=ovec[i+num]<>(8-rem); + if (rem == 0) + memmove(ovec, ovec + num, 8); + else + for (i = 0; i < 8; ++i) + ovec[i] = ovec[i + num] << rem | + ovec[i + num + 1] >> (8 - rem); #ifdef L_ENDIAN - v0=sh[0], v1=sh[1]; + v0 = sh[0], v1 = sh[1]; #else - iv=&ovec[0]; - c2l(iv,v0); - c2l(iv,v1); + iv = &ovec[0]; + c2l(iv, v0); + c2l(iv, v1); #endif - } - } - } - else - { - while (l >= (unsigned long)n) - { - l-=n; - ti[0]=v0; - ti[1]=v1; - DES_encrypt1((DES_LONG *)ti,schedule,DES_ENCRYPT); - c2ln(in,d0,d1,n); - in+=n; - /* 30-08-94 - eay - changed because l>>32 and - * l<<32 are bad under gcc :-( */ - if (numbits == 32) - { v0=v1; v1=d0; } - else if (numbits == 64) - { v0=d0; v1=d1; } - else - { + } + } + } else { + while (l >= (unsigned long)n) { + l -= n; + ti[0] = v0; + ti[1] = v1; + DES_encrypt1((DES_LONG *)ti, schedule, DES_ENCRYPT); + c2ln(in, d0, d1, n); + in += n; + /* + * 30-08-94 - eay - changed because l>>32 and l<<32 are bad under + * gcc :-( + */ + if (numbits == 32) { + v0 = v1; + v1 = d0; + } else if (numbits == 64) { + v0 = d0; + v1 = d1; + } else { #ifndef L_ENDIAN - iv=&ovec[0]; - l2c(v0,iv); - l2c(v1,iv); - l2c(d0,iv); - l2c(d1,iv); + iv = &ovec[0]; + l2c(v0, iv); + l2c(v1, iv); + l2c(d0, iv); + l2c(d1, iv); #else - sh[0]=v0, sh[1]=v1, sh[2]=d0, sh[3]=d1; + sh[0] = v0, sh[1] = v1, sh[2] = d0, sh[3] = d1; #endif - if (rem==0) - memmove(ovec,ovec+num,8); - else - for(i=0 ; i < 8 ; ++i) - ovec[i]=ovec[i+num]<>(8-rem); + if (rem == 0) + memmove(ovec, ovec + num, 8); + else + for (i = 0; i < 8; ++i) + ovec[i] = ovec[i + num] << rem | + ovec[i + num + 1] >> (8 - rem); #ifdef L_ENDIAN - v0=sh[0], v1=sh[1]; + v0 = sh[0], v1 = sh[1]; #else - iv=&ovec[0]; - c2l(iv,v0); - c2l(iv,v1); + iv = &ovec[0]; + c2l(iv, v0); + c2l(iv, v1); #endif - } - d0^=ti[0]; - d1^=ti[1]; - l2cn(d0,d1,out,n); - out+=n; - } - } - iv = &(*ivec)[0]; - l2c(v0,iv); - l2c(v1,iv); - v0=v1=d0=d1=ti[0]=ti[1]=0; - } - + } + d0 ^= ti[0]; + d1 ^= ti[1]; + l2cn(d0, d1, out, n); + out += n; + } + } + iv = &(*ivec)[0]; + l2c(v0, iv); + l2c(v1, iv); + v0 = v1 = d0 = d1 = ti[0] = ti[1] = 0; +} diff --git a/crypto/des/des.c b/crypto/des/des.c index 3713e35b09..402695160d 100644 --- a/crypto/des/des.c +++ b/crypto/des/des.c @@ -5,21 +5,21 @@ * This package is an SSL implementation written * 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 * the following conditions are aheared to. The following conditions * 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@cryptsoft.com). - * + * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. * If this package is used in a product, Eric Young should be given attribution * as the author of the parts of the library used. * This can be in the form of a textual message at program startup or * in documentation (online or textual) provided with the package. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -34,10 +34,10 @@ * 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 + * 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@cryptsoft.com)" - * + * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -49,7 +49,7 @@ * 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. - * + * * The licence and distribution terms for any publically available version or * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence @@ -61,30 +61,30 @@ #include #include #ifndef OPENSSL_SYS_MSDOS -#ifndef OPENSSL_SYS_VMS -#include OPENSSL_UNISTD -#else /* OPENSSL_SYS_VMS */ -#ifdef __DECC -#include -#else /* not __DECC */ -#include -#endif /* __DECC */ -#endif /* OPENSSL_SYS_VMS */ -#else /* OPENSSL_SYS_MSDOS */ -#include +# ifndef OPENSSL_SYS_VMS +# include OPENSSL_UNISTD +# else /* OPENSSL_SYS_VMS */ +# ifdef __DECC +# include +# else /* not __DECC */ +# include +# endif /* __DECC */ +# endif /* OPENSSL_SYS_VMS */ +#else /* OPENSSL_SYS_MSDOS */ +# include #endif #include #include "des_ver.h" #ifdef OPENSSL_SYS_VMS -#include -#include +# include +# include #else -#ifndef _IRIX -#include -#endif -#include +# ifndef _IRIX +# include +# endif +# include #endif #include #include @@ -94,840 +94,773 @@ void usage(void); void doencryption(void); int uufwrite(unsigned char *data, int size, unsigned int num, FILE *fp); void uufwriteEnd(FILE *fp); -int uufread(unsigned char *out,int size,unsigned int num,FILE *fp); -int uuencode(unsigned char *in,int num,unsigned char *out); -int uudecode(unsigned char *in,int num,unsigned char *out); -void DES_3cbc_encrypt(DES_cblock *input,DES_cblock *output,long length, - DES_key_schedule sk1,DES_key_schedule sk2, - DES_cblock *ivec1,DES_cblock *ivec2,int enc); +int uufread(unsigned char *out, int size, unsigned int num, FILE *fp); +int uuencode(unsigned char *in, int num, unsigned char *out); +int uudecode(unsigned char *in, int num, unsigned char *out); +void DES_3cbc_encrypt(DES_cblock *input, DES_cblock *output, long length, + DES_key_schedule sk1, DES_key_schedule sk2, + DES_cblock *ivec1, DES_cblock *ivec2, int enc); #ifdef OPENSSL_SYS_VMS -#define EXIT(a) exit(a&0x10000000L) +# define EXIT(a) exit(a&0x10000000L) #else -#define EXIT(a) exit(a) +# define EXIT(a) exit(a) #endif #define BUFSIZE (8*1024) #define VERIFY 1 -#define KEYSIZ 8 -#define KEYSIZB 1024 /* should hit tty line limit first :-) */ -char key[KEYSIZB+1]; -int do_encrypt,longk=0; -FILE *DES_IN,*DES_OUT,*CKSUM_OUT; +#define KEYSIZ 8 +#define KEYSIZB 1024 /* should hit tty line limit first :-) */ +char key[KEYSIZB + 1]; +int do_encrypt, longk = 0; +FILE *DES_IN, *DES_OUT, *CKSUM_OUT; char uuname[200]; unsigned char uubuf[50]; -int uubufnum=0; -#define INUUBUFN (45*100) -#define OUTUUBUF (65*100) +int uubufnum = 0; +#define INUUBUFN (45*100) +#define OUTUUBUF (65*100) unsigned char b[OUTUUBUF]; unsigned char bb[300]; -DES_cblock cksum={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; -char cksumname[200]=""; +DES_cblock cksum = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -int vflag,cflag,eflag,dflag,kflag,bflag,fflag,sflag,uflag,flag3,hflag,error; +char cksumname[200] = ""; + +int vflag, cflag, eflag, dflag, kflag, bflag, fflag, sflag, uflag, flag3, + hflag, error; int main(int argc, char **argv) - { - int i; - struct stat ins,outs; - char *p; - char *in=NULL,*out=NULL; - - vflag=cflag=eflag=dflag=kflag=hflag=bflag=fflag=sflag=uflag=flag3=0; - error=0; - memset(key,0,sizeof(key)); - - for (i=1; i=0; j--) - argv[i][j]='\0'; - } - break; - default: - fprintf(stderr,"'%c' unknown flag\n",p[-1]); - error=1; - break; - } - } - } - else - { - if (in == NULL) - in=argv[i]; - else if (out == NULL) - out=argv[i]; - else - error=1; - } - } - if (error) usage(); - /*- - * We either - * do checksum or - * do encrypt or - * do decrypt or - * do decrypt then ckecksum or - * do checksum then encrypt - */ - if (((eflag+dflag) == 1) || cflag) - { - if (eflag) do_encrypt=DES_ENCRYPT; - if (dflag) do_encrypt=DES_DECRYPT; - } - else - { - if (vflag) - { -#ifndef _Windows - fprintf(stderr,"des(1) built with %s\n",libdes_version); -#endif - EXIT(1); - } - else usage(); - } - -#ifndef _Windows - if (vflag) fprintf(stderr,"des(1) built with %s\n",libdes_version); -#endif - if ( (in != NULL) && - (out != NULL) && +{ + int i; + struct stat ins, outs; + char *p; + char *in = NULL, *out = NULL; + + vflag = cflag = eflag = dflag = kflag = hflag = bflag = fflag = sflag = + uflag = flag3 = 0; + error = 0; + memset(key, 0, sizeof(key)); + + for (i = 1; i < argc; i++) { + p = argv[i]; + if ((p[0] == '-') && (p[1] != '\0')) { + p++; + while (*p) { + switch (*(p++)) { + case '3': + flag3 = 1; + longk = 1; + break; + case 'c': + cflag = 1; + strncpy(cksumname, p, 200); + cksumname[sizeof(cksumname) - 1] = '\0'; + p += strlen(cksumname); + break; + case 'C': + cflag = 1; + longk = 1; + strncpy(cksumname, p, 200); + cksumname[sizeof(cksumname) - 1] = '\0'; + p += strlen(cksumname); + break; + case 'e': + eflag = 1; + break; + case 'v': + vflag = 1; + break; + case 'E': + eflag = 1; + longk = 1; + break; + case 'd': + dflag = 1; + break; + case 'D': + dflag = 1; + longk = 1; + break; + case 'b': + bflag = 1; + break; + case 'f': + fflag = 1; + break; + case 's': + sflag = 1; + break; + case 'u': + uflag = 1; + strncpy(uuname, p, 200); + uuname[sizeof(uuname) - 1] = '\0'; + p += strlen(uuname); + break; + case 'h': + hflag = 1; + break; + case 'k': + kflag = 1; + if ((i + 1) == argc) { + fputs("must have a key with the -k option\n", stderr); + error = 1; + } else { + int j; + + i++; + strncpy(key, argv[i], KEYSIZB); + for (j = strlen(argv[i]) - 1; j >= 0; j--) + argv[i][j] = '\0'; + } + break; + default: + fprintf(stderr, "'%c' unknown flag\n", p[-1]); + error = 1; + break; + } + } + } else { + if (in == NULL) + in = argv[i]; + else if (out == NULL) + out = argv[i]; + else + error = 1; + } + } + if (error) + usage(); + /*- + * We either + * do checksum or + * do encrypt or + * do decrypt or + * do decrypt then ckecksum or + * do checksum then encrypt + */ + if (((eflag + dflag) == 1) || cflag) { + if (eflag) + do_encrypt = DES_ENCRYPT; + if (dflag) + do_encrypt = DES_DECRYPT; + } else { + if (vflag) { +#ifndef _Windows + fprintf(stderr, "des(1) built with %s\n", libdes_version); +#endif + EXIT(1); + } else + usage(); + } + +#ifndef _Windows + if (vflag) + fprintf(stderr, "des(1) built with %s\n", libdes_version); +#endif + if ((in != NULL) && (out != NULL) && #ifndef OPENSSL_SYS_MSDOS - (stat(in,&ins) != -1) && - (stat(out,&outs) != -1) && - (ins.st_dev == outs.st_dev) && - (ins.st_ino == outs.st_ino)) -#else /* OPENSSL_SYS_MSDOS */ - (strcmp(in,out) == 0)) + (stat(in, &ins) != -1) && + (stat(out, &outs) != -1) && + (ins.st_dev == outs.st_dev) && (ins.st_ino == outs.st_ino)) +#else /* OPENSSL_SYS_MSDOS */ + (strcmp(in, out) == 0)) #endif - { - fputs("input and output file are the same\n",stderr); - EXIT(3); - } - - if (!kflag) - if (des_read_pw_string(key,KEYSIZB+1,"Enter key:",eflag?VERIFY:0)) - { - fputs("password error\n",stderr); - EXIT(2); - } - - if (in == NULL) - DES_IN=stdin; - else if ((DES_IN=fopen(in,"r")) == NULL) - { - perror("opening input file"); - EXIT(4); - } - - CKSUM_OUT=stdout; - if (out == NULL) - { - DES_OUT=stdout; - CKSUM_OUT=stderr; - } - else if ((DES_OUT=fopen(out,"w")) == NULL) - { - perror("opening output file"); - EXIT(5); - } - + { + fputs("input and output file are the same\n", stderr); + EXIT(3); + } + + if (!kflag) + if (des_read_pw_string + (key, KEYSIZB + 1, "Enter key:", eflag ? VERIFY : 0)) { + fputs("password error\n", stderr); + EXIT(2); + } + + if (in == NULL) + DES_IN = stdin; + else if ((DES_IN = fopen(in, "r")) == NULL) { + perror("opening input file"); + EXIT(4); + } + + CKSUM_OUT = stdout; + if (out == NULL) { + DES_OUT = stdout; + CKSUM_OUT = stderr; + } else if ((DES_OUT = fopen(out, "w")) == NULL) { + perror("opening output file"); + EXIT(5); + } #ifdef OPENSSL_SYS_MSDOS - /* This should set the file to binary mode. */ - { -#include - if (!(uflag && dflag)) - setmode(fileno(DES_IN),O_BINARY); - if (!(uflag && eflag)) - setmode(fileno(DES_OUT),O_BINARY); - } + /* This should set the file to binary mode. */ + { +# include + if (!(uflag && dflag)) + setmode(fileno(DES_IN), O_BINARY); + if (!(uflag && eflag)) + setmode(fileno(DES_OUT), O_BINARY); + } #endif - doencryption(); - fclose(DES_IN); - fclose(DES_OUT); - EXIT(0); - } + doencryption(); + fclose(DES_IN); + fclose(DES_OUT); + EXIT(0); +} void usage(void) - { - char **u; - static const char *Usage[]={ -"des [input-file [output-file]]", -"options:", -"-v : des(1) version number", -"-e : encrypt using SunOS compatible user key to DES key conversion.", -"-E : encrypt ", -"-d : decrypt using SunOS compatible user key to DES key conversion.", -"-D : decrypt ", -"-c[ckname] : generate a cbc_cksum using SunOS compatible user key to", -" DES key conversion and output to ckname (stdout default,", -" stderr if data being output on stdout). The checksum is", -" generated before encryption and after decryption if used", -" 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 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).", -"-b : encrypt using DES in ecb encryption mode, the default is cbc mode.", -"-3 : encrypt using triple DES encryption. This uses 2 keys", -" generated from the input key. If the input key is less", -" than 8 characters long, this is equivalent to normal", -" encryption. Default is triple cbc, -b makes it triple ecb.", -NULL -}; - for (u=(char **)Usage; *u; u++) - { - fputs(*u,stderr); - fputc('\n',stderr); - } - - EXIT(1); - } +{ + char **u; + static const char *Usage[] = { + "des [input-file [output-file]]", + "options:", + "-v : des(1) version number", + "-e : encrypt using SunOS compatible user key to DES key conversion.", + "-E : encrypt ", + "-d : decrypt using SunOS compatible user key to DES key conversion.", + "-D : decrypt ", + "-c[ckname] : generate a cbc_cksum using SunOS compatible user key to", + " DES key conversion and output to ckname (stdout default,", + " stderr if data being output on stdout). The checksum is", + " generated before encryption and after decryption if used", + " 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 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).", + "-b : encrypt using DES in ecb encryption mode, the default is cbc mode.", + "-3 : encrypt using triple DES encryption. This uses 2 keys", + " generated from the input key. If the input key is less", + " than 8 characters long, this is equivalent to normal", + " encryption. Default is triple cbc, -b makes it triple ecb.", + NULL + }; + for (u = (char **)Usage; *u; u++) { + fputs(*u, stderr); + fputc('\n', stderr); + } + + EXIT(1); +} void doencryption(void) - { +{ #ifdef _LIBC - extern unsigned long time(); + extern unsigned long time(); #endif - register int i; - DES_key_schedule ks,ks2; - DES_cblock iv,iv2; - char *p; - int num=0,j,k,l,rem,ll,len,last,ex=0; - DES_cblock kk,k2; - FILE *O; - int Exit=0; + register int i; + DES_key_schedule ks, ks2; + DES_cblock iv, iv2; + char *p; + int num = 0, j, k, l, rem, ll, len, last, ex = 0; + DES_cblock kk, k2; + FILE *O; + int Exit = 0; #ifndef OPENSSL_SYS_MSDOS - static unsigned char buf[BUFSIZE+8],obuf[BUFSIZE+8]; + static unsigned char buf[BUFSIZE + 8], obuf[BUFSIZE + 8]; #else - static unsigned char *buf=NULL,*obuf=NULL; - - if (buf == NULL) - { - if ( (( buf=OPENSSL_malloc(BUFSIZE+8)) == NULL) || - ((obuf=OPENSSL_malloc(BUFSIZE+8)) == NULL)) - { - fputs("Not enough memory\n",stderr); - Exit=10; - goto problems; - } - } + static unsigned char *buf = NULL, *obuf = NULL; + + if (buf == NULL) { + if (((buf = OPENSSL_malloc(BUFSIZE + 8)) == NULL) || + ((obuf = OPENSSL_malloc(BUFSIZE + 8)) == NULL)) { + fputs("Not enough memory\n", stderr); + Exit = 10; + goto problems; + } + } #endif - if (hflag) - { - j=(flag3?16:8); - p=key; - for (i=0; i= '0')) - k=(*p-'0')<<4; - else if ((*p <= 'f') && (*p >= 'a')) - k=(*p-'a'+10)<<4; - else if ((*p <= 'F') && (*p >= 'A')) - k=(*p-'A'+10)<<4; - else - { - fputs("Bad hex key\n",stderr); - Exit=9; - goto problems; - } - p++; - if ((*p <= '9') && (*p >= '0')) - k|=(*p-'0'); - else if ((*p <= 'f') && (*p >= 'a')) - k|=(*p-'a'+10); - else if ((*p <= 'F') && (*p >= 'A')) - k|=(*p-'A'+10); - else - { - fputs("Bad hex key\n",stderr); - Exit=9; - goto problems; - } - p++; - if (i < 8) - kk[i]=k; - else - k2[i-8]=k; - } - DES_set_key_unchecked(&k2,&ks2); - OPENSSL_cleanse(k2,sizeof(k2)); - } - else if (longk || flag3) - { - if (flag3) - { - DES_string_to_2keys(key,&kk,&k2); - DES_set_key_unchecked(&k2,&ks2); - OPENSSL_cleanse(k2,sizeof(k2)); - } - else - DES_string_to_key(key,&kk); - } - else - for (i=0; i>=1; - } - if (l & 1) - kk[i]=key[i]&0x7f; - else - kk[i]=key[i]|0x80; - } - - DES_set_key_unchecked(&kk,&ks); - OPENSSL_cleanse(key,sizeof(key)); - OPENSSL_cleanse(kk,sizeof(kk)); - /* woops - A bug that does not showup under unix :-( */ - memset(iv,0,sizeof(iv)); - memset(iv2,0,sizeof(iv2)); - - l=1; - rem=0; - /* first read */ - if (eflag || (!dflag && cflag)) - { - for (;;) - { - num=l=fread(&(buf[rem]),1,BUFSIZE,DES_IN); - l+=rem; - num+=rem; - if (l < 0) - { - perror("read error"); - Exit=6; - goto problems; - } - - rem=l%8; - len=l-rem; - if (feof(DES_IN)) - { - for (i=7-rem; i>0; i--) - RAND_pseudo_bytes(buf + l++, 1); - buf[l++]=rem; - ex=1; - len+=rem; - } - else - l-=rem; - - if (cflag) - { - DES_cbc_cksum(buf,&cksum, - (long)len,&ks,&cksum); - if (!eflag) - { - if (feof(DES_IN)) break; - else continue; - } - } - - if (bflag && !flag3) - for (i=0; i= 8) memcpy(iv,&(obuf[l-8]),8); - } - if (rem) memcpy(buf,&(buf[l]),(unsigned int)rem); - - i=0; - while (i < l) - { - if (uflag) - j=uufwrite(obuf,1,(unsigned int)l-i, - DES_OUT); - else - j=fwrite(obuf,1,(unsigned int)l-i, - DES_OUT); - if (j == -1) - { - perror("Write error"); - Exit=7; - goto problems; - } - i+=j; - } - if (feof(DES_IN)) - { - if (uflag) uufwriteEnd(DES_OUT); - break; - } - } - } - else /* decrypt */ - { - ex=1; - for (;;) - { - if (ex) { - if (uflag) - l=uufread(buf,1,BUFSIZE,DES_IN); - else - l=fread(buf,1,BUFSIZE,DES_IN); - ex=0; - rem=l%8; - l-=rem; - } - if (l < 0) - { - perror("read error"); - Exit=6; - goto problems; - } - - if (bflag && !flag3) - for (i=0; i= 8) memcpy(iv,&(buf[l-8]),8); - } - - if (uflag) - ll=uu