diff options
Diffstat (limited to 'crypto/cast')
-rw-r--r-- | crypto/cast/Makefile | 104 | ||||
-rw-r--r-- | crypto/cast/asm/cast-586.pl | 31 | ||||
-rw-r--r-- | crypto/cast/asm/readme | 7 | ||||
-rw-r--r-- | crypto/cast/build.info | 7 | ||||
-rw-r--r-- | crypto/cast/c_cfb64.c | 61 | ||||
-rw-r--r-- | crypto/cast/c_ecb.c | 63 | ||||
-rw-r--r-- | crypto/cast/c_enc.c | 69 | ||||
-rw-r--r-- | crypto/cast/c_ofb64.c | 61 | ||||
-rw-r--r-- | crypto/cast/c_skey.c | 71 | ||||
-rw-r--r-- | crypto/cast/cast.h | 107 | ||||
-rw-r--r-- | crypto/cast/cast_lcl.h | 81 | ||||
-rw-r--r-- | crypto/cast/cast_s.h | 78 | ||||
-rw-r--r-- | crypto/cast/cast_spd.c | 262 | ||||
-rw-r--r-- | crypto/cast/castopts.c | 334 | ||||
-rw-r--r-- | crypto/cast/casttest.c | 241 |
15 files changed, 101 insertions, 1476 deletions
diff --git a/crypto/cast/Makefile b/crypto/cast/Makefile deleted file mode 100644 index 4c4b5e9baa55..000000000000 --- a/crypto/cast/Makefile +++ /dev/null @@ -1,104 +0,0 @@ -# -# OpenSSL/crypto/cast/Makefile -# - -DIR= cast -TOP= ../.. -CC= cc -CPP= $(CC) -E -INCLUDES= -CFLAG=-g -MAKEFILE= Makefile -AR= ar r - -CAST_ENC=c_enc.o - -CFLAGS= $(INCLUDES) $(CFLAG) -ASFLAGS= $(INCLUDES) $(ASFLAG) -AFLAGS= $(ASFLAGS) - -GENERAL=Makefile -TEST=casttest.c -APPS= - -LIB=$(TOP)/libcrypto.a -LIBSRC=c_skey.c c_ecb.c c_enc.c c_cfb64.c c_ofb64.c -LIBOBJ=c_skey.o c_ecb.o $(CAST_ENC) c_cfb64.o c_ofb64.o - -SRC= $(LIBSRC) - -EXHEADER= cast.h -HEADER= cast_s.h cast_lcl.h $(EXHEADER) - -ALL= $(GENERAL) $(SRC) $(HEADER) - -top: - (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) - -all: lib - -lib: $(LIBOBJ) - $(AR) $(LIB) $(LIBOBJ) - $(RANLIB) $(LIB) || echo Never mind. - @touch lib - -cast-586.s: asm/cast-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl - $(PERL) asm/cast-586.pl $(PERLASM_SCHEME) $(CLAGS) $(PROCESSOR) > $@ - -files: - $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO - -links: - @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) - @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) - @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) - -install: - @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile... - @headerlist="$(EXHEADER)"; for i in $$headerlist ; \ - do \ - (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ - chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ - done; - -tags: - ctags $(SRC) - -tests: - -lint: - lint -DLINT $(INCLUDES) $(SRC)>fluff - -update: depend - -depend: - @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile... - $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) - -dclean: - $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new - mv -f Makefile.new $(MAKEFILE) - -clean: - rm -f *.s *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -# DO NOT DELETE THIS LINE -- make depend depends on it. - -c_cfb64.o: ../../e_os.h ../../include/openssl/cast.h -c_cfb64.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h -c_cfb64.o: c_cfb64.c cast_lcl.h -c_ecb.o: ../../e_os.h ../../include/openssl/cast.h -c_ecb.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h -c_ecb.o: ../../include/openssl/opensslv.h c_ecb.c cast_lcl.h -c_enc.o: ../../e_os.h ../../include/openssl/cast.h -c_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h -c_enc.o: c_enc.c cast_lcl.h -c_ofb64.o: ../../e_os.h ../../include/openssl/cast.h -c_ofb64.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h -c_ofb64.o: c_ofb64.c cast_lcl.h -c_skey.o: ../../e_os.h ../../include/openssl/cast.h -c_skey.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h -c_skey.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h -c_skey.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h -c_skey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h -c_skey.o: c_skey.c cast_lcl.h cast_s.h diff --git a/crypto/cast/asm/cast-586.pl b/crypto/cast/asm/cast-586.pl index bf6810d335f2..d5d38965cf76 100644 --- a/crypto/cast/asm/cast-586.pl +++ b/crypto/cast/asm/cast-586.pl @@ -1,6 +1,16 @@ -#!/usr/local/bin/perl - -# define for pentium pro friendly version +#! /usr/bin/env perl +# Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. +# +# Licensed under the OpenSSL license (the "License"). You may not use +# this file except in compliance with the License. You can obtain a copy +# in the file LICENSE in the source distribution or at +# https://www.openssl.org/source/license.html + + +# This flag makes the inner loop one cycle longer, but generates +# code that runs %30 faster on the pentium pro/II, 44% faster +# of PIII, while only %7 slower on the pentium. +# By default, this flag is on. $ppro=1; $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1; @@ -8,7 +18,10 @@ push(@INC,"${dir}","${dir}../../perlasm"); require "x86asm.pl"; require "cbc.pl"; -&asm_init($ARGV[0],"cast-586.pl",$ARGV[$#ARGV] eq "386"); +$output=pop; +open STDOUT,">$output"; + +&asm_init($ARGV[0],$ARGV[$#ARGV] eq "386"); $CAST_ROUNDS=16; $L="edi"; @@ -33,6 +46,8 @@ $S4="CAST_S_table3"; &asm_finish(); +close STDOUT; + sub CAST_encrypt { local($name,$enc)=@_; @@ -140,18 +155,18 @@ sub E_CAST { &rotl( $tmp4, &LB($tmp1)); if ($ppro) { - &mov( $tmp2, $tmp4); # B &xor( $tmp1, $tmp1); - + &mov( $tmp2, 0xff); + &movb( &LB($tmp1), &HB($tmp4)); # A - &and( $tmp2, 0xff); + &and( $tmp2, $tmp4); &shr( $tmp4, 16); # &xor( $tmp3, $tmp3); } else { &mov( $tmp2, $tmp4); # B &movb( &LB($tmp1), &HB($tmp4)); # A # BAD BAD BAD - + &shr( $tmp4, 16); # &and( $tmp2, 0xff); } diff --git a/crypto/cast/asm/readme b/crypto/cast/asm/readme deleted file mode 100644 index fbcd76289e26..000000000000 --- a/crypto/cast/asm/readme +++ /dev/null @@ -1,7 +0,0 @@ -There is a ppro flag in cast-586 which turns on/off -generation of pentium pro/II friendly code - -This flag makes the inner loop one cycle longer, but generates -code that runs %30 faster on the pentium pro/II, while only %7 slower -on the pentium. By default, this flag is on. - diff --git a/crypto/cast/build.info b/crypto/cast/build.info new file mode 100644 index 000000000000..b0f59f38002c --- /dev/null +++ b/crypto/cast/build.info @@ -0,0 +1,7 @@ +LIBS=../../libcrypto +SOURCE[../../libcrypto]=\ + c_skey.c c_ecb.c {- $target{cast_asm_src} -} c_cfb64.c c_ofb64.c + +GENERATE[cast-586.s]=asm/cast-586.pl \ + $(PERLASM_SCHEME) $(LIB_CFLAGS) $(LIB_CPPFLAGS) $(PROCESSOR) +DEPEND[cast-586.s]=../perlasm/x86asm.pl ../perlasm/cbc.pl diff --git a/crypto/cast/c_cfb64.c b/crypto/cast/c_cfb64.c index f2f16e5d77a0..bd7cb2f46843 100644 --- a/crypto/cast/c_cfb64.c +++ b/crypto/cast/c_cfb64.c @@ -1,59 +1,10 @@ -/* crypto/cast/c_cfb64.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. +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. * - * 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.] + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html */ #include <openssl/cast.h> diff --git a/crypto/cast/c_ecb.c b/crypto/cast/c_ecb.c index 4793f28edfd4..da4179438f1d 100644 --- a/crypto/cast/c_ecb.c +++ b/crypto/cast/c_ecb.c @@ -1,67 +1,16 @@ -/* crypto/cast/c_ecb.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. +/* + * Copyright 1995-2016 The OpenSSL Project Authors. 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.] + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html */ #include <openssl/cast.h> #include "cast_lcl.h" #include <openssl/opensslv.h> -const char CAST_version[] = "CAST" OPENSSL_VERSION_PTEXT; - void CAST_ecb_encrypt(const unsigned char *in, unsigned char *out, const CAST_KEY *ks, int enc) { diff --git a/crypto/cast/c_enc.c b/crypto/cast/c_enc.c index 6e1d50f10dd9..700b6d162a9f 100644 --- a/crypto/cast/c_enc.c +++ b/crypto/cast/c_enc.c @@ -1,59 +1,10 @@ -/* crypto/cast/c_enc.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. +/* + * Copyright 1995-2016 The OpenSSL Project Authors. 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.] + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html */ #include <openssl/cast.h> @@ -61,8 +12,8 @@ void CAST_encrypt(CAST_LONG *data, const CAST_KEY *key) { - register CAST_LONG l, r, t; - const register CAST_LONG *k; + CAST_LONG l, r, t; + const CAST_LONG *k; k = &(key->data[0]); l = data[0]; @@ -93,8 +44,8 @@ void CAST_encrypt(CAST_LONG *data, const CAST_KEY *key) void CAST_decrypt(CAST_LONG *data, const CAST_KEY *key) { - register CAST_LONG l, r, t; - const register CAST_LONG *k; + CAST_LONG l, r, t; + const CAST_LONG *k; k = &(key->data[0]); l = data[0]; diff --git a/crypto/cast/c_ofb64.c b/crypto/cast/c_ofb64.c index 4e0a7c2e6eb4..dffb074762c2 100644 --- a/crypto/cast/c_ofb64.c +++ b/crypto/cast/c_ofb64.c @@ -1,59 +1,10 @@ -/* crypto/cast/c_ofb64.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. +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. * - * 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.] + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html */ #include <openssl/cast.h> diff --git a/crypto/cast/c_skey.c b/crypto/cast/c_skey.c index bbb6d560991b..962d2a60b4c5 100644 --- a/crypto/cast/c_skey.c +++ b/crypto/cast/c_skey.c @@ -1,62 +1,12 @@ -/* crypto/cast/c_skey.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. +/* + * Copyright 1995-2016 The OpenSSL Project Authors. 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.] + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html */ -#include <openssl/crypto.h> #include <openssl/cast.h> #include "cast_lcl.h" #include "cast_s.h" @@ -72,15 +22,8 @@ #define S5 CAST_S_table5 #define S6 CAST_S_table6 #define S7 CAST_S_table7 -void CAST_set_key(CAST_KEY *key, int len, const unsigned char *data) -#ifdef OPENSSL_FIPS -{ - fips_cipher_abort(CAST); - private_CAST_set_key(key, len, data); -} -void private_CAST_set_key(CAST_KEY *key, int len, const unsigned char *data) -#endif +void CAST_set_key(CAST_KEY *key, int len, const unsigned char *data) { CAST_LONG x[16]; CAST_LONG z[16]; diff --git a/crypto/cast/cast.h b/crypto/cast/cast.h deleted file mode 100644 index 0003ec9c7c02..000000000000 --- a/crypto/cast/cast.h +++ /dev/null @@ -1,107 +0,0 @@ -/* crypto/cast/cast.h */ -/* 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.] - */ - -#ifndef HEADER_CAST_H -# define HEADER_CAST_H - -#ifdef __cplusplus -extern "C" { -#endif - -# include <openssl/opensslconf.h> - -# ifdef OPENSSL_NO_CAST -# error CAST is disabled. -# endif - -# define CAST_ENCRYPT 1 -# define CAST_DECRYPT 0 - -# define CAST_LONG unsigned int - -# define CAST_BLOCK 8 -# define CAST_KEY_LENGTH 16 - -typedef struct cast_key_st { - CAST_LONG data[32]; - int short_key; /* Use reduced rounds for short key */ -} CAST_KEY; - -# ifdef OPENSSL_FIPS -void private_CAST_set_key(CAST_KEY *key, int len, const unsigned char *data); -# endif -void CAST_set_key(CAST_KEY *key, int len, const unsigned char *data); -void CAST_ecb_encrypt(const unsigned char *in, unsigned char *out, - const CAST_KEY *key, int enc); -void CAST_encrypt(CAST_LONG *data, const CAST_KEY *key); -void CAST_decrypt(CAST_LONG *data, const CAST_KEY *key); -void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out, - long length, const CAST_KEY *ks, unsigned char *iv, - int enc); -void CAST_cfb64_encrypt(const unsigned char *in, unsigned char *out, - long length, const CAST_KEY *schedule, - unsigned char *ivec, int *num, int enc); -void CAST_ofb64_encrypt(const unsigned char *in, unsigned char *out, - long length, const CAST_KEY *schedule, - unsigned char *ivec, int *num); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/crypto/cast/cast_lcl.h b/crypto/cast/cast_lcl.h index b0f08294e373..35e89930a8c0 100644 --- a/crypto/cast/cast_lcl.h +++ b/crypto/cast/cast_lcl.h @@ -1,63 +1,12 @@ -/* crypto/cast/cast_lcl.h */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. +/* + * Copyright 1995-2017 The OpenSSL Project Authors. 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.] + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html */ -#include "e_os.h" - #ifdef OPENSSL_SYS_WIN32 # include <stdlib.h> #endif @@ -113,12 +62,19 @@ l1=l2=0; \ switch (n) { \ case 8: l2 =((unsigned long)(*(--(c)))) ; \ + /* fall thru */ \ case 7: l2|=((unsigned long)(*(--(c))))<< 8; \ + /* fall thru */ \ case 6: l2|=((unsigned long)(*(--(c))))<<16; \ + /* fall thru */ \ case 5: l2|=((unsigned long)(*(--(c))))<<24; \ + /* fall thru */ \ case 4: l1 =((unsigned long)(*(--(c)))) ; \ + /* fall thru */ \ case 3: l1|=((unsigned long)(*(--(c))))<< 8; \ + /* fall thru */ \ case 2: l1|=((unsigned long)(*(--(c))))<<16; \ + /* fall thru */ \ case 1: l1|=((unsigned long)(*(--(c))))<<24; \ } \ } @@ -128,12 +84,19 @@ c+=n; \ switch (n) { \ case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \ + /* fall thru */ \ case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \ + /* fall thru */ \ case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \ + /* fall thru */ \ case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \ + /* fall thru */ \ case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \ + /* fall thru */ \ case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \ + /* fall thru */ \ case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \ + /* fall thru */ \ case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \ } \ } @@ -152,10 +115,8 @@ #if defined(OPENSSL_SYS_WIN32) && defined(_MSC_VER) # define ROTL(a,n) (_lrotl(a,n)) -#elif defined(PEDANTIC) -# define ROTL(a,n) ((((a)<<(n))&0xffffffffL)|((a)>>((32-(n))&31))) #else -# define ROTL(a,n) ((((a)<<(n))&0xffffffffL)|((a)>>(32-(n)))) +# define ROTL(a,n) ((((a)<<(n))&0xffffffffL)|((a)>>((32-(n))&31))) #endif #define C_M 0x3fc diff --git a/crypto/cast/cast_s.h b/crypto/cast/cast_s.h index 380dc81aef37..b27415b967f5 100644 --- a/crypto/cast/cast_s.h +++ b/crypto/cast/cast_s.h @@ -1,61 +1,13 @@ -/* crypto/cast/cast_s.h */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. +/* + * Copyright 1995-2016 The OpenSSL Project Authors. 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.] + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html */ -OPENSSL_GLOBAL const CAST_LONG CAST_S_table0[256] = { + +const CAST_LONG CAST_S_table0[256] = { 0x30fb40d4, 0x9fa0ff0b, 0x6beccd2f, 0x3f258c7a, 0x1e213f2f, 0x9c004dd3, 0x6003e540, 0xcf9fc949, 0xbfd4af27, 0x88bbbdb5, 0xe2034090, 0x98d09675, @@ -122,7 +74,7 @@ OPENSSL_GLOBAL const CAST_LONG CAST_S_table0[256] = { 0x427b169c, 0x5ac9f049, 0xdd8f0f00, 0x5c8165bf, }; -OPENSSL_GLOBAL const CAST_LONG CAST_S_table1[256] = { +const CAST_LONG CAST_S_table1[256] = { 0x1f201094, 0xef0ba75b, 0x69e3cf7e, 0x393f4380, 0xfe61cf7a, 0xeec5207a, 0x55889c94, 0x72fc0651, 0xada7ef79, 0x4e1d7235, 0xd55a63ce, 0xde0436ba, @@ -189,7 +141,7 @@ OPENSSL_GLOBAL const CAST_LONG CAST_S_table1[256] = { 0x7160a539, 0x73bfbe70, 0x83877605, 0x4523ecf1, }; -OPENSSL_GLOBAL const CAST_LONG CAST_S_table2[256] = { +const CAST_LONG CAST_S_table2[256] = { 0x8defc240, 0x25fa5d9f, 0xeb903dbf, 0xe810c907, 0x47607fff, 0x369fe44b, 0x8c1fc644, 0xaececa90, 0xbeb1f9bf, 0xeefbcaea, 0xe8cf1950, 0x51df07ae, @@ -256,7 +208,7 @@ OPENSSL_GLOBAL const CAST_LONG CAST_S_table2[256] = { 0xdfef4636, 0xa133c501, 0xe9d3531c, 0xee353783, }; -OPENSSL_GLOBAL const CAST_LONG CAST_S_table3[256] = { +const CAST_LONG CAST_S_table3[256] = { 0x9db30420, 0x1fb6e9de, 0xa7be7bef, 0xd273a298, 0x4a4f7bdb, 0x64ad8c57, 0x85510443, 0xfa020ed1, 0x7e287aff, 0xe60fb663, 0x095f35a1, 0x79ebf120, @@ -323,7 +275,7 @@ OPENSSL_GLOBAL const CAST_LONG CAST_S_table3[256] = { 0x13ecf0b0, 0xd3ffb372, 0x3f85c5c1, 0x0aef7ed2, }; -OPENSSL_GLOBAL const CAST_LONG CAST_S_table4[256] = { +const CAST_LONG CAST_S_table4[256] = { 0x7ec90c04, 0x2c6e74b9, 0x9b0e66df, 0xa6337911, 0xb86a7fff, 0x1dd358f5, 0x44dd9d44, 0x1731167f, 0x08fbf1fa, 0xe7f511cc, 0xd2051b00, 0x735aba00, @@ -390,7 +342,7 @@ OPENSSL_GLOBAL const CAST_LONG CAST_S_table4[256] = { 0x5e76ffa8, 0xb1534546, 0x6d47de08, 0xefe9e7d4, }; -OPENSSL_GLOBAL const CAST_LONG CAST_S_table5[256] = { +const CAST_LONG CAST_S_table5[256] = { 0xf6fa8f9d, 0x2cac6ce1, 0x4ca34867, 0xe2337f7c, 0x95db08e7, 0x016843b4, 0xeced5cbc, 0x325553ac, 0xbf9f0960, 0xdfa1e2ed, 0x83f0579d, 0x63ed86b9, @@ -457,7 +409,7 @@ OPENSSL_GLOBAL const CAST_LONG CAST_S_table5[256] = { 0x48392905, 0xa65b1db8, 0x851c97bd, 0xd675cf2f, }; -OPENSSL_GLOBAL const CAST_LONG CAST_S_table6[256] = { +const CAST_LONG CAST_S_table6[256] = { 0x85e04019, 0x332bf567, 0x662dbfff, 0xcfc65693, 0x2a8d7f6f, 0xab9bc912, 0xde6008a1, 0x2028da1f, 0x0227bce7, 0x4d642916, 0x18fac300, 0x50f18b82, @@ -524,7 +476,7 @@ OPENSSL_GLOBAL const CAST_LONG CAST_S_table6[256] = { 0xf2a279c7, 0x94e01be8, 0x90716f4b, 0x954b8aa3, }; -OPENSSL_GLOBAL const CAST_LONG CAST_S_table7[256] = { +const CAST_LONG CAST_S_table7[256] = { 0xe216300d, 0xbbddfffc, 0xa7ebdabd, 0x35648095, 0x7789f8b7, 0xe6c1121b, 0x0e241600, 0x052ce8b5, 0x11a9cfb0, 0xe5952f11, 0xece7990a, 0x9386d174, diff --git a/crypto/cast/cast_spd.c b/crypto/cast/cast_spd.c deleted file mode 100644 index 91d2ce23f7f4..000000000000 --- a/crypto/cast/cast_spd.c +++ /dev/null @@ -1,262 +0,0 @@ -/* crypto/cast/cast_spd.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.] - */ - -/* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */ -/* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */ - -#if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX) -# define TIMES -#endif - -#include <stdio.h> - -#include <openssl/e_os2.h> -#include OPENSSL_UNISTD_IO -OPENSSL_DECLARE_EXIT -#ifndef OPENSSL_SYS_NETWARE -# include <signal.h> -#endif -#ifndef _IRIX -# include <time.h> -#endif -#ifdef TIMES -# include <sys/types.h> -# include <sys/times.h> -#endif - /* - * Depending on the VMS version, the tms structure is perhaps defined. - * The __TMS macro will show if it was. If it wasn't defined, we should - * undefine TIMES, since that tells the rest of the program how things - * should be handled. -- Richard Levitte - */ -#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS) -# undef TIMES -#endif -#ifndef TIMES -# include <sys/timeb.h> -#endif -#if defined(sun) || defined(__ultrix) -# define _POSIX_SOURCE -# include <limits.h> -# include <sys/param.h> -#endif -#include <openssl/cast.h> -/* The following if from times(3) man page. It may need to be changed */ -#ifndef HZ -# ifndef CLK_TCK -# define HZ 100.0 -# else /* CLK_TCK */ -# define HZ ((double)CLK_TCK) -# endif -#endif -#define BUFSIZE ((long)1024) -long run = 0; - -double Time_F(int s); -#ifdef SIGALRM -# if defined(__STDC__) || defined(sgi) || defined(_AIX) -# define SIGRETTYPE void -# else -# define SIGRETTYPE int -# endif - -SIGRETTYPE sig_done(int sig); -SIGRETTYPE sig_done(int sig) -{ - signal(SIGALRM, sig_done); - run = 0; -# ifdef LINT - sig = sig; -# endif -} -#endif - -#define START 0 -#define STOP 1 - -double Time_F(int s) -{ - double ret; -#ifdef TIMES - static struct tms tstart, tend; - - if (s == START) { - times(&tstart); - return (0); - } else { - times(&tend); - ret = ((double)(tend.tms_utime - tstart.tms_utime)) / HZ; - return ((ret == 0.0) ? 1e-6 : ret); - } -#else /* !times() */ - static struct timeb tstart, tend; - long i; - - if (s == START) { - ftime(&tstart); - return (0); - } else { - ftime(&tend); - i = (long)tend.millitm - (long)tstart.millitm; - ret = ((double)(tend.time - tstart.time)) + ((double)i) / 1e3; - return ((ret == 0.0) ? 1e-6 : ret); - } -#endif -} - -int main(int argc, char **argv) -{ - long count; - static unsigned char buf[BUFSIZE]; - static unsigned char key[] = { - 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, - 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, - }; - CAST_KEY sch; - double a, b, c, d; -#ifndef SIGALRM - long ca, cb, cc; -#endif - -#ifndef TIMES - printf("To get the most accurate results, try to run this\n"); - printf("program when this computer is idle.\n"); -#endif - -#ifndef SIGALRM - printf("First we calculate the approximate speed ...\n"); - CAST_set_key(&sch, 16, key); - count = 10; - do { - long i; - CAST_LONG data[2]; - - count *= 2; - Time_F(START); - for (i = count; i; i--) - CAST_encrypt(data, &sch); - d = Time_F(STOP); - } while (d < 3.0); - ca = count / 512; - cb = count; - cc = count * 8 / BUFSIZE + 1; - printf("Doing CAST_set_key %ld times\n", ca); -# define COND(d) (count != (d)) -# define COUNT(d) (d) -#else -# define COND(c) (run) -# define COUNT(d) (count) - signal(SIGALRM, sig_done); - printf("Doing CAST_set_key for 10 seconds\n"); - alarm(10); -#endif - - Time_F(START); - for (count = 0, run = 1; COND(ca); count += 4) { - CAST_set_key(&sch, 16, key); - CAST_set_key(&sch, 16, key); - CAST_set_key(&sch, 16, key); - CAST_set_key(&sch, 16, key); - } - d = Time_F(STOP); - printf("%ld cast set_key's in %.2f seconds\n", count, d); - a = ((double)COUNT(ca)) / d; - -#ifdef SIGALRM - printf("Doing CAST_encrypt's for 10 seconds\n"); - alarm(10); -#else - printf("Doing CAST_encrypt %ld times\n", cb); -#endif - Time_F(START); - for (count = 0, run = 1; COND(cb); count += 4) { - CAST_LONG data[2]; - - CAST_encrypt(data, &sch); - CAST_encrypt(data, &sch); - CAST_encrypt(data, &sch); - CAST_encrypt(data, &sch); - } - d = Time_F(STOP); - printf("%ld CAST_encrypt's in %.2f second\n", count, d); - b = ((double)COUNT(cb) * 8) / d; - -#ifdef SIGALRM - printf("Doing CAST_cbc_encrypt on %ld byte blocks for 10 seconds\n", - BUFSIZE); - alarm(10); -#else - printf("Doing CAST_cbc_encrypt %ld times on %ld byte blocks\n", cc, - BUFSIZE); -#endif - Time_F(START); - for (count = 0, run = 1; COND(cc); count++) - CAST_cbc_encrypt(buf, buf, BUFSIZE, &sch, &(key[0]), CAST_ENCRYPT); - d = Time_F(STOP); - printf("%ld CAST_cbc_encrypt's of %ld byte blocks in %.2f second\n", - count, BUFSIZE, d); - c = ((double)COUNT(cc) * BUFSIZE) / d; - - printf("CAST set_key per sec = %12.2f (%9.3fuS)\n", a, 1.0e6 / a); - printf("CAST raw ecb bytes per sec = %12.2f (%9.3fuS)\n", b, 8.0e6 / b); - printf("CAST cbc bytes per sec = %12.2f (%9.3fuS)\n", c, 8.0e6 / c); - exit(0); -#if defined(LINT) || defined(OPENSSL_SYS_MSDOS) - return (0); -#endif -} diff --git a/crypto/cast/castopts.c b/crypto/cast/castopts.c deleted file mode 100644 index 42687f2884b0..000000000000 --- a/crypto/cast/castopts.c +++ /dev/null @@ -1,334 +0,0 @@ -/* crypto/cast/castopts.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.] - */ - -/* - * define PART1, PART2, PART3 or PART4 to build only with a few of the - * options. This is for machines with 64k code segment size restrictions. - */ - -#if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) -# define TIMES -#endif - -#include <stdio.h> - -#include <openssl/e_os2.h> -#include OPENSSL_UNISTD_IO -OPENSSL_DECLARE_EXIT -#ifndef OPENSSL_SYS_NETWARE -# include <signal.h> -#endif -#ifndef _IRIX -# include <time.h> -#endif -#ifdef TIMES -# include <sys/types.h> -# include <sys/times.h> -#endif - /* - * Depending on the VMS version, the tms structure is perhaps defined. - * The __TMS macro will show if it was. If it wasn't defined, we should - * undefine TIMES, since that tells the rest of the program how things - * should be handled. -- Richard Levitte - */ -#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS) -# undef TIMES -#endif -#ifndef TIMES -# include <sys/timeb.h> -#endif -#if defined(sun) || defined(__ultrix) -# define _POSIX_SOURCE -# include <limits.h> -# include <sys/param.h> -#endif -#include <openssl/cast.h> -#define CAST_DEFAULT_OPTIONS -#undef E_CAST -#define CAST_encrypt CAST_encrypt_normal -#define CAST_decrypt CAST_decrypt_normal -#define CAST_cbc_encrypt CAST_cbc_encrypt_normal -#undef HEADER_CAST_LOCL_H -#include "c_enc.c" -#define CAST_PTR -#undef CAST_PTR2 -#undef E_CAST -#undef CAST_encrypt -#undef CAST_decrypt -#undef CAST_cbc_encrypt -#define CAST_encrypt CAST_encrypt_ptr -#define CAST_decrypt CAST_decrypt_ptr -#define CAST_cbc_encrypt CAST_cbc_encrypt_ptr -#undef HEADER_CAST_LOCL_H -#include "c_enc.c" -#undef CAST_PTR -#define CAST_PTR2 -#undef E_CAST -#undef CAST_encrypt -#undef CAST_decrypt -#undef CAST_cbc_encrypt -#define CAST_encrypt CAST_encrypt_ptr2 -#define CAST_decrypt CAST_decrypt_ptr2 -#define CAST_cbc_encrypt CAST_cbc_encrypt_ptr2 -#undef HEADER_CAST_LOCL_H -#include "c_enc.c" -/* The following if from times(3) man page. It may need to be changed */ -#ifndef HZ -# ifndef CLK_TCK -# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */ -# define HZ 100.0 -# else /* _BSD_CLK_TCK_ */ -# define HZ ((double)_BSD_CLK_TCK_) -# endif -# else /* CLK_TCK */ -# define HZ ((double)CLK_TCK) -# endif -#endif -#define BUFSIZE ((long)1024) -long run = 0; - -double Time_F(int s); -#ifdef SIGALRM -# if defined(__STDC__) || defined(sgi) -# define SIGRETTYPE void -# else -# define SIGRETTYPE int -# endif - -SIGRETTYPE sig_done(int sig); -SIGRETTYPE sig_done(int sig) -{ - signal(SIGALRM, sig_done); - run = 0; -# ifdef LINT - sig = sig; -# endif -} -#endif - -#define START 0 -#define STOP 1 - -double Time_F(int s) -{ - double ret; -#ifdef TIMES - static struct tms tstart, tend; - - if (s == START) { - times(&tstart); - return (0); - } else { - times(&tend); - ret = ((double)(tend.tms_utime - tstart.tms_utime)) / HZ; - return ((ret == 0.0) ? 1e-6 : ret); - } -#else /* !times() */ - static struct timeb tstart, tend; - long i; - - if (s == START) { - ftime(&tstart); - return (0); - } else { - ftime(&tend); - i = (long)tend.millitm - (long)tstart.millitm; - ret = ((double)(tend.time - tstart.time)) + ((double)i) / 1000.0; - return ((ret == 0.0) ? 1e-6 : ret); - } -#endif -} - -#ifdef SIGALRM -# define print_name(name) fprintf(stderr,"Doing %s's for 10 seconds\n",name); alarm(10); -#else -# define print_name(name) fprintf(stderr,"Doing %s %ld times\n",name,cb); -#endif - -#define time_it(func,name,index) \ - print_name(name); \ - Time_F(START); \ - for (count=0,run=1; COND(cb); count+=4) \ - { \ - unsigned long d[2]; \ - func(d,&sch); \ - func(d,&sch); \ - func(d,&sch); \ - func(d,&sch); \ - } \ - tm[index]=Time_F(STOP); \ - fprintf(stderr,"%ld %s's in %.2f second\n",count,name,tm[index]); \ - tm[index]=((double)COUNT(cb))/tm[index]; - -#define print_it(name,index) \ - fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \ - tm[index]*8,1.0e6/tm[index]); - -int main(int argc, char **argv) -{ - long count; - static unsigned char buf[BUFSIZE]; - static char key[16] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, - 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 - }; - CAST_KEY sch; - double d, tm[16], max = 0; - int rank[16]; - char *str[16]; - int max_idx = 0, i, num = 0, j; -#ifndef SIGALARM - long ca, cb, cc, cd, ce; -#endif - - for (i = 0; i < 12; i++) { - tm[i] = 0.0; - rank[i] = 0; - } - -#ifndef TIMES - fprintf(stderr, "To get the most accurate results, try to run this\n"); - fprintf(stderr, "program when this computer is idle.\n"); -#endif - - CAST_set_key(&sch, 16, key); - -#ifndef SIGALRM - fprintf(stderr, "First we calculate the approximate speed ...\n"); - count = 10; - do { - long i; - unsigned long data[2]; - - count *= 2; - Time_F(START); - for (i = count; i; i--) - CAST_encrypt(data, &sch); - d = Time_F(STOP); - } while (d < 3.0); - ca = count; - cb = count * 3; - cc = count * 3 * 8 / BUFSIZE + 1; - cd = count * 8 / BUFSIZE + 1; - - ce = count / 20 + 1; -# define COND(d) (count != (d)) -# define COUNT(d) (d) -#else -# define COND(c) (run) -# define COUNT(d) (count) - signal(SIGALRM, sig_done); - alarm(10); -#endif - - time_it(CAST_encrypt_normal, "CAST_encrypt_normal ", 0); - time_it(CAST_encrypt_ptr, "CAST_encrypt_ptr ", 1); - time_it(CAST_encrypt_ptr2, "CAST_encrypt_ptr2 ", 2); - num += 3; - - str[0] = "<nothing>"; - print_it("CAST_encrypt_normal ", 0); - max = tm[0]; - max_idx = 0; - str[1] = "ptr "; - print_it("CAST_encrypt_ptr ", 1); - if (max < tm[1]) { - max = tm[1]; - max_idx = 1; - } - str[2] = "ptr2 "; - print_it("CAST_encrypt_ptr2 ", 2); - if (max < tm[2]) { - max = tm[2]; - max_idx = 2; - } - - printf("options CAST ecb/s\n"); - printf("%s %12.2f 100.0%%\n", str[max_idx], tm[max_idx]); - d = tm[max_idx]; - tm[max_idx] = -2.0; - max = -1.0; - for (;;) { - for (i = 0; i < 3; i++) { - if (max < tm[i]) { - max = tm[i]; - j = i; - } - } - if (max < 0.0) - break; - printf("%s %12.2f %4.1f%%\n", str[j], tm[j], tm[j] / d * 100.0); - tm[j] = -2.0; - max = -1.0; - } - - switch (max_idx) { - case 0: - printf("-DCAST_DEFAULT_OPTIONS\n"); - break; - case 1: - printf("-DCAST_PTR\n"); - break; - case 2: - printf("-DCAST_PTR2\n"); - break; - } - exit(0); -#if defined(LINT) || defined(OPENSSL_SYS_MSDOS) - return (0); -#endif -} diff --git a/crypto/cast/casttest.c b/crypto/cast/casttest.c deleted file mode 100644 index dc31bc6604a8..000000000000 --- a/crypto/cast/casttest.c +++ /dev/null @@ -1,241 +0,0 @@ -/* crypto/cast/casttest.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.] - */ - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <openssl/opensslconf.h> /* To see if OPENSSL_NO_CAST is defined */ - -#include "../e_os.h" - -#ifdef OPENSSL_NO_CAST -int main(int argc, char *argv[]) -{ - printf("No CAST support\n"); - return (0); -} -#else -# include <openssl/cast.h> - -# define FULL_TEST - -static unsigned char k[16] = { - 0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78, - 0x23, 0x45, 0x67, 0x89, 0x34, 0x56, 0x78, 0x9A -}; - -static unsigned char in[8] = - { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF }; - -static int k_len[3] = { 16, 10, 5 }; - -static unsigned char c[3][8] = { - {0x23, 0x8B, 0x4F, 0xE5, 0x84, 0x7E, 0x44, 0xB2}, - {0xEB, 0x6A, 0x71, 0x1A, 0x2C, 0x02, 0x27, 0x1B}, - {0x7A, 0xC8, 0x16, 0xD1, 0x6E, 0x9B, 0x30, 0x2E}, -}; - -static unsigned char out[80]; - -static unsigned char in_a[16] = { - 0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78, - 0x23, 0x45, 0x67, 0x89, 0x34, 0x56, 0x78, 0x9A -}; - -static unsigned char in_b[16] = { - 0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78, - 0x23, 0x45, 0x67, 0x89, 0x34, 0x56, 0x78, 0x9A -}; - -static unsigned char c_a[16] = { - 0xEE, 0xA9, 0xD0, 0xA2, 0x49, 0xFD, 0x3B, 0xA6, - 0xB3, 0x43, 0x6F, 0xB8, 0x9D, 0x6D, 0xCA, 0x92 -}; - -static unsigned char c_b[16] = { - 0xB2, 0xC9, 0x5E, 0xB0, 0x0C, 0x31, 0xAD, 0x71, - 0x80, 0xAC, 0x05, 0xB8, 0xE8, 0x3D, 0x69, 0x6E -}; - -# if 0 -char *text = "Hello to all people out there"; - -static unsigned char cfb_key[16] = { - 0xe1, 0xf0, 0xc3, 0xd2, 0xa5, 0xb4, 0x87, 0x96, - 0x69, 0x78, 0x4b, 0x5a, 0x2d, 0x3c, 0x0f, 0x1e, -}; -static unsigned char cfb_iv[80] = - { 0x34, 0x12, 0x78, 0x56, 0xab, 0x90, 0xef, 0xcd }; -static unsigned char cfb_buf1[40], cfb_buf2[40], cfb_tmp[8]; -# define CFB_TEST_SIZE 24 -static unsigned char plain[CFB_TEST_SIZE] = { - 0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73, - 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, - 0x69, 0x6d, 0x65, 0x20, 0x66, 0x6f, - 0x72, 0x20, 0x61, 0x6c, 0x6c, 0x20 -}; - -static unsigned char cfb_cipher64[CFB_TEST_SIZE] = { - 0x59, 0xD8, 0xE2, 0x65, 0x00, 0x58, 0x6C, 0x3F, - 0x2C, 0x17, 0x25, 0xD0, 0x1A, 0x38, 0xB7, 0x2A, - 0x39, 0x61, 0x37, 0xDC, 0x79, 0xFB, 0x9F, 0x45 -/*- 0xF9,0x78,0x32,0xB5,0x42,0x1A,0x6B,0x38, - 0x9A,0x44,0xD6,0x04,0x19,0x43,0xC4,0xD9, - 0x3D,0x1E,0xAE,0x47,0xFC,0xCF,0x29,0x0B,*/ -}; -# endif - -int main(int argc, char *argv[]) -{ -# ifdef FULL_TEST - long l; - CAST_KEY key_b; -# endif - int i, z, err = 0; - CAST_KEY key; - - for (z = 0; z < 3; z++) { - CAST_set_key(&key, k_len[z], k); - - CAST_ecb_encrypt(in, out, &key, CAST_ENCRYPT); - if (memcmp(out, &(c[z][0]), 8) != 0) { - printf("ecb cast error encrypting for keysize %d\n", - k_len[z] * 8); - printf("got :"); - for (i = 0; i < 8; i++) - printf("%02X ", out[i]); - printf("\n"); - printf("expected:"); - for (i = 0; i < 8; i++) - printf("%02X ", c[z][i]); - err = 20; - printf("\n"); - } - - CAST_ecb_encrypt(out, out, &key, CAST_DECRYPT); - if (memcmp(out, in, 8) != 0) { - printf("ecb cast error decrypting for keysize %d\n", - k_len[z] * 8); - printf("got :"); - for (i = 0; i < 8; i++) - printf("%02X ", out[i]); - printf("\n"); - printf("expected:"); - for (i = 0; i < 8; i++) - printf("%02X ", in[i]); - printf("\n"); - err = 3; - } - } - if (err == 0) - printf("ecb cast5 ok\n"); - -# ifdef FULL_TEST - { - unsigned char out_a[16], out_b[16]; - static char *hex = "0123456789ABCDEF"; - - printf("This test will take some time...."); - fflush(stdout); - memcpy(out_a, in_a, sizeof(in_a)); - memcpy(out_b, in_b, sizeof(in_b)); - i = 1; - - for (l = 0; l < 1000000L; l++) { - CAST_set_key(&key_b, 16, out_b); - CAST_ecb_encrypt(&(out_a[0]), &(out_a[0]), &key_b, CAST_ENCRYPT); - CAST_ecb_encrypt(&(out_a[8]), &(out_a[8]), &key_b, CAST_ENCRYPT); - CAST_set_key(&key, 16, out_a); - CAST_ecb_encrypt(&(out_b[0]), &(out_b[0]), &key, CAST_ENCRYPT); - CAST_ecb_encrypt(&(out_b[8]), &(out_b[8]), &key, CAST_ENCRYPT); - if ((l & 0xffff) == 0xffff) { - printf("%c", hex[i & 0x0f]); - fflush(stdout); - i++; - } - } - - if ((memcmp(out_a, c_a, sizeof(c_a)) != 0) || - (memcmp(out_b, c_b, sizeof(c_b)) != 0)) { - printf("\n"); - printf("Error\n"); - - printf("A out ="); - for (i = 0; i < 16; i++) - printf("%02X ", out_a[i]); - printf("\nactual="); - for (i = 0; i < 16; i++) - printf("%02X ", c_a[i]); - printf("\n"); - - printf("B out ="); - for (i = 0; i < 16; i++) - printf("%02X ", out_b[i]); - printf("\nactual="); - for (i = 0; i < 16; i++) - printf("%02X ", c_b[i]); - printf("\n"); - } else - printf(" ok\n"); - } -# endif - - EXIT(err); - return (err); -} -#endif |