From edb93ae643c9f84df92fbddceff437994c6ea58b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ulf=20M=C3=B6ller?= Date: Sun, 19 Mar 2000 02:10:17 +0000 Subject: [PATCH] cleanup. --- crypto/des/Makefile.ssl | 6 +-- crypto/des/des.h | 29 ++++++++--- crypto/des/fcrypt.c | 1 - crypto/des/rand_key.c | 8 ++- crypto/des/set_key.c | 11 +++-- crypto/des/supp.c | 107 ---------------------------------------- 6 files changed, 38 insertions(+), 124 deletions(-) delete mode 100644 crypto/des/supp.c diff --git a/crypto/des/Makefile.ssl b/crypto/des/Makefile.ssl index 92153d1540..65900867f7 100644 --- a/crypto/des/Makefile.ssl +++ b/crypto/des/Makefile.ssl @@ -32,15 +32,15 @@ LIBSRC= cbc_cksm.c cbc_enc.c cfb64enc.c cfb_enc.c \ fcrypt.c ofb64enc.c ofb_enc.c pcbc_enc.c \ qud_cksm.c rand_key.c read_pwd.c rpc_enc.c set_key.c \ des_enc.c fcrypt_b.c read2pwd.c \ - fcrypt.c xcbc_enc.c \ - str2key.c cfb64ede.c ofb64ede.c supp.c ede_cbcm_enc.c + xcbc_enc.c \ + str2key.c cfb64ede.c ofb64ede.c ede_cbcm_enc.c LIBOBJ= set_key.o ecb_enc.o cbc_enc.o \ ecb3_enc.o cfb64enc.o cfb64ede.o cfb_enc.o ofb64ede.o \ enc_read.o enc_writ.o ofb64enc.o \ ofb_enc.o str2key.o pcbc_enc.o qud_cksm.o rand_key.o \ ${DES_ENC} read2pwd.o \ - fcrypt.o xcbc_enc.o read_pwd.o rpc_enc.o cbc_cksm.o supp.o \ + fcrypt.o xcbc_enc.o read_pwd.o rpc_enc.o cbc_cksm.o \ ede_cbcm_enc.o SRC= $(LIBSRC) diff --git a/crypto/des/des.h b/crypto/des/des.h index 98a9c4127c..ead67986d9 100644 --- a/crypto/des/des.h +++ b/crypto/des/des.h @@ -78,10 +78,7 @@ extern "C" { typedef unsigned char des_cblock[8]; typedef /* const */ unsigned char const_des_cblock[8]; /* With "const", gcc 2.8.1 on Solaris thinks that des_cblock * - * and const_des_cblock * are incompatible pointer types. - * I haven't seen that warning on other systems ... I'll look - * what the standard says. */ - + * and const_des_cblock * are incompatible pointer types. */ typedef struct des_ks_struct { @@ -141,8 +138,26 @@ void des_cfb_encrypt(const unsigned char *in,unsigned char *out,int numbits, int enc); void des_ecb_encrypt(const_des_cblock *input,des_cblock *output, des_key_schedule ks,int enc); + +/* This is the DES encryption function that gets called by just about + every other DES routine in the library. You should not use this + function except to implement 'modes' of DES. I say this because the + functions that call this routine do the conversion from 'char *' to + long, and this needs to be done to make sure 'non-aligned' memory + access do not occur. The characters are loaded 'little endian'. + Data is a pointer to 2 unsigned long's and ks is the + des_key_schedule to use. enc, is non zero specifies encryption, + zero if decryption. */ void des_encrypt(DES_LONG *data,des_key_schedule ks, int enc); + +/* This functions is the same as des_encrypt() except that the DES + initial permutation (IP) and final permutation (FP) have been left + out. As for des_encrypt(), you should not use this function. + It is used by the routines in the library that implement triple DES. + IP() des_encrypt2() des_encrypt2() des_encrypt2() FP() is the same + as des_encrypt() des_encrypt() des_encrypt() except faster :-). */ void des_encrypt2(DES_LONG *data,des_key_schedule ks, int enc); + void des_encrypt3(DES_LONG *data, des_key_schedule ks1, des_key_schedule ks2, des_key_schedule ks3); void des_decrypt3(DES_LONG *data, des_key_schedule ks1, @@ -192,6 +207,7 @@ int des_read_2passwords(des_cblock *key1,des_cblock *key2, const char *prompt,int verify); int des_read_pw_string(char *buf,int length,const char *prompt,int verify); void des_set_odd_parity(des_cblock *key); +int des_check_key_parity(const_des_cblock *key); int des_is_weak_key(const_des_cblock *key); /* des_set_key (= set_key = des_key_sched = key_sched) calls * des_set_key_checked if global variable des_check_key is set, @@ -209,9 +225,6 @@ void des_ofb64_encrypt(const unsigned char *in,unsigned char *out,long length, des_key_schedule schedule,des_cblock *ivec,int *num); int des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify); -/* Extra functions from Mark Murray */ -void des_cblock_print_file(const_des_cblock *cb, FILE *fp); - /* The following definitions provide compatibility with the MIT Kerberos * library. The des_key_schedule structure is not binary compatible. */ @@ -241,11 +254,11 @@ void des_cblock_print_file(const_des_cblock *cb, FILE *fp); # define xcbc_encrypt des_xcbc_encrypt # define cbc_cksum des_cbc_cksum # define quad_cksum des_quad_cksum +# define check_parity des_check_key_parity #endif typedef des_key_schedule bit_64; #define des_fixup_key_parity des_set_odd_parity -#define des_check_key_parity check_parity #ifdef __cplusplus } diff --git a/crypto/des/fcrypt.c b/crypto/des/fcrypt.c index 88fbbcf25f..1d619316fd 100644 --- a/crypto/des/fcrypt.c +++ b/crypto/des/fcrypt.c @@ -11,7 +11,6 @@ /* This version of crypt has been developed from my MIT compatible * DES library. - * The library is available at pub/Crypto/DES at ftp.psy.uq.oz.au * Eric Young (eay@cryptsoft.com) */ diff --git a/crypto/des/rand_key.c b/crypto/des/rand_key.c index 7816a8f25c..ee1a6c274e 100644 --- a/crypto/des/rand_key.c +++ b/crypto/des/rand_key.c @@ -63,7 +63,11 @@ void des_random_seed(des_cblock *key) int des_random_key(des_cblock *ret) { - int r = RAND_bytes((unsigned char *)ret, sizeof(des_cblock)); + do + { + if (RAND_bytes((unsigned char *)ret, sizeof(des_cblock)) != 1) + return (0); + } while (des_is_weak_key(ret)); des_set_odd_parity(ret); - return r; + return (1); } diff --git a/crypto/des/set_key.c b/crypto/des/set_key.c index 213b59f783..58e74d674f 100644 --- a/crypto/des/set_key.c +++ b/crypto/des/set_key.c @@ -67,7 +67,6 @@ #include "podd.h" #include "sk.h" -static int check_parity(const_des_cblock *key); OPENSSL_GLOBAL int des_check_key=0; void des_set_odd_parity(des_cblock *key) @@ -78,7 +77,7 @@ void des_set_odd_parity(des_cblock *key) (*key)[i]=odd_parity[(*key)[i]]; } -static int check_parity(const_des_cblock *key) +int des_check_key_parity(const_des_cblock *key) { int i; @@ -164,7 +163,7 @@ int des_set_key(const_des_cblock *key, des_key_schedule schedule) */ int des_set_key_checked(const_des_cblock *key, des_key_schedule schedule) { - if (!check_parity(key)) + if (!des_check_key_parity(key)) return(-1); if (des_is_weak_key(key)) return(-2); @@ -245,3 +244,9 @@ int des_key_sched(const_des_cblock *key, des_key_schedule schedule) { return(des_set_key(key,schedule)); } + +#undef des_fixup_key_parity +void des_fixup_key_parity(des_cblock *key) + { + des_set_odd_parity(key); + } diff --git a/crypto/des/supp.c b/crypto/des/supp.c deleted file mode 100644 index e51b36c916..0000000000 --- a/crypto/des/supp.c +++ /dev/null @@ -1,107 +0,0 @@ -/* crypto/des/supp.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * 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: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * 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 cryptographic software written by - * 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@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 - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * 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 - * [including the GNU Public Licence.] - */ - -/* - * Copyright (c) 1995 - * Mark Murray. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * 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 Mark Murray - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY MARK MURRAY AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * 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: supp.c,v 1.5 1999/05/16 12:25:45 bodo Exp $ - */ - -#include -#include "des_locl.h" - -void des_cblock_print_file(const_des_cblock *cb, FILE *fp) -{ - int i; - const unsigned int *p = (const unsigned int *)cb; - - fprintf(fp, " 0x { "); - for (i = 0; i < 8; i++) { - fprintf(fp, "%x", p[i]); - if (i != 7) fprintf(fp, ", "); - } - fprintf(fp, " }"); -} -- 2.25.1