From 58964a492275ca9a59a0cd9c8155cb2491b4b909 Mon Sep 17 00:00:00 2001 From: "Ralf S. Engelschall" Date: Mon, 21 Dec 1998 10:56:39 +0000 Subject: Import of old SSLeay release: SSLeay 0.9.0b --- crypto/idea/Makefile.uni | 72 +++++++++++ crypto/idea/i_cbc.c | 37 +++++- crypto/idea/i_cfb64.c | 2 +- crypto/idea/i_ecb.c | 56 +-------- crypto/idea/i_ofb64.c | 2 +- crypto/idea/i_skey.c | 2 +- crypto/idea/idea_lcl.h | 22 +++- crypto/idea/idea_spd.c | 315 +++++++++++++++++++++++++++++++++++++++++++++++ crypto/idea/ideatest.c | 2 +- 9 files changed, 449 insertions(+), 61 deletions(-) create mode 100644 crypto/idea/Makefile.uni create mode 100644 crypto/idea/idea_spd.c (limited to 'crypto/idea') diff --git a/crypto/idea/Makefile.uni b/crypto/idea/Makefile.uni new file mode 100644 index 0000000000..354123dac8 --- /dev/null +++ b/crypto/idea/Makefile.uni @@ -0,0 +1,72 @@ +# Targets +# make - twidle the options yourself :-) +# make cc - standard cc options +# make gcc - standard gcc options + +DIR= cast +TOP= . +CC= gcc +CFLAG= -O3 -fomit-frame-pointer + +CPP= $(CC) -E +INCLUDES= +INSTALLTOP=/usr/local/lib +MAKE= make +MAKEDEPEND= makedepend +MAKEFILE= Makefile.uni +AR= ar r + +IDEA_ENC=i_cbc.o + +CFLAGS= $(INCLUDES) $(CFLAG) + +GENERAL=Makefile +TEST=ideatest +APPS=idea_spd + +LIB=libidea.a +LIBSRC=i_skey.c i_ecb.c i_cbc.c i_cfb64.c i_ofb64.c +LIBOBJ=i_skey.o i_ecb.o $(IDEA_ENC) i_cfb64.o i_ofb64.o + +SRC= $(LIBSRC) + +EXHEADER= idea.h +HEADER= idea_lcl.h $(EXHEADER) + +ALL= $(GENERAL) $(SRC) $(HEADER) + +all: $(LIB) $(TEST) $(APPS) + +$(LIB): $(LIBOBJ) + $(AR) $(LIB) $(LIBOBJ) + sh $(TOP)/ranlib.sh $(LIB) + +test: $(TEST) + ./$(TEST) + +$(TEST): $(TEST).c $(LIB) + $(CC) -o $(TEST) $(CFLAGS) $(TEST).c $(LIB) + +$(APPS): $(APPS).c $(LIB) + $(CC) -o $(APPS) $(CFLAGS) $(APPS).c $(LIB) + +lint: + lint -DLINT $(INCLUDES) $(SRC)>fluff + +depend: + $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + +dclean: + perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + mv -f Makefile.new $(MAKEFILE) + +clean: + /bin/rm -f $(LIB) $(TEST) $(APPS) *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff + +cc: + $(MAKE) CC="cc" CFLAG="-O" all + +gcc: + $(MAKE) CC="gcc" CFLAGS="-O3 -fomit-frame-pointer" all + +# DO NOT DELETE THIS LINE -- make depend depends on it. diff --git a/crypto/idea/i_cbc.c b/crypto/idea/i_cbc.c index d17e9f29e0..716ea3f474 100644 --- a/crypto/idea/i_cbc.c +++ b/crypto/idea/i_cbc.c @@ -1,5 +1,5 @@ /* crypto/idea/i_cbc.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written @@ -138,3 +138,38 @@ int encrypt; tin[0]=tin[1]=0; } +void idea_encrypt(d,key) +unsigned long *d; +IDEA_KEY_SCHEDULE *key; + { + register IDEA_INT *p; + register unsigned long x1,x2,x3,x4,t0,t1,ul; + + x2=d[0]; + x1=(x2>>16); + x4=d[1]; + x3=(x4>>16); + + p= &(key->data[0][0]); + + E_IDEA(0); + E_IDEA(1); + E_IDEA(2); + E_IDEA(3); + E_IDEA(4); + E_IDEA(5); + E_IDEA(6); + E_IDEA(7); + + x1&=0xffff; + idea_mul(x1,x1,*p,ul); p++; + + t0= x3+ *(p++); + t1= x2+ *(p++); + + x4&=0xffff; + idea_mul(x4,x4,*p,ul); + + d[0]=(t0&0xffff)|((x1&0xffff)<<16); + d[1]=(x4&0xffff)|((t1&0xffff)<<16); + } diff --git a/crypto/idea/i_cfb64.c b/crypto/idea/i_cfb64.c index 366f2d19cf..8dfa7ece48 100644 --- a/crypto/idea/i_cfb64.c +++ b/crypto/idea/i_cfb64.c @@ -1,5 +1,5 @@ /* crypto/idea/i_cfb64.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written diff --git a/crypto/idea/i_ecb.c b/crypto/idea/i_ecb.c index b3b694b0c6..6721126db1 100644 --- a/crypto/idea/i_ecb.c +++ b/crypto/idea/i_ecb.c @@ -1,5 +1,5 @@ /* crypto/idea/i_ecb.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written @@ -59,7 +59,7 @@ #include "idea.h" #include "idea_lcl.h" -char *IDEA_version="IDEA part of SSLeay 0.8.1b 29-Jun-1998"; +char *IDEA_version="IDEA part of SSLeay 0.9.0b 29-Jun-1998"; char *idea_options() { @@ -84,55 +84,3 @@ IDEA_KEY_SCHEDULE *ks; l0=l1=d[0]=d[1]=0; } -void idea_encrypt(d,key) -unsigned long *d; -IDEA_KEY_SCHEDULE *key; - { - int i; - register IDEA_INT *p; - register unsigned long x1,x2,x3,x4,t0,t1,ul; - - x2=d[0]; - x1=(x2>>16); - x4=d[1]; - x3=(x4>>16); - - p= &(key->data[0][0]); - for (i=0; i<8; i++) - { - x1&=0xffff; - idea_mul(x1,x1,*p,ul); p++; - - x2+= *(p++); - x3+= *(p++); - - x4&=0xffff; - idea_mul(x4,x4,*p,ul); p++; - - t0=(x1^x3)&0xffff; - idea_mul(t0,t0,*p,ul); p++; - - t1=(t0+(x2^x4))&0xffff; - idea_mul(t1,t1,*p,ul); p++; - - t0+=t1; - - x1^=t1; - x4^=t0; - ul=x2^t0; /* do the swap to x3 */ - x2=x3^t1; - x3=ul; - } - - x1&=0xffff; - idea_mul(x1,x1,*p,ul); p++; - - t0= x3+ *(p++); - t1= x2+ *(p++); - - x4&=0xffff; - idea_mul(x4,x4,*p,ul); - - d[0]=(t0&0xffff)|((x1&0xffff)<<16); - d[1]=(x4&0xffff)|((t1&0xffff)<<16); - } diff --git a/crypto/idea/i_ofb64.c b/crypto/idea/i_ofb64.c index 43a9584a37..d687adb22d 100644 --- a/crypto/idea/i_ofb64.c +++ b/crypto/idea/i_ofb64.c @@ -1,5 +1,5 @@ /* crypto/idea/i_ofb64.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written diff --git a/crypto/idea/i_skey.c b/crypto/idea/i_skey.c index fcbdb691e2..00fcc1e586 100644 --- a/crypto/idea/i_skey.c +++ b/crypto/idea/i_skey.c @@ -1,5 +1,5 @@ /* crypto/idea/i_skey.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written diff --git a/crypto/idea/idea_lcl.h b/crypto/idea/idea_lcl.h index fcd007f2b4..4cf256ae87 100644 --- a/crypto/idea/idea_lcl.h +++ b/crypto/idea/idea_lcl.h @@ -1,5 +1,5 @@ /* crypto/idea/idea_lcl.h */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written @@ -65,7 +65,6 @@ if (ul != 0) \ { \ r=(ul&0xffff)-(ul>>16); \ r-=((r)>>16); \ -/* if (r&0xffff0000L) r=(r+0x10001); */ \ } \ else \ r=(-(int)a-b+1); /* assuming a or b is 0 and in range */ \ @@ -195,3 +194,22 @@ else { \ *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ *((c)++)=(unsigned char)(((l)>>24L)&0xff)) #endif + +#define E_IDEA(num) \ + x1&=0xffff; \ + idea_mul(x1,x1,*p,ul); p++; \ + x2+= *(p++); \ + x3+= *(p++); \ + x4&=0xffff; \ + idea_mul(x4,x4,*p,ul); p++; \ + t0=(x1^x3)&0xffff; \ + idea_mul(t0,t0,*p,ul); p++; \ + t1=(t0+(x2^x4))&0xffff; \ + idea_mul(t1,t1,*p,ul); p++; \ + t0+=t1; \ + x1^=t1; \ + x4^=t0; \ + ul=x2^t0; /* do the swap to x3 */ \ + x2=x3^t1; \ + x3=ul; + diff --git a/crypto/idea/idea_spd.c b/crypto/idea/idea_spd.c new file mode 100644 index 0000000000..4b3eec5123 --- /dev/null +++ b/crypto/idea/idea_spd.c @@ -0,0 +1,315 @@ +/* crypto/idea/idea_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 */ + +#ifndef MSDOS +#define TIMES +#endif + +#include +#ifndef MSDOS +#include +#else +#include +extern int exit(); +#endif +#include +#ifndef VMS +#ifndef _IRIX +#include +#endif +#ifdef TIMES +#include +#include +#endif +#else /* VMS */ +#include +struct tms { + time_t tms_utime; + time_t tms_stime; + time_t tms_uchild; /* I dunno... */ + time_t tms_uchildsys; /* so these names are a guess :-) */ + } +#endif +#ifndef TIMES +#include +#endif + +#ifdef sun +#include +#include +#endif + +#include "idea.h" + +/* The following if from times(3) man page. It may need to be changed */ +#ifndef HZ +#ifndef CLK_TCK +#ifndef VMS +#define HZ 100.0 +#else /* VMS */ +#define HZ 100.0 +#endif +#else /* CLK_TCK */ +#define HZ ((double)CLK_TCK) +#endif +#endif + +#define BUFSIZE ((long)1024) +long run=0; + +#ifndef NOPROTO +double Time_F(int s); +#else +double Time_F(); +#endif + +#ifdef SIGALRM +#if defined(__STDC__) || defined(sgi) || defined(_AIX) +#define SIGRETTYPE void +#else +#define SIGRETTYPE int +#endif + +#ifndef NOPROTO +SIGRETTYPE sig_done(int sig); +#else +SIGRETTYPE sig_done(); +#endif + +SIGRETTYPE sig_done(sig) +int sig; + { + signal(SIGALRM,sig_done); + run=0; +#ifdef LINT + sig=sig; +#endif + } +#endif + +#define START 0 +#define STOP 1 + +double Time_F(s) +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(argc,argv) +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, + }; + IDEA_KEY_SCHEDULE sch; + double a,aa,b,c,d; +#ifndef SIGALRM + long ca,cca,cb,cc; +#endif + +#ifndef TIMES + printf("To get the most acurate 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"); + idea_set_encrypt_key(key,&sch); + count=10; + do { + long i; + IDEA_INT data[2]; + + count*=2; + Time_F(START); + for (i=count; i; i--) + idea_encrypt(data,&sch); + d=Time_F(STOP); + } while (d < 3.0); + ca=count/4; + cca=count/200; + cb=count; + cc=count*8/BUFSIZE+1; + printf("idea_set_encrypt_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 idea_set_encrypt_key for 10 seconds\n"); + alarm(10); +#endif + + Time_F(START); + for (count=0,run=1; COND(ca); count+=4) + { + idea_set_encrypt_key(key,&sch); + idea_set_encrypt_key(key,&sch); + idea_set_encrypt_key(key,&sch); + idea_set_encrypt_key(key,&sch); + } + d=Time_F(STOP); + printf("%ld idea idea_set_encrypt_key's in %.2f seconds\n",count,d); + a=((double)COUNT(ca))/d; + +#ifdef SIGALRM + printf("Doing idea_set_decrypt_key for 10 seconds\n"); + alarm(10); +#else + printf("Doing idea_set_decrypt_key %ld times\n",cca); +#endif + + Time_F(START); + for (count=0,run=1; COND(cca); count+=4) + { + idea_set_decrypt_key(&sch,&sch); + idea_set_decrypt_key(&sch,&sch); + idea_set_decrypt_key(&sch,&sch); + idea_set_decrypt_key(&sch,&sch); + } + d=Time_F(STOP); + printf("%ld idea idea_set_decrypt_key's in %.2f seconds\n",count,d); + aa=((double)COUNT(cca))/d; + +#ifdef SIGALRM + printf("Doing idea_encrypt's for 10 seconds\n"); + alarm(10); +#else + printf("Doing idea_encrypt %ld times\n",cb); +#endif + Time_F(START); + for (count=0,run=1; COND(cb); count+=4) + { + unsigned long data[2]; + + idea_encrypt(data,&sch); + idea_encrypt(data,&sch); + idea_encrypt(data,&sch); + idea_encrypt(data,&sch); + } + d=Time_F(STOP); + printf("%ld idea_encrypt's in %.2f second\n",count,d); + b=((double)COUNT(cb)*8)/d; + +#ifdef SIGALRM + printf("Doing idea_cbc_encrypt on %ld byte blocks for 10 seconds\n", + BUFSIZE); + alarm(10); +#else + printf("Doing idea_cbc_encrypt %ld times on %ld byte blocks\n",cc, + BUFSIZE); +#endif + Time_F(START); + for (count=0,run=1; COND(cc); count++) + idea_cbc_encrypt(buf,buf,BUFSIZE,&sch, + &(key[0]),IDEA_ENCRYPT); + d=Time_F(STOP); + printf("%ld idea_cbc_encrypt's of %ld byte blocks in %.2f second\n", + count,BUFSIZE,d); + c=((double)COUNT(cc)*BUFSIZE)/d; + + printf("IDEA set_encrypt_key per sec = %12.2f (%9.3fuS)\n",a,1.0e6/a); + printf("IDEA set_decrypt_key per sec = %12.2f (%9.3fuS)\n",aa,1.0e6/aa); + printf("IDEA raw ecb bytes per sec = %12.2f (%9.3fuS)\n",b,8.0e6/b); + printf("IDEA cbc bytes per sec = %12.2f (%9.3fuS)\n",c,8.0e6/c); + exit(0); +#if defined(LINT) || defined(MSDOS) + return(0); +#endif + } + diff --git a/crypto/idea/ideatest.c b/crypto/idea/ideatest.c index ee01ba5b2c..6eff9029cc 100644 --- a/crypto/idea/ideatest.c +++ b/crypto/idea/ideatest.c @@ -1,5 +1,5 @@ /* crypto/idea/ideatest.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written -- cgit v1.2.3