diff options
Diffstat (limited to 'src/lib/libcrypto/idea')
| -rw-r--r-- | src/lib/libcrypto/idea/Makefile (renamed from src/lib/libcrypto/idea/Makefile.ssl) | 22 | ||||
| -rw-r--r-- | src/lib/libcrypto/idea/i_cbc.c | 168 | ||||
| -rw-r--r-- | src/lib/libcrypto/idea/i_cfb64.c | 122 | ||||
| -rw-r--r-- | src/lib/libcrypto/idea/i_ecb.c | 85 | ||||
| -rw-r--r-- | src/lib/libcrypto/idea/i_ofb64.c | 111 | ||||
| -rw-r--r-- | src/lib/libcrypto/idea/i_skey.c | 164 | ||||
| -rw-r--r-- | src/lib/libcrypto/idea/idea.h | 103 | ||||
| -rw-r--r-- | src/lib/libcrypto/idea/idea_lcl.h | 215 | ||||
| -rw-r--r-- | src/lib/libcrypto/idea/ideatest.c | 235 | ||||
| -rw-r--r-- | src/lib/libcrypto/idea/version | 12 |
10 files changed, 1225 insertions, 12 deletions
diff --git a/src/lib/libcrypto/idea/Makefile.ssl b/src/lib/libcrypto/idea/Makefile index fa016ea399..8af0acdad9 100644 --- a/src/lib/libcrypto/idea/Makefile.ssl +++ b/src/lib/libcrypto/idea/Makefile | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | # | 1 | # |
| 2 | # SSLeay/crypto/idea/Makefile | 2 | # OpenSSL/crypto/idea/Makefile |
| 3 | # | 3 | # |
| 4 | 4 | ||
| 5 | DIR= idea | 5 | DIR= idea |
| @@ -7,13 +7,7 @@ TOP= ../.. | |||
| 7 | CC= cc | 7 | CC= cc |
| 8 | INCLUDES= | 8 | INCLUDES= |
| 9 | CFLAG=-g | 9 | CFLAG=-g |
| 10 | INSTALL_PREFIX= | 10 | MAKEFILE= Makefile |
| 11 | OPENSSLDIR= /usr/local/ssl | ||
| 12 | INSTALLTOP=/usr/local/ssl | ||
| 13 | MAKE= make -f Makefile.ssl | ||
| 14 | MAKEDEPPROG= makedepend | ||
| 15 | MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG) | ||
| 16 | MAKEFILE= Makefile.ssl | ||
| 17 | AR= ar r | 11 | AR= ar r |
| 18 | 12 | ||
| 19 | CFLAGS= $(INCLUDES) $(CFLAG) | 13 | CFLAGS= $(INCLUDES) $(CFLAG) |
| @@ -44,16 +38,16 @@ lib: $(LIBOBJ) | |||
| 44 | @touch lib | 38 | @touch lib |
| 45 | 39 | ||
| 46 | files: | 40 | files: |
| 47 | $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | 41 | $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO |
| 48 | 42 | ||
| 49 | links: | 43 | links: |
| 50 | @sh $(TOP)/util/point.sh Makefile.ssl Makefile | ||
| 51 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | 44 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) |
| 52 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | 45 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) |
| 53 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | 46 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) |
| 54 | 47 | ||
| 55 | install: | 48 | install: |
| 56 | @for i in $(EXHEADER) ; \ | 49 | @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile... |
| 50 | @headerlist="$(EXHEADER)"; for i in $$headerlist ; \ | ||
| 57 | do \ | 51 | do \ |
| 58 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | 52 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ |
| 59 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | 53 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ |
| @@ -68,6 +62,7 @@ lint: | |||
| 68 | lint -DLINT $(INCLUDES) $(SRC)>fluff | 62 | lint -DLINT $(INCLUDES) $(SRC)>fluff |
| 69 | 63 | ||
| 70 | depend: | 64 | depend: |
| 65 | @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile... | ||
| 71 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) | 66 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) |
| 72 | 67 | ||
| 73 | dclean: | 68 | dclean: |
| @@ -87,5 +82,8 @@ i_ecb.o: ../../include/openssl/idea.h ../../include/openssl/opensslconf.h | |||
| 87 | i_ecb.o: ../../include/openssl/opensslv.h i_ecb.c idea_lcl.h | 82 | i_ecb.o: ../../include/openssl/opensslv.h i_ecb.c idea_lcl.h |
| 88 | i_ofb64.o: ../../include/openssl/idea.h ../../include/openssl/opensslconf.h | 83 | i_ofb64.o: ../../include/openssl/idea.h ../../include/openssl/opensslconf.h |
| 89 | i_ofb64.o: i_ofb64.c idea_lcl.h | 84 | i_ofb64.o: i_ofb64.c idea_lcl.h |
| 85 | i_skey.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 90 | i_skey.o: ../../include/openssl/idea.h ../../include/openssl/opensslconf.h | 86 | i_skey.o: ../../include/openssl/idea.h ../../include/openssl/opensslconf.h |
| 91 | i_skey.o: i_skey.c idea_lcl.h | 87 | i_skey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h |
| 88 | i_skey.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 89 | i_skey.o: ../../include/openssl/symhacks.h i_skey.c idea_lcl.h | ||
diff --git a/src/lib/libcrypto/idea/i_cbc.c b/src/lib/libcrypto/idea/i_cbc.c new file mode 100644 index 0000000000..ecb9cb8b83 --- /dev/null +++ b/src/lib/libcrypto/idea/i_cbc.c | |||
| @@ -0,0 +1,168 @@ | |||
| 1 | /* crypto/idea/i_cbc.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <openssl/idea.h> | ||
| 60 | #include "idea_lcl.h" | ||
| 61 | |||
| 62 | void idea_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, | ||
| 63 | IDEA_KEY_SCHEDULE *ks, unsigned char *iv, int encrypt) | ||
| 64 | { | ||
| 65 | register unsigned long tin0,tin1; | ||
| 66 | register unsigned long tout0,tout1,xor0,xor1; | ||
| 67 | register long l=length; | ||
| 68 | unsigned long tin[2]; | ||
| 69 | |||
| 70 | if (encrypt) | ||
| 71 | { | ||
| 72 | n2l(iv,tout0); | ||
| 73 | n2l(iv,tout1); | ||
| 74 | iv-=8; | ||
| 75 | for (l-=8; l>=0; l-=8) | ||
| 76 | { | ||
| 77 | n2l(in,tin0); | ||
| 78 | n2l(in,tin1); | ||
| 79 | tin0^=tout0; | ||
| 80 | tin1^=tout1; | ||
| 81 | tin[0]=tin0; | ||
| 82 | tin[1]=tin1; | ||
| 83 | idea_encrypt(tin,ks); | ||
| 84 | tout0=tin[0]; l2n(tout0,out); | ||
| 85 | tout1=tin[1]; l2n(tout1,out); | ||
| 86 | } | ||
| 87 | if (l != -8) | ||
| 88 | { | ||
| 89 | n2ln(in,tin0,tin1,l+8); | ||
| 90 | tin0^=tout0; | ||
| 91 | tin1^=tout1; | ||
| 92 | tin[0]=tin0; | ||
| 93 | tin[1]=tin1; | ||
| 94 | idea_encrypt(tin,ks); | ||
| 95 | tout0=tin[0]; l2n(tout0,out); | ||
| 96 | tout1=tin[1]; l2n(tout1,out); | ||
| 97 | } | ||
| 98 | l2n(tout0,iv); | ||
| 99 | l2n(tout1,iv); | ||
| 100 | } | ||
| 101 | else | ||
| 102 | { | ||
| 103 | n2l(iv,xor0); | ||
| 104 | n2l(iv,xor1); | ||
| 105 | iv-=8; | ||
| 106 | for (l-=8; l>=0; l-=8) | ||
| 107 | { | ||
| 108 | n2l(in,tin0); tin[0]=tin0; | ||
| 109 | n2l(in,tin1); tin[1]=tin1; | ||
| 110 | idea_encrypt(tin,ks); | ||
| 111 | tout0=tin[0]^xor0; | ||
| 112 | tout1=tin[1]^xor1; | ||
| 113 | l2n(tout0,out); | ||
| 114 | l2n(tout1,out); | ||
| 115 | xor0=tin0; | ||
| 116 | xor1=tin1; | ||
| 117 | } | ||
| 118 | if (l != -8) | ||
| 119 | { | ||
| 120 | n2l(in,tin0); tin[0]=tin0; | ||
| 121 | n2l(in,tin1); tin[1]=tin1; | ||
| 122 | idea_encrypt(tin,ks); | ||
| 123 | tout0=tin[0]^xor0; | ||
| 124 | tout1=tin[1]^xor1; | ||
| 125 | l2nn(tout0,tout1,out,l+8); | ||
| 126 | xor0=tin0; | ||
| 127 | xor1=tin1; | ||
| 128 | } | ||
| 129 | l2n(xor0,iv); | ||
| 130 | l2n(xor1,iv); | ||
| 131 | } | ||
| 132 | tin0=tin1=tout0=tout1=xor0=xor1=0; | ||
| 133 | tin[0]=tin[1]=0; | ||
| 134 | } | ||
| 135 | |||
| 136 | void idea_encrypt(unsigned long *d, IDEA_KEY_SCHEDULE *key) | ||
| 137 | { | ||
| 138 | register IDEA_INT *p; | ||
| 139 | register unsigned long x1,x2,x3,x4,t0,t1,ul; | ||
| 140 | |||
| 141 | x2=d[0]; | ||
| 142 | x1=(x2>>16); | ||
| 143 | x4=d[1]; | ||
| 144 | x3=(x4>>16); | ||
| 145 | |||
| 146 | p= &(key->data[0][0]); | ||
| 147 | |||
| 148 | E_IDEA(0); | ||
| 149 | E_IDEA(1); | ||
| 150 | E_IDEA(2); | ||
| 151 | E_IDEA(3); | ||
| 152 | E_IDEA(4); | ||
| 153 | E_IDEA(5); | ||
| 154 | E_IDEA(6); | ||
| 155 | E_IDEA(7); | ||
| 156 | |||
| 157 | x1&=0xffff; | ||
| 158 | idea_mul(x1,x1,*p,ul); p++; | ||
| 159 | |||
| 160 | t0= x3+ *(p++); | ||
| 161 | t1= x2+ *(p++); | ||
| 162 | |||
| 163 | x4&=0xffff; | ||
| 164 | idea_mul(x4,x4,*p,ul); | ||
| 165 | |||
| 166 | d[0]=(t0&0xffff)|((x1&0xffff)<<16); | ||
| 167 | d[1]=(x4&0xffff)|((t1&0xffff)<<16); | ||
| 168 | } | ||
diff --git a/src/lib/libcrypto/idea/i_cfb64.c b/src/lib/libcrypto/idea/i_cfb64.c new file mode 100644 index 0000000000..66d49d520e --- /dev/null +++ b/src/lib/libcrypto/idea/i_cfb64.c | |||
| @@ -0,0 +1,122 @@ | |||
| 1 | /* crypto/idea/i_cfb64.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <openssl/idea.h> | ||
| 60 | #include "idea_lcl.h" | ||
| 61 | |||
| 62 | /* The input and output encrypted as though 64bit cfb mode is being | ||
| 63 | * used. The extra state information to record how much of the | ||
| 64 | * 64bit block we have used is contained in *num; | ||
| 65 | */ | ||
| 66 | |||
| 67 | void idea_cfb64_encrypt(const unsigned char *in, unsigned char *out, | ||
| 68 | long length, IDEA_KEY_SCHEDULE *schedule, | ||
| 69 | unsigned char *ivec, int *num, int encrypt) | ||
| 70 | { | ||
| 71 | register unsigned long v0,v1,t; | ||
| 72 | register int n= *num; | ||
| 73 | register long l=length; | ||
| 74 | unsigned long ti[2]; | ||
| 75 | unsigned char *iv,c,cc; | ||
| 76 | |||
| 77 | iv=(unsigned char *)ivec; | ||
| 78 | if (encrypt) | ||
| 79 | { | ||
| 80 | while (l--) | ||
| 81 | { | ||
| 82 | if (n == 0) | ||
| 83 | { | ||
| 84 | n2l(iv,v0); ti[0]=v0; | ||
| 85 | n2l(iv,v1); ti[1]=v1; | ||
| 86 | idea_encrypt((unsigned long *)ti,schedule); | ||
| 87 | iv=(unsigned char *)ivec; | ||
| 88 | t=ti[0]; l2n(t,iv); | ||
| 89 | t=ti[1]; l2n(t,iv); | ||
| 90 | iv=(unsigned char *)ivec; | ||
| 91 | } | ||
| 92 | c= *(in++)^iv[n]; | ||
| 93 | *(out++)=c; | ||
| 94 | iv[n]=c; | ||
| 95 | n=(n+1)&0x07; | ||
| 96 | } | ||
| 97 | } | ||
| 98 | else | ||
| 99 | { | ||
| 100 | while (l--) | ||
| 101 | { | ||
| 102 | if (n == 0) | ||
| 103 | { | ||
| 104 | n2l(iv,v0); ti[0]=v0; | ||
| 105 | n2l(iv,v1); ti[1]=v1; | ||
| 106 | idea_encrypt((unsigned long *)ti,schedule); | ||
| 107 | iv=(unsigned char *)ivec; | ||
| 108 | t=ti[0]; l2n(t,iv); | ||
| 109 | t=ti[1]; l2n(t,iv); | ||
| 110 | iv=(unsigned char *)ivec; | ||
| 111 | } | ||
| 112 | cc= *(in++); | ||
| 113 | c=iv[n]; | ||
| 114 | iv[n]=cc; | ||
| 115 | *(out++)=c^cc; | ||
| 116 | n=(n+1)&0x07; | ||
| 117 | } | ||
| 118 | } | ||
| 119 | v0=v1=ti[0]=ti[1]=t=c=cc=0; | ||
| 120 | *num=n; | ||
| 121 | } | ||
| 122 | |||
diff --git a/src/lib/libcrypto/idea/i_ecb.c b/src/lib/libcrypto/idea/i_ecb.c new file mode 100644 index 0000000000..fef38230a7 --- /dev/null +++ b/src/lib/libcrypto/idea/i_ecb.c | |||
| @@ -0,0 +1,85 @@ | |||
| 1 | /* crypto/idea/i_ecb.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <openssl/idea.h> | ||
| 60 | #include "idea_lcl.h" | ||
| 61 | #include <openssl/opensslv.h> | ||
| 62 | |||
| 63 | const char IDEA_version[]="IDEA" OPENSSL_VERSION_PTEXT; | ||
| 64 | |||
| 65 | const char *idea_options(void) | ||
| 66 | { | ||
| 67 | if (sizeof(short) != sizeof(IDEA_INT)) | ||
| 68 | return("idea(int)"); | ||
| 69 | else | ||
| 70 | return("idea(short)"); | ||
| 71 | } | ||
| 72 | |||
| 73 | void idea_ecb_encrypt(const unsigned char *in, unsigned char *out, | ||
| 74 | IDEA_KEY_SCHEDULE *ks) | ||
| 75 | { | ||
| 76 | unsigned long l0,l1,d[2]; | ||
| 77 | |||
| 78 | n2l(in,l0); d[0]=l0; | ||
| 79 | n2l(in,l1); d[1]=l1; | ||
| 80 | idea_encrypt(d,ks); | ||
| 81 | l0=d[0]; l2n(l0,out); | ||
| 82 | l1=d[1]; l2n(l1,out); | ||
| 83 | l0=l1=d[0]=d[1]=0; | ||
| 84 | } | ||
| 85 | |||
diff --git a/src/lib/libcrypto/idea/i_ofb64.c b/src/lib/libcrypto/idea/i_ofb64.c new file mode 100644 index 0000000000..e749e88e34 --- /dev/null +++ b/src/lib/libcrypto/idea/i_ofb64.c | |||
| @@ -0,0 +1,111 @@ | |||
| 1 | /* crypto/idea/i_ofb64.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <openssl/idea.h> | ||
| 60 | #include "idea_lcl.h" | ||
| 61 | |||
| 62 | /* The input and output encrypted as though 64bit ofb mode is being | ||
| 63 | * used. The extra state information to record how much of the | ||
| 64 | * 64bit block we have used is contained in *num; | ||
| 65 | */ | ||
| 66 | void idea_ofb64_encrypt(const unsigned char *in, unsigned char *out, | ||
| 67 | long length, IDEA_KEY_SCHEDULE *schedule, | ||
| 68 | unsigned char *ivec, int *num) | ||
| 69 | { | ||
| 70 | register unsigned long v0,v1,t; | ||
| 71 | register int n= *num; | ||
| 72 | register long l=length; | ||
| 73 | unsigned char d[8]; | ||
| 74 | register char *dp; | ||
| 75 | unsigned long ti[2]; | ||
| 76 | unsigned char *iv; | ||
| 77 | int save=0; | ||
| 78 | |||
| 79 | iv=(unsigned char *)ivec; | ||
| 80 | n2l(iv,v0); | ||
| 81 | n2l(iv,v1); | ||
| 82 | ti[0]=v0; | ||
| 83 | ti[1]=v1; | ||
| 84 | dp=(char *)d; | ||
| 85 | l2n(v0,dp); | ||
| 86 | l2n(v1,dp); | ||
| 87 | while (l--) | ||
| 88 | { | ||
| 89 | if (n == 0) | ||
| 90 | { | ||
| 91 | idea_encrypt((unsigned long *)ti,schedule); | ||
| 92 | dp=(char *)d; | ||
| 93 | t=ti[0]; l2n(t,dp); | ||
| 94 | t=ti[1]; l2n(t,dp); | ||
| 95 | save++; | ||
| 96 | } | ||
| 97 | *(out++)= *(in++)^d[n]; | ||
| 98 | n=(n+1)&0x07; | ||
| 99 | } | ||
| 100 | if (save) | ||
| 101 | { | ||
| 102 | v0=ti[0]; | ||
| 103 | v1=ti[1]; | ||
| 104 | iv=(unsigned char *)ivec; | ||
| 105 | l2n(v0,iv); | ||
| 106 | l2n(v1,iv); | ||
| 107 | } | ||
| 108 | t=v0=v1=ti[0]=ti[1]=0; | ||
| 109 | *num=n; | ||
| 110 | } | ||
| 111 | |||
diff --git a/src/lib/libcrypto/idea/i_skey.c b/src/lib/libcrypto/idea/i_skey.c new file mode 100644 index 0000000000..afb830964d --- /dev/null +++ b/src/lib/libcrypto/idea/i_skey.c | |||
| @@ -0,0 +1,164 @@ | |||
| 1 | /* crypto/idea/i_skey.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <openssl/crypto.h> | ||
| 60 | #include <openssl/idea.h> | ||
| 61 | #include "idea_lcl.h" | ||
| 62 | |||
| 63 | static IDEA_INT inverse(unsigned int xin); | ||
| 64 | void idea_set_encrypt_key(const unsigned char *key, IDEA_KEY_SCHEDULE *ks) | ||
| 65 | #ifdef OPENSSL_FIPS | ||
| 66 | { | ||
| 67 | fips_cipher_abort(IDEA); | ||
| 68 | private_idea_set_encrypt_key(key, ks); | ||
| 69 | } | ||
| 70 | void private_idea_set_encrypt_key(const unsigned char *key, IDEA_KEY_SCHEDULE *ks) | ||
| 71 | #endif | ||
| 72 | { | ||
| 73 | int i; | ||
| 74 | register IDEA_INT *kt,*kf,r0,r1,r2; | ||
| 75 | |||
| 76 | kt= &(ks->data[0][0]); | ||
| 77 | n2s(key,kt[0]); n2s(key,kt[1]); n2s(key,kt[2]); n2s(key,kt[3]); | ||
| 78 | n2s(key,kt[4]); n2s(key,kt[5]); n2s(key,kt[6]); n2s(key,kt[7]); | ||
| 79 | |||
| 80 | kf=kt; | ||
| 81 | kt+=8; | ||
| 82 | for (i=0; i<6; i++) | ||
| 83 | { | ||
| 84 | r2= kf[1]; | ||
| 85 | r1= kf[2]; | ||
| 86 | *(kt++)= ((r2<<9) | (r1>>7))&0xffff; | ||
| 87 | r0= kf[3]; | ||
| 88 | *(kt++)= ((r1<<9) | (r0>>7))&0xffff; | ||
| 89 | r1= kf[4]; | ||
| 90 | *(kt++)= ((r0<<9) | (r1>>7))&0xffff; | ||
| 91 | r0= kf[5]; | ||
| 92 | *(kt++)= ((r1<<9) | (r0>>7))&0xffff; | ||
| 93 | r1= kf[6]; | ||
| 94 | *(kt++)= ((r0<<9) | (r1>>7))&0xffff; | ||
| 95 | r0= kf[7]; | ||
| 96 | *(kt++)= ((r1<<9) | (r0>>7))&0xffff; | ||
| 97 | r1= kf[0]; | ||
| 98 | if (i >= 5) break; | ||
| 99 | *(kt++)= ((r0<<9) | (r1>>7))&0xffff; | ||
| 100 | *(kt++)= ((r1<<9) | (r2>>7))&0xffff; | ||
| 101 | kf+=8; | ||
| 102 | } | ||
| 103 | } | ||
| 104 | |||
| 105 | void idea_set_decrypt_key(IDEA_KEY_SCHEDULE *ek, IDEA_KEY_SCHEDULE *dk) | ||
| 106 | { | ||
| 107 | int r; | ||
| 108 | register IDEA_INT *fp,*tp,t; | ||
| 109 | |||
| 110 | tp= &(dk->data[0][0]); | ||
| 111 | fp= &(ek->data[8][0]); | ||
| 112 | for (r=0; r<9; r++) | ||
| 113 | { | ||
| 114 | *(tp++)=inverse(fp[0]); | ||
| 115 | *(tp++)=((int)(0x10000L-fp[2])&0xffff); | ||
| 116 | *(tp++)=((int)(0x10000L-fp[1])&0xffff); | ||
| 117 | *(tp++)=inverse(fp[3]); | ||
| 118 | if (r == 8) break; | ||
| 119 | fp-=6; | ||
| 120 | *(tp++)=fp[4]; | ||
| 121 | *(tp++)=fp[5]; | ||
| 122 | } | ||
| 123 | |||
| 124 | tp= &(dk->data[0][0]); | ||
| 125 | t=tp[1]; | ||
| 126 | tp[1]=tp[2]; | ||
| 127 | tp[2]=t; | ||
| 128 | |||
| 129 | t=tp[49]; | ||
| 130 | tp[49]=tp[50]; | ||
| 131 | tp[50]=t; | ||
| 132 | } | ||
| 133 | |||
| 134 | /* taken directly from the 'paper' I'll have a look at it later */ | ||
| 135 | static IDEA_INT inverse(unsigned int xin) | ||
| 136 | { | ||
| 137 | long n1,n2,q,r,b1,b2,t; | ||
| 138 | |||
| 139 | if (xin == 0) | ||
| 140 | b2=0; | ||
| 141 | else | ||
| 142 | { | ||
| 143 | n1=0x10001; | ||
| 144 | n2=xin; | ||
| 145 | b2=1; | ||
| 146 | b1=0; | ||
| 147 | |||
| 148 | do { | ||
| 149 | r=(n1%n2); | ||
| 150 | q=(n1-r)/n2; | ||
| 151 | if (r == 0) | ||
| 152 | { if (b2 < 0) b2=0x10001+b2; } | ||
| 153 | else | ||
| 154 | { | ||
| 155 | n1=n2; | ||
| 156 | n2=r; | ||
| 157 | t=b2; | ||
| 158 | b2=b1-q*b2; | ||
| 159 | b1=t; | ||
| 160 | } | ||
| 161 | } while (r != 0); | ||
| 162 | } | ||
| 163 | return((IDEA_INT)b2); | ||
| 164 | } | ||
diff --git a/src/lib/libcrypto/idea/idea.h b/src/lib/libcrypto/idea/idea.h new file mode 100644 index 0000000000..e9a1e7f1a5 --- /dev/null +++ b/src/lib/libcrypto/idea/idea.h | |||
| @@ -0,0 +1,103 @@ | |||
| 1 | /* crypto/idea/idea.h */ | ||
| 2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #ifndef HEADER_IDEA_H | ||
| 60 | #define HEADER_IDEA_H | ||
| 61 | |||
| 62 | #include <openssl/opensslconf.h> /* IDEA_INT, OPENSSL_NO_IDEA */ | ||
| 63 | |||
| 64 | #ifdef OPENSSL_NO_IDEA | ||
| 65 | #error IDEA is disabled. | ||
| 66 | #endif | ||
| 67 | |||
| 68 | #define IDEA_ENCRYPT 1 | ||
| 69 | #define IDEA_DECRYPT 0 | ||
| 70 | |||
| 71 | #define IDEA_BLOCK 8 | ||
| 72 | #define IDEA_KEY_LENGTH 16 | ||
| 73 | |||
| 74 | #ifdef __cplusplus | ||
| 75 | extern "C" { | ||
| 76 | #endif | ||
| 77 | |||
| 78 | typedef struct idea_key_st | ||
| 79 | { | ||
| 80 | IDEA_INT data[9][6]; | ||
| 81 | } IDEA_KEY_SCHEDULE; | ||
| 82 | |||
| 83 | const char *idea_options(void); | ||
| 84 | void idea_ecb_encrypt(const unsigned char *in, unsigned char *out, | ||
| 85 | IDEA_KEY_SCHEDULE *ks); | ||
| 86 | #ifdef OPENSSL_FIPS | ||
| 87 | void private_idea_set_encrypt_key(const unsigned char *key, IDEA_KEY_SCHEDULE *ks); | ||
| 88 | #endif | ||
| 89 | void idea_set_encrypt_key(const unsigned char *key, IDEA_KEY_SCHEDULE *ks); | ||
| 90 | void idea_set_decrypt_key(IDEA_KEY_SCHEDULE *ek, IDEA_KEY_SCHEDULE *dk); | ||
| 91 | void idea_cbc_encrypt(const unsigned char *in, unsigned char *out, | ||
| 92 | long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv,int enc); | ||
| 93 | void idea_cfb64_encrypt(const unsigned char *in, unsigned char *out, | ||
| 94 | long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, | ||
| 95 | int *num,int enc); | ||
| 96 | void idea_ofb64_encrypt(const unsigned char *in, unsigned char *out, | ||
| 97 | long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, int *num); | ||
| 98 | void idea_encrypt(unsigned long *in, IDEA_KEY_SCHEDULE *ks); | ||
| 99 | #ifdef __cplusplus | ||
| 100 | } | ||
| 101 | #endif | ||
| 102 | |||
| 103 | #endif | ||
diff --git a/src/lib/libcrypto/idea/idea_lcl.h b/src/lib/libcrypto/idea/idea_lcl.h new file mode 100644 index 0000000000..f3dbfa67e9 --- /dev/null +++ b/src/lib/libcrypto/idea/idea_lcl.h | |||
| @@ -0,0 +1,215 @@ | |||
| 1 | /* crypto/idea/idea_lcl.h */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | /* The new form of this macro (check if the a*b == 0) was suggested by | ||
| 60 | * Colin Plumb <colin@nyx10.cs.du.edu> */ | ||
| 61 | /* Removal of the inner if from from Wei Dai 24/4/96 */ | ||
| 62 | #define idea_mul(r,a,b,ul) \ | ||
| 63 | ul=(unsigned long)a*b; \ | ||
| 64 | if (ul != 0) \ | ||
| 65 | { \ | ||
| 66 | r=(ul&0xffff)-(ul>>16); \ | ||
| 67 | r-=((r)>>16); \ | ||
| 68 | } \ | ||
| 69 | else \ | ||
| 70 | r=(-(int)a-b+1); /* assuming a or b is 0 and in range */ | ||
| 71 | |||
| 72 | #ifdef undef | ||
| 73 | #define idea_mul(r,a,b,ul,sl) \ | ||
| 74 | if (a == 0) r=(0x10001-b)&0xffff; \ | ||
| 75 | else if (b == 0) r=(0x10001-a)&0xffff; \ | ||
| 76 | else { \ | ||
| 77 | ul=(unsigned long)a*b; \ | ||
| 78 | sl=(ul&0xffff)-(ul>>16); \ | ||
| 79 | if (sl <= 0) sl+=0x10001; \ | ||
| 80 | r=sl; \ | ||
| 81 | } | ||
| 82 | #endif | ||
| 83 | |||
| 84 | /* 7/12/95 - Many thanks to Rhys Weatherley <rweather@us.oracle.com> | ||
| 85 | * for pointing out that I was assuming little endian | ||
| 86 | * byte order for all quantities what idea | ||
| 87 | * actually used bigendian. No where in the spec does it mention | ||
| 88 | * this, it is all in terms of 16 bit numbers and even the example | ||
| 89 | * does not use byte streams for the input example :-(. | ||
| 90 | * If you byte swap each pair of input, keys and iv, the functions | ||
| 91 | * would produce the output as the old version :-(. | ||
| 92 | */ | ||
| 93 | |||
| 94 | /* NOTE - c is not incremented as per n2l */ | ||
| 95 | #define n2ln(c,l1,l2,n) { \ | ||
| 96 | c+=n; \ | ||
| 97 | l1=l2=0; \ | ||
| 98 | switch (n) { \ | ||
| 99 | case 8: l2 =((unsigned long)(*(--(c)))) ; \ | ||
| 100 | case 7: l2|=((unsigned long)(*(--(c))))<< 8; \ | ||
| 101 | case 6: l2|=((unsigned long)(*(--(c))))<<16; \ | ||
| 102 | case 5: l2|=((unsigned long)(*(--(c))))<<24; \ | ||
| 103 | case 4: l1 =((unsigned long)(*(--(c)))) ; \ | ||
| 104 | case 3: l1|=((unsigned long)(*(--(c))))<< 8; \ | ||
| 105 | case 2: l1|=((unsigned long)(*(--(c))))<<16; \ | ||
| 106 | case 1: l1|=((unsigned long)(*(--(c))))<<24; \ | ||
| 107 | } \ | ||
| 108 | } | ||
| 109 | |||
| 110 | /* NOTE - c is not incremented as per l2n */ | ||
| 111 | #define l2nn(l1,l2,c,n) { \ | ||
| 112 | c+=n; \ | ||
| 113 | switch (n) { \ | ||
| 114 | case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \ | ||
| 115 | case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \ | ||
| 116 | case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \ | ||
| 117 | case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \ | ||
| 118 | case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \ | ||
| 119 | case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \ | ||
| 120 | case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \ | ||
| 121 | case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \ | ||
| 122 | } \ | ||
| 123 | } | ||
| 124 | |||
| 125 | #undef n2l | ||
| 126 | #define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \ | ||
| 127 | l|=((unsigned long)(*((c)++)))<<16L, \ | ||
| 128 | l|=((unsigned long)(*((c)++)))<< 8L, \ | ||
| 129 | l|=((unsigned long)(*((c)++)))) | ||
| 130 | |||
| 131 | #undef l2n | ||
| 132 | #define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \ | ||
| 133 | *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ | ||
| 134 | *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ | ||
| 135 | *((c)++)=(unsigned char)(((l) )&0xff)) | ||
| 136 | |||
| 137 | #undef s2n | ||
| 138 | #define s2n(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ | ||
| 139 | *((c)++)=(unsigned char)(((l)>> 8L)&0xff)) | ||
| 140 | |||
| 141 | #undef n2s | ||
| 142 | #define n2s(c,l) (l =((IDEA_INT)(*((c)++)))<< 8L, \ | ||
| 143 | l|=((IDEA_INT)(*((c)++))) ) | ||
| 144 | |||
| 145 | #ifdef undef | ||
| 146 | /* NOTE - c is not incremented as per c2l */ | ||
| 147 | #define c2ln(c,l1,l2,n) { \ | ||
| 148 | c+=n; \ | ||
| 149 | l1=l2=0; \ | ||
| 150 | switch (n) { \ | ||
| 151 | case 8: l2 =((unsigned long)(*(--(c))))<<24; \ | ||
| 152 | case 7: l2|=((unsigned long)(*(--(c))))<<16; \ | ||
| 153 | case 6: l2|=((unsigned long)(*(--(c))))<< 8; \ | ||
| 154 | case 5: l2|=((unsigned long)(*(--(c)))); \ | ||
| 155 | case 4: l1 =((unsigned long)(*(--(c))))<<24; \ | ||
| 156 | case 3: l1|=((unsigned long)(*(--(c))))<<16; \ | ||
| 157 | case 2: l1|=((unsigned long)(*(--(c))))<< 8; \ | ||
| 158 | case 1: l1|=((unsigned long)(*(--(c)))); \ | ||
| 159 | } \ | ||
| 160 | } | ||
| 161 | |||
| 162 | /* NOTE - c is not incremented as per l2c */ | ||
| 163 | #define l2cn(l1,l2,c,n) { \ | ||
| 164 | c+=n; \ | ||
| 165 | switch (n) { \ | ||
| 166 | case 8: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \ | ||
| 167 | case 7: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \ | ||
| 168 | case 6: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \ | ||
| 169 | case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \ | ||
| 170 | case 4: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \ | ||
| 171 | case 3: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \ | ||
| 172 | case 2: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \ | ||
| 173 | case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \ | ||
| 174 | } \ | ||
| 175 | } | ||
| 176 | |||
| 177 | #undef c2s | ||
| 178 | #define c2s(c,l) (l =((unsigned long)(*((c)++))) , \ | ||
| 179 | l|=((unsigned long)(*((c)++)))<< 8L) | ||
| 180 | |||
| 181 | #undef s2c | ||
| 182 | #define s2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ | ||
| 183 | *((c)++)=(unsigned char)(((l)>> 8L)&0xff)) | ||
| 184 | |||
| 185 | #undef c2l | ||
| 186 | #define c2l(c,l) (l =((unsigned long)(*((c)++))) , \ | ||
| 187 | l|=((unsigned long)(*((c)++)))<< 8L, \ | ||
| 188 | l|=((unsigned long)(*((c)++)))<<16L, \ | ||
| 189 | l|=((unsigned long)(*((c)++)))<<24L) | ||
| 190 | |||
| 191 | #undef l2c | ||
| 192 | #define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ | ||
| 193 | *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ | ||
| 194 | *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ | ||
| 195 | *((c)++)=(unsigned char)(((l)>>24L)&0xff)) | ||
| 196 | #endif | ||
| 197 | |||
| 198 | #define E_IDEA(num) \ | ||
| 199 | x1&=0xffff; \ | ||
| 200 | idea_mul(x1,x1,*p,ul); p++; \ | ||
| 201 | x2+= *(p++); \ | ||
| 202 | x3+= *(p++); \ | ||
| 203 | x4&=0xffff; \ | ||
| 204 | idea_mul(x4,x4,*p,ul); p++; \ | ||
| 205 | t0=(x1^x3)&0xffff; \ | ||
| 206 | idea_mul(t0,t0,*p,ul); p++; \ | ||
| 207 | t1=(t0+(x2^x4))&0xffff; \ | ||
| 208 | idea_mul(t1,t1,*p,ul); p++; \ | ||
| 209 | t0+=t1; \ | ||
| 210 | x1^=t1; \ | ||
| 211 | x4^=t0; \ | ||
| 212 | ul=x2^t0; /* do the swap to x3 */ \ | ||
| 213 | x2=x3^t1; \ | ||
| 214 | x3=ul; | ||
| 215 | |||
diff --git a/src/lib/libcrypto/idea/ideatest.c b/src/lib/libcrypto/idea/ideatest.c new file mode 100644 index 0000000000..e6ffc7025e --- /dev/null +++ b/src/lib/libcrypto/idea/ideatest.c | |||
| @@ -0,0 +1,235 @@ | |||
| 1 | /* crypto/idea/ideatest.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <string.h> | ||
| 61 | #include <stdlib.h> | ||
| 62 | |||
| 63 | #include "../e_os.h" | ||
| 64 | |||
| 65 | #ifdef OPENSSL_NO_IDEA | ||
| 66 | int main(int argc, char *argv[]) | ||
| 67 | { | ||
| 68 | printf("No IDEA support\n"); | ||
| 69 | return(0); | ||
| 70 | } | ||
| 71 | #else | ||
| 72 | #include <openssl/idea.h> | ||
| 73 | |||
| 74 | unsigned char k[16]={ | ||
| 75 | 0x00,0x01,0x00,0x02,0x00,0x03,0x00,0x04, | ||
| 76 | 0x00,0x05,0x00,0x06,0x00,0x07,0x00,0x08}; | ||
| 77 | |||
| 78 | unsigned char in[8]={0x00,0x00,0x00,0x01,0x00,0x02,0x00,0x03}; | ||
| 79 | unsigned char c[8]={0x11,0xFB,0xED,0x2B,0x01,0x98,0x6D,0xE5}; | ||
| 80 | unsigned char out[80]; | ||
| 81 | |||
| 82 | char *text="Hello to all people out there"; | ||
| 83 | |||
| 84 | static unsigned char cfb_key[16]={ | ||
| 85 | 0xe1,0xf0,0xc3,0xd2,0xa5,0xb4,0x87,0x96, | ||
| 86 | 0x69,0x78,0x4b,0x5a,0x2d,0x3c,0x0f,0x1e, | ||
| 87 | }; | ||
| 88 | static unsigned char cfb_iv[80]={0x34,0x12,0x78,0x56,0xab,0x90,0xef,0xcd}; | ||
| 89 | static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8]; | ||
| 90 | #define CFB_TEST_SIZE 24 | ||
| 91 | static unsigned char plain[CFB_TEST_SIZE]= | ||
| 92 | { | ||
| 93 | 0x4e,0x6f,0x77,0x20,0x69,0x73, | ||
| 94 | 0x20,0x74,0x68,0x65,0x20,0x74, | ||
| 95 | 0x69,0x6d,0x65,0x20,0x66,0x6f, | ||
| 96 | 0x72,0x20,0x61,0x6c,0x6c,0x20 | ||
| 97 | }; | ||
| 98 | static unsigned char cfb_cipher64[CFB_TEST_SIZE]={ | ||
| 99 | 0x59,0xD8,0xE2,0x65,0x00,0x58,0x6C,0x3F, | ||
| 100 | 0x2C,0x17,0x25,0xD0,0x1A,0x38,0xB7,0x2A, | ||
| 101 | 0x39,0x61,0x37,0xDC,0x79,0xFB,0x9F,0x45 | ||
| 102 | |||
| 103 | /* 0xF9,0x78,0x32,0xB5,0x42,0x1A,0x6B,0x38, | ||
| 104 | 0x9A,0x44,0xD6,0x04,0x19,0x43,0xC4,0xD9, | ||
| 105 | 0x3D,0x1E,0xAE,0x47,0xFC,0xCF,0x29,0x0B,*/ | ||
| 106 | }; | ||
| 107 | |||
| 108 | static int cfb64_test(unsigned char *cfb_cipher); | ||
| 109 | static char *pt(unsigned char *p); | ||
| 110 | int main(int argc, char *argv[]) | ||
| 111 | { | ||
| 112 | int i,err=0; | ||
| 113 | IDEA_KEY_SCHEDULE key,dkey; | ||
| 114 | unsigned char iv[8]; | ||
| 115 | |||
| 116 | idea_set_encrypt_key(k,&key); | ||
| 117 | idea_ecb_encrypt(in,out,&key); | ||
| 118 | if (memcmp(out,c,8) != 0) | ||
| 119 | { | ||
| 120 | printf("ecb idea error encrypting\n"); | ||
| 121 | printf("got :"); | ||
| 122 | for (i=0; i<8; i++) | ||
| 123 | printf("%02X ",out[i]); | ||
| 124 | printf("\n"); | ||
| 125 | printf("expected:"); | ||
| 126 | for (i=0; i<8; i++) | ||
| 127 | printf("%02X ",c[i]); | ||
| 128 | err=20; | ||
| 129 | printf("\n"); | ||
| 130 | } | ||
| 131 | |||
| 132 | idea_set_decrypt_key(&key,&dkey); | ||
| 133 | idea_ecb_encrypt(c,out,&dkey); | ||
| 134 | if (memcmp(out,in,8) != 0) | ||
| 135 | { | ||
| 136 | printf("ecb idea error decrypting\n"); | ||
| 137 | printf("got :"); | ||
| 138 | for (i=0; i<8; i++) | ||
| 139 | printf("%02X ",out[i]); | ||
| 140 | printf("\n"); | ||
| 141 | printf("expected:"); | ||
| 142 | for (i=0; i<8; i++) | ||
| 143 | printf("%02X ",in[i]); | ||
| 144 | printf("\n"); | ||
| 145 | err=3; | ||
| 146 | } | ||
| 147 | |||
| 148 | if (err == 0) printf("ecb idea ok\n"); | ||
| 149 | |||
| 150 | memcpy(iv,k,8); | ||
| 151 | idea_cbc_encrypt((unsigned char *)text,out,strlen(text)+1,&key,iv,1); | ||
| 152 | memcpy(iv,k,8); | ||
| 153 | idea_cbc_encrypt(out,out,8,&dkey,iv,0); | ||
| 154 | idea_cbc_encrypt(&(out[8]),&(out[8]),strlen(text)+1-8,&dkey,iv,0); | ||
| 155 | if (memcmp(text,out,strlen(text)+1) != 0) | ||
| 156 | { | ||
| 157 | printf("cbc idea bad\n"); | ||
| 158 | err=4; | ||
| 159 | } | ||
| 160 | else | ||
| 161 | printf("cbc idea ok\n"); | ||
| 162 | |||
| 163 | printf("cfb64 idea "); | ||
| 164 | if (cfb64_test(cfb_cipher64)) | ||
| 165 | { | ||
| 166 | printf("bad\n"); | ||
| 167 | err=5; | ||
| 168 | } | ||
| 169 | else | ||
| 170 | printf("ok\n"); | ||
| 171 | |||
| 172 | #ifdef OPENSSL_SYS_NETWARE | ||
| 173 | if (err) printf("ERROR: %d\n", err); | ||
| 174 | #endif | ||
| 175 | EXIT(err); | ||
| 176 | return(err); | ||
| 177 | } | ||
| 178 | |||
| 179 | static int cfb64_test(unsigned char *cfb_cipher) | ||
| 180 | { | ||
| 181 | IDEA_KEY_SCHEDULE eks,dks; | ||
| 182 | int err=0,i,n; | ||
| 183 | |||
| 184 | idea_set_encrypt_key(cfb_key,&eks); | ||
| 185 | idea_set_decrypt_key(&eks,&dks); | ||
| 186 | memcpy(cfb_tmp,cfb_iv,8); | ||
| 187 | n=0; | ||
| 188 | idea_cfb64_encrypt(plain,cfb_buf1,(long)12,&eks, | ||
| 189 | cfb_tmp,&n,IDEA_ENCRYPT); | ||
| 190 | idea_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]), | ||
| 191 | (long)CFB_TEST_SIZE-12,&eks, | ||
| 192 | cfb_tmp,&n,IDEA_ENCRYPT); | ||
| 193 | if (memcmp(cfb_cipher,cfb_buf1,CFB_TEST_SIZE) != 0) | ||
| 194 | { | ||
| 195 | err=1; | ||
| 196 | printf("idea_cfb64_encrypt encrypt error\n"); | ||
| 197 | for (i=0; i<CFB_TEST_SIZE; i+=8) | ||
| 198 | printf("%s\n",pt(&(cfb_buf1[i]))); | ||
| 199 | } | ||
| 200 | memcpy(cfb_tmp,cfb_iv,8); | ||
| 201 | n=0; | ||
| 202 | idea_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,&eks, | ||
| 203 | cfb_tmp,&n,IDEA_DECRYPT); | ||
| 204 | idea_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]), | ||
| 205 | (long)CFB_TEST_SIZE-17,&dks, | ||
| 206 | cfb_tmp,&n,IDEA_DECRYPT); | ||
| 207 | if (memcmp(plain,cfb_buf2,CFB_TEST_SIZE) != 0) | ||
| 208 | { | ||
| 209 | err=1; | ||
| 210 | printf("idea_cfb_encrypt decrypt error\n"); | ||
| 211 | for (i=0; i<24; i+=8) | ||
| 212 | printf("%s\n",pt(&(cfb_buf2[i]))); | ||
| 213 | } | ||
| 214 | return(err); | ||
| 215 | } | ||
| 216 | |||
| 217 | static char *pt(unsigned char *p) | ||
| 218 | { | ||
| 219 | static char bufs[10][20]; | ||
| 220 | static int bnum=0; | ||
| 221 | char *ret; | ||
| 222 | int i; | ||
| 223 | static char *f="0123456789ABCDEF"; | ||
| 224 | |||
| 225 | ret= &(bufs[bnum++][0]); | ||
| 226 | bnum%=10; | ||
| 227 | for (i=0; i<8; i++) | ||
| 228 | { | ||
| 229 | ret[i*2]=f[(p[i]>>4)&0xf]; | ||
| 230 | ret[i*2+1]=f[p[i]&0xf]; | ||
| 231 | } | ||
| 232 | ret[16]='\0'; | ||
| 233 | return(ret); | ||
| 234 | } | ||
| 235 | #endif | ||
diff --git a/src/lib/libcrypto/idea/version b/src/lib/libcrypto/idea/version new file mode 100644 index 0000000000..3f22293795 --- /dev/null +++ b/src/lib/libcrypto/idea/version | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | 1.1 07/12/95 - eay | ||
| 2 | Many thanks to Rhys Weatherley <rweather@us.oracle.com> | ||
| 3 | for pointing out that I was assuming little endian byte | ||
| 4 | order for all quantities what idea actually used | ||
| 5 | bigendian. No where in the spec does it mention | ||
| 6 | this, it is all in terms of 16 bit numbers and even the example | ||
| 7 | does not use byte streams for the input example :-(. | ||
| 8 | If you byte swap each pair of input, keys and iv, the functions | ||
| 9 | would produce the output as the old version :-(. | ||
| 10 | |||
| 11 | 1.0 ??/??/95 - eay | ||
| 12 | First version. | ||
