diff options
author | Ralf S. Engelschall <rse@openssl.org> | 1998-12-21 11:56:39 +0100 |
---|---|---|
committer | Ralf S. Engelschall <rse@openssl.org> | 1998-12-21 11:56:39 +0100 |
commit | 58964a492275ca9a59a0cd9c8155cb2491b4b909 (patch) | |
tree | c7b16876a5789463bbbb468ef4829c8129b3d718 /crypto/rc2 | |
parent | Import of old SSLeay release: SSLeay 0.8.1b (diff) | |
download | openssl-58964a492275ca9a59a0cd9c8155cb2491b4b909.tar.xz openssl-58964a492275ca9a59a0cd9c8155cb2491b4b909.zip |
Import of old SSLeay release: SSLeay 0.9.0b
Diffstat (limited to 'crypto/rc2')
-rw-r--r-- | crypto/rc2/Makefile.uni | 72 | ||||
-rw-r--r-- | crypto/rc2/rc2.h | 4 | ||||
-rw-r--r-- | crypto/rc2/rc2.org | 4 | ||||
-rw-r--r-- | crypto/rc2/rc2_cbc.c | 105 | ||||
-rw-r--r-- | crypto/rc2/rc2_ecb.c | 85 | ||||
-rw-r--r-- | crypto/rc2/rc2_locl.h | 12 | ||||
-rw-r--r-- | crypto/rc2/rc2_skey.c | 2 | ||||
-rw-r--r-- | crypto/rc2/rc2cfb64.c | 6 | ||||
-rw-r--r-- | crypto/rc2/rc2ofb64.c | 4 | ||||
-rw-r--r-- | crypto/rc2/rc2speed.c | 293 | ||||
-rw-r--r-- | crypto/rc2/rc2test.c | 2 |
11 files changed, 495 insertions, 94 deletions
diff --git a/crypto/rc2/Makefile.uni b/crypto/rc2/Makefile.uni new file mode 100644 index 0000000000..e50b3f2d19 --- /dev/null +++ b/crypto/rc2/Makefile.uni @@ -0,0 +1,72 @@ +# Targets +# make - twidle the options yourself :-) +# make cc - standard cc options +# make gcc - standard gcc options + +DIR= rc2 +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=rc2_cbc.o + +CFLAGS= $(INCLUDES) $(CFLAG) + +GENERAL=Makefile +TEST=rc2test +APPS=rc2speed + +LIB=librc2.a +LIBSRC=rc2_skey.c rc2_ecb.c rc2_cbc.c rc2cfb64.c rc2ofb64.c +LIBOBJ=rc2_skey.o rc2_ecb.o $(IDEA_ENC) rc2cfb64.o rc2ofb64.o + +SRC= $(LIBSRC) + +EXHEADER= rc2.h +HEADER= rc2_locl.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/rc2/rc2.h b/crypto/rc2/rc2.h index 0903417fc3..9232bbd564 100644 --- a/crypto/rc2/rc2.h +++ b/crypto/rc2/rc2.h @@ -90,7 +90,8 @@ typedef struct rc2_key_st void RC2_set_key(RC2_KEY *key, int len, unsigned char *data,int bits); void RC2_ecb_encrypt(unsigned char *in,unsigned char *out,RC2_KEY *key, int enc); -void RC2_encrypt(unsigned long *data,RC2_KEY *key,int enc); +void RC2_encrypt(unsigned long *data,RC2_KEY *key); +void RC2_decrypt(unsigned long *data,RC2_KEY *key); void RC2_cbc_encrypt(unsigned char *in, unsigned char *out, long length, RC2_KEY *ks, unsigned char *iv, int enc); void RC2_cfb64_encrypt(unsigned char *in, unsigned char *out, long length, @@ -103,6 +104,7 @@ void RC2_ofb64_encrypt(unsigned char *in, unsigned char *out, long length, void RC2_set_key(); void RC2_ecb_encrypt(); void RC2_encrypt(); +void RC2_decrypt(); void RC2_cbc_encrypt(); void RC2_cfb64_encrypt(); void RC2_ofb64_encrypt(); diff --git a/crypto/rc2/rc2.org b/crypto/rc2/rc2.org index af9310f13e..37354cfa62 100644 --- a/crypto/rc2/rc2.org +++ b/crypto/rc2/rc2.org @@ -90,7 +90,8 @@ typedef struct rc2_key_st void RC2_set_key(RC2_KEY *key, int len, unsigned char *data,int bits); void RC2_ecb_encrypt(unsigned char *in,unsigned char *out,RC2_KEY *key, int enc); -void RC2_encrypt(unsigned long *data,RC2_KEY *key,int enc); +void RC2_encrypt(unsigned long *data,RC2_KEY *key); +void RC2_decrypt(unsigned long *data,RC2_KEY *key); void RC2_cbc_encrypt(unsigned char *in, unsigned char *out, long length, RC2_KEY *ks, unsigned char *iv, int enc); void RC2_cfb64_encrypt(unsigned char *in, unsigned char *out, long length, @@ -103,6 +104,7 @@ void RC2_ofb64_encrypt(unsigned char *in, unsigned char *out, long length, void RC2_set_key(); void RC2_ecb_encrypt(); void RC2_encrypt(); +void RC2_decrypt(); void RC2_cbc_encrypt(); void RC2_cfb64_encrypt(); void RC2_ofb64_encrypt(); diff --git a/crypto/rc2/rc2_cbc.c b/crypto/rc2/rc2_cbc.c index 24e7759357..22e89f0441 100644 --- a/crypto/rc2/rc2_cbc.c +++ b/crypto/rc2/rc2_cbc.c @@ -1,5 +1,5 @@ /* crypto/rc2/rc2_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 @@ -85,7 +85,7 @@ int encrypt; tin1^=tout1; tin[0]=tin0; tin[1]=tin1; - RC2_encrypt(tin,ks,RC2_ENCRYPT); + RC2_encrypt(tin,ks); tout0=tin[0]; l2c(tout0,out); tout1=tin[1]; l2c(tout1,out); } @@ -96,7 +96,7 @@ int encrypt; tin1^=tout1; tin[0]=tin0; tin[1]=tin1; - RC2_encrypt(tin,ks,RC2_ENCRYPT); + RC2_encrypt(tin,ks); tout0=tin[0]; l2c(tout0,out); tout1=tin[1]; l2c(tout1,out); } @@ -112,7 +112,7 @@ int encrypt; { c2l(in,tin0); tin[0]=tin0; c2l(in,tin1); tin[1]=tin1; - RC2_encrypt(tin,ks,RC2_DECRYPT); + RC2_decrypt(tin,ks); tout0=tin[0]^xor0; tout1=tin[1]^xor1; l2c(tout0,out); @@ -124,7 +124,7 @@ int encrypt; { c2l(in,tin0); tin[0]=tin0; c2l(in,tin1); tin[1]=tin1; - RC2_encrypt(tin,ks,RC2_DECRYPT); + RC2_decrypt(tin,ks); tout0=tin[0]^xor0; tout1=tin[1]^xor1; l2cn(tout0,tout1,out,l+8); @@ -138,3 +138,98 @@ int encrypt; tin[0]=tin[1]=0; } +void RC2_encrypt(d,key) +unsigned long *d; +RC2_KEY *key; + { + int i,n; + register RC2_INT *p0,*p1; + register RC2_INT x0,x1,x2,x3,t; + unsigned long l; + + l=d[0]; + x0=(RC2_INT)l&0xffff; + x1=(RC2_INT)(l>>16L); + l=d[1]; + x2=(RC2_INT)l&0xffff; + x3=(RC2_INT)(l>>16L); + + n=3; + i=5; + + p0=p1= &(key->data[0]); + for (;;) + { + t=(x0+(x1& ~x3)+(x2&x3)+ *(p0++))&0xffff; + x0=(t<<1)|(t>>15); + t=(x1+(x2& ~x0)+(x3&x0)+ *(p0++))&0xffff; + x1=(t<<2)|(t>>14); + t=(x2+(x3& ~x1)+(x0&x1)+ *(p0++))&0xffff; + x2=(t<<3)|(t>>13); + t=(x3+(x0& ~x2)+(x1&x2)+ *(p0++))&0xffff; + x3=(t<<5)|(t>>11); + + if (--i == 0) + { + if (--n == 0) break; + i=(n == 2)?6:5; + + x0+=p1[x3&0x3f]; + x1+=p1[x0&0x3f]; + x2+=p1[x1&0x3f]; + x3+=p1[x2&0x3f]; + } + } + + d[0]=(unsigned long)(x0&0xffff)|((unsigned long)(x1&0xffff)<<16L); + d[1]=(unsigned long)(x2&0xffff)|((unsigned long)(x3&0xffff)<<16L); + } + +void RC2_decrypt(d,key) +unsigned long *d; +RC2_KEY *key; + { + int i,n; + register RC2_INT *p0,*p1; + register RC2_INT x0,x1,x2,x3,t; + unsigned long l; + + l=d[0]; + x0=(RC2_INT)l&0xffff; + x1=(RC2_INT)(l>>16L); + l=d[1]; + x2=(RC2_INT)l&0xffff; + x3=(RC2_INT)(l>>16L); + + n=3; + i=5; + + p0= &(key->data[63]); + p1= &(key->data[0]); + for (;;) + { + t=((x3<<11)|(x3>>5))&0xffff; + x3=(t-(x0& ~x2)-(x1&x2)- *(p0--))&0xffff; + t=((x2<<13)|(x2>>3))&0xffff; + x2=(t-(x3& ~x1)-(x0&x1)- *(p0--))&0xffff; + t=((x1<<14)|(x1>>2))&0xffff; + x1=(t-(x2& ~x0)-(x3&x0)- *(p0--))&0xffff; + t=((x0<<15)|(x0>>1))&0xffff; + x0=(t-(x1& ~x3)-(x2&x3)- *(p0--))&0xffff; + + if (--i == 0) + { + if (--n == 0) break; + i=(n == 2)?6:5; + + x3=(x3-p1[x2&0x3f])&0xffff; + x2=(x2-p1[x1&0x3f])&0xffff; + x1=(x1-p1[x0&0x3f])&0xffff; + x0=(x0-p1[x3&0x3f])&0xffff; + } + } + + d[0]=(unsigned long)(x0&0xffff)|((unsigned long)(x1&0xffff)<<16L); + d[1]=(unsigned long)(x2&0xffff)|((unsigned long)(x3&0xffff)<<16L); + } + diff --git a/crypto/rc2/rc2_ecb.c b/crypto/rc2/rc2_ecb.c index 65b5d3536a..96239cd4e0 100644 --- a/crypto/rc2/rc2_ecb.c +++ b/crypto/rc2/rc2_ecb.c @@ -1,5 +1,5 @@ /* crypto/rc2/rc2_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 "rc2.h" #include "rc2_locl.h" -char *RC2_version="RC2 part of SSLeay 0.8.1b 29-Jun-1998"; +char *RC2_version="RC2 part of SSLeay 0.9.0b 29-Jun-1998"; /* RC2 as implemented frm a posting from * Newsgroups: sci.crypt @@ -79,85 +79,12 @@ int encrypt; c2l(in,l); d[0]=l; c2l(in,l); d[1]=l; - RC2_encrypt(d,ks,encrypt); + if (encrypt) + RC2_encrypt(d,ks); + else + RC2_decrypt(d,ks); l=d[0]; l2c(l,out); l=d[1]; l2c(l,out); l=d[0]=d[1]=0; } -void RC2_encrypt(d,key,encrypt) -unsigned long *d; -RC2_KEY *key; -int encrypt; - { - int i,n; - register RC2_INT *p0,*p1; - register RC2_INT x0,x1,x2,x3,t; - unsigned long l; - - l=d[0]; - x0=(RC2_INT)l&0xffff; - x1=(RC2_INT)(l>>16L); - l=d[1]; - x2=(RC2_INT)l&0xffff; - x3=(RC2_INT)(l>>16L); - - n=3; - i=5; - if (encrypt) - { - p0=p1= &(key->data[0]); - for (;;) - { - t=(x0+(x1& ~x3)+(x2&x3)+ *(p0++))&0xffff; - x0=(t<<1)|(t>>15); - t=(x1+(x2& ~x0)+(x3&x0)+ *(p0++))&0xffff; - x1=(t<<2)|(t>>14); - t=(x2+(x3& ~x1)+(x0&x1)+ *(p0++))&0xffff; - x2=(t<<3)|(t>>13); - t=(x3+(x0& ~x2)+(x1&x2)+ *(p0++))&0xffff; - x3=(t<<5)|(t>>11); - - if (--i == 0) - { - if (--n == 0) break; - i=(n == 2)?6:5; - - x0+=p1[x3&0x3f]; - x1+=p1[x0&0x3f]; - x2+=p1[x1&0x3f]; - x3+=p1[x2&0x3f]; - } - } - } - else - { - p0= &(key->data[63]); - p1= &(key->data[0]); - for (;;) - { - t=((x3<<11)|(x3>>5))&0xffff; - x3=(t-(x0& ~x2)-(x1&x2)- *(p0--))&0xffff; - t=((x2<<13)|(x2>>3))&0xffff; - x2=(t-(x3& ~x1)-(x0&x1)- *(p0--))&0xffff; - t=((x1<<14)|(x1>>2))&0xffff; - x1=(t-(x2& ~x0)-(x3&x0)- *(p0--))&0xffff; - t=((x0<<15)|(x0>>1))&0xffff; - x0=(t-(x1& ~x3)-(x2&x3)- *(p0--))&0xffff; - - if (--i == 0) - { - if (--n == 0) break; - i=(n == 2)?6:5; - - x3=(x3-p1[x2&0x3f])&0xffff; - x2=(x2-p1[x1&0x3f])&0xffff; - x1=(x1-p1[x0&0x3f])&0xffff; - x0=(x0-p1[x3&0x3f])&0xffff; - } - } - } - - d[0]=(unsigned long)(x0&0xffff)|((unsigned long)(x1&0xffff)<<16L); - d[1]=(unsigned long)(x2&0xffff)|((unsigned long)(x3&0xffff)<<16L); - } diff --git a/crypto/rc2/rc2_locl.h b/crypto/rc2/rc2_locl.h index 05f45b0573..565cd17619 100644 --- a/crypto/rc2/rc2_locl.h +++ b/crypto/rc2/rc2_locl.h @@ -1,5 +1,5 @@ /* crypto/rc2/rc2_locl.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 @@ -144,3 +144,13 @@ *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ *((c)++)=(unsigned char)(((l) )&0xff)) +#define C_RC2(n) \ + t=(x0+(x1& ~x3)+(x2&x3)+ *(p0++))&0xffff; \ + x0=(t<<1)|(t>>15); \ + t=(x1+(x2& ~x0)+(x3&x0)+ *(p0++))&0xffff; \ + x1=(t<<2)|(t>>14); \ + t=(x2+(x3& ~x1)+(x0&x1)+ *(p0++))&0xffff; \ + x2=(t<<3)|(t>>13); \ + t=(x3+(x0& ~x2)+(x1&x2)+ *(p0++))&0xffff; \ + x3=(t<<5)|(t>>11); + diff --git a/crypto/rc2/rc2_skey.c b/crypto/rc2/rc2_skey.c index cfc8a50cd9..0f1f253395 100644 --- a/crypto/rc2/rc2_skey.c +++ b/crypto/rc2/rc2_skey.c @@ -1,5 +1,5 @@ /* crypto/rc2/rc2_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/rc2/rc2cfb64.c b/crypto/rc2/rc2cfb64.c index 44df3dc951..d409fb77e9 100644 --- a/crypto/rc2/rc2cfb64.c +++ b/crypto/rc2/rc2cfb64.c @@ -1,5 +1,5 @@ /* crypto/rc2/rc2cfb64.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 @@ -88,7 +88,7 @@ int encrypt; { c2l(iv,v0); ti[0]=v0; c2l(iv,v1); ti[1]=v1; - RC2_encrypt((unsigned long *)ti,schedule,RC2_ENCRYPT); + RC2_encrypt((unsigned long *)ti,schedule); iv=(unsigned char *)ivec; t=ti[0]; l2c(t,iv); t=ti[1]; l2c(t,iv); @@ -108,7 +108,7 @@ int encrypt; { c2l(iv,v0); ti[0]=v0; c2l(iv,v1); ti[1]=v1; - RC2_encrypt((unsigned long *)ti,schedule,RC2_ENCRYPT); + RC2_encrypt((unsigned long *)ti,schedule); iv=(unsigned char *)ivec; t=ti[0]; l2c(t,iv); t=ti[1]; l2c(t,iv); diff --git a/crypto/rc2/rc2ofb64.c b/crypto/rc2/rc2ofb64.c index 5df004bcec..4f09167447 100644 --- a/crypto/rc2/rc2ofb64.c +++ b/crypto/rc2/rc2ofb64.c @@ -1,5 +1,5 @@ /* crypto/rc2/rc2ofb64.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 @@ -92,7 +92,7 @@ int *num; { if (n == 0) { - RC2_encrypt((unsigned long *)ti,schedule,RC2_ENCRYPT); + RC2_encrypt((unsigned long *)ti,schedule); dp=(char *)d; t=ti[0]; l2c(t,dp); t=ti[1]; l2c(t,dp); diff --git a/crypto/rc2/rc2speed.c b/crypto/rc2/rc2speed.c new file mode 100644 index 0000000000..6cd8ea8f27 --- /dev/null +++ b/crypto/rc2/rc2speed.c @@ -0,0 +1,293 @@ +/* crypto/rc2/rc2speed.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 <stdio.h> +#ifndef MSDOS +#include <unistd.h> +#else +#include <io.h> +extern int exit(); +#endif +#include <signal.h> +#ifndef VMS +#ifndef _IRIX +#include <time.h> +#endif +#ifdef TIMES +#include <sys/types.h> +#include <sys/times.h> +#endif +#else /* VMS */ +#include <types.h> +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 <sys/timeb.h> +#endif + +#ifdef sun +#include <limits.h> +#include <sys/param.h> +#endif + +#include "rc2.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, + }; + RC2_KEY sch; + double a,b,c,d; +#ifndef SIGALRM + long ca,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"); + RC2_set_key(&sch,16,key,128); + count=10; + do { + long i; + unsigned long data[2]; + + count*=2; + Time_F(START); + for (i=count; i; i--) + RC2_encrypt(data,&sch); + d=Time_F(STOP); + } while (d < 3.0); + ca=count/512; + cb=count; + cc=count*8/BUFSIZE+1; + printf("Doing RC2_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 RC2_set_key for 10 seconds\n"); + alarm(10); +#endif + + Time_F(START); + for (count=0,run=1; COND(ca); count+=4) + { + RC2_set_key(&sch,16,key,128); + RC2_set_key(&sch,16,key,128); + RC2_set_key(&sch,16,key,128); + RC2_set_key(&sch,16,key,128); + } + d=Time_F(STOP); + printf("%ld RC2_set_key's in %.2f seconds\n",count,d); + a=((double)COUNT(ca))/d; + +#ifdef SIGALRM + printf("Doing RC2_encrypt's for 10 seconds\n"); + alarm(10); +#else + printf("Doing RC2_encrypt %ld times\n",cb); +#endif + Time_F(START); + for (count=0,run=1; COND(cb); count+=4) + { + unsigned long data[2]; + + RC2_encrypt(data,&sch); + RC2_encrypt(data,&sch); + RC2_encrypt(data,&sch); + RC2_encrypt(data,&sch); + } + d=Time_F(STOP); + printf("%ld RC2_encrypt's in %.2f second\n",count,d); + b=((double)COUNT(cb)*8)/d; + +#ifdef SIGALRM + printf("Doing RC2_cbc_encrypt on %ld byte blocks for 10 seconds\n", + BUFSIZE); + alarm(10); +#else + printf("Doing RC2_cbc_encrypt %ld times on %ld byte blocks\n",cc, + BUFSIZE); +#endif + Time_F(START); + for (count=0,run=1; COND(cc); count++) + RC2_cbc_encrypt(buf,buf,BUFSIZE,&sch, + &(key[0]),RC2_ENCRYPT); + d=Time_F(STOP); + printf("%ld RC2_cbc_encrypt's of %ld byte blocks in %.2f second\n", + count,BUFSIZE,d); + c=((double)COUNT(cc)*BUFSIZE)/d; + + printf("RC2 set_key per sec = %12.2f (%9.3fuS)\n",a,1.0e6/a); + printf("RC2 raw ecb bytes per sec = %12.2f (%9.3fuS)\n",b,8.0e6/b); + printf("RC2 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/rc2/rc2test.c b/crypto/rc2/rc2test.c index 00e21ddd3a..9d0f8016ec 100644 --- a/crypto/rc2/rc2test.c +++ b/crypto/rc2/rc2test.c @@ -1,5 +1,5 @@ /* crypto/rc2/rc2test.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 |