diff options
Diffstat (limited to 'src/lib/libcrypto/idea')
| -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 | 100 | ||||
| -rw-r--r-- | src/lib/libcrypto/idea/idea_lcl.h | 215 | ||||
| -rw-r--r-- | src/lib/libcrypto/idea/idea_spd.c | 299 |
8 files changed, 1264 insertions, 0 deletions
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..5782e54b0f --- /dev/null +++ b/src/lib/libcrypto/idea/idea.h | |||
| @@ -0,0 +1,100 @@ | |||
| 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 | void idea_set_encrypt_key(const unsigned char *key, IDEA_KEY_SCHEDULE *ks); | ||
| 87 | void idea_set_decrypt_key(IDEA_KEY_SCHEDULE *ek, IDEA_KEY_SCHEDULE *dk); | ||
| 88 | void idea_cbc_encrypt(const unsigned char *in, unsigned char *out, | ||
| 89 | long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv,int enc); | ||
| 90 | void idea_cfb64_encrypt(const unsigned char *in, unsigned char *out, | ||
| 91 | long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, | ||
| 92 | int *num,int enc); | ||
| 93 | void idea_ofb64_encrypt(const unsigned char *in, unsigned char *out, | ||
| 94 | long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, int *num); | ||
| 95 | void idea_encrypt(unsigned long *in, IDEA_KEY_SCHEDULE *ks); | ||
| 96 | #ifdef __cplusplus | ||
| 97 | } | ||
| 98 | #endif | ||
| 99 | |||
| 100 | #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/idea_spd.c b/src/lib/libcrypto/idea/idea_spd.c new file mode 100644 index 0000000000..699353e871 --- /dev/null +++ b/src/lib/libcrypto/idea/idea_spd.c | |||
| @@ -0,0 +1,299 @@ | |||
| 1 | /* crypto/idea/idea_spd.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 | /* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */ | ||
| 60 | /* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */ | ||
| 61 | |||
| 62 | #if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX) | ||
| 63 | #define TIMES | ||
| 64 | #endif | ||
| 65 | |||
| 66 | #include <stdio.h> | ||
| 67 | |||
| 68 | #include <openssl/e_os2.h> | ||
| 69 | #include OPENSSL_UNISTD_IO | ||
| 70 | OPENSSL_DECLARE_EXIT | ||
| 71 | |||
| 72 | #ifndef OPENSSL_SYS_NETWARE | ||
| 73 | #include <signal.h> | ||
| 74 | #endif | ||
| 75 | |||
| 76 | #ifndef _IRIX | ||
| 77 | #include <time.h> | ||
| 78 | #endif | ||
| 79 | #ifdef TIMES | ||
| 80 | #include <sys/types.h> | ||
| 81 | #include <sys/times.h> | ||
| 82 | #endif | ||
| 83 | |||
| 84 | /* Depending on the VMS version, the tms structure is perhaps defined. | ||
| 85 | The __TMS macro will show if it was. If it wasn't defined, we should | ||
| 86 | undefine TIMES, since that tells the rest of the program how things | ||
| 87 | should be handled. -- Richard Levitte */ | ||
| 88 | #if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS) | ||
| 89 | #undef TIMES | ||
| 90 | #endif | ||
| 91 | |||
| 92 | #ifndef TIMES | ||
| 93 | #include <sys/timeb.h> | ||
| 94 | #endif | ||
| 95 | |||
| 96 | #if defined(sun) || defined(__ultrix) | ||
| 97 | #define _POSIX_SOURCE | ||
| 98 | #include <limits.h> | ||
| 99 | #include <sys/param.h> | ||
| 100 | #endif | ||
| 101 | |||
| 102 | #include <openssl/idea.h> | ||
| 103 | |||
| 104 | /* The following if from times(3) man page. It may need to be changed */ | ||
| 105 | #ifndef HZ | ||
| 106 | #ifndef CLK_TCK | ||
| 107 | #define HZ 100.0 | ||
| 108 | #else /* CLK_TCK */ | ||
| 109 | #define HZ ((double)CLK_TCK) | ||
| 110 | #endif | ||
| 111 | #endif | ||
| 112 | |||
| 113 | #define BUFSIZE ((long)1024) | ||
| 114 | long run=0; | ||
| 115 | |||
| 116 | double Time_F(int s); | ||
| 117 | #ifdef SIGALRM | ||
| 118 | #if defined(__STDC__) || defined(sgi) || defined(_AIX) | ||
| 119 | #define SIGRETTYPE void | ||
| 120 | #else | ||
| 121 | #define SIGRETTYPE int | ||
| 122 | #endif | ||
| 123 | |||
| 124 | SIGRETTYPE sig_done(int sig); | ||
| 125 | SIGRETTYPE sig_done(int sig) | ||
| 126 | { | ||
| 127 | signal(SIGALRM,sig_done); | ||
| 128 | run=0; | ||
| 129 | #ifdef LINT | ||
| 130 | sig=sig; | ||
| 131 | #endif | ||
| 132 | } | ||
| 133 | #endif | ||
| 134 | |||
| 135 | #define START 0 | ||
| 136 | #define STOP 1 | ||
| 137 | |||
| 138 | double Time_F(int s) | ||
| 139 | { | ||
| 140 | double ret; | ||
| 141 | #ifdef TIMES | ||
| 142 | static struct tms tstart,tend; | ||
| 143 | |||
| 144 | if (s == START) | ||
| 145 | { | ||
| 146 | times(&tstart); | ||
| 147 | return(0); | ||
| 148 | } | ||
| 149 | else | ||
| 150 | { | ||
| 151 | times(&tend); | ||
| 152 | ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ; | ||
| 153 | return((ret == 0.0)?1e-6:ret); | ||
| 154 | } | ||
| 155 | #else /* !times() */ | ||
| 156 | static struct timeb tstart,tend; | ||
| 157 | long i; | ||
| 158 | |||
| 159 | if (s == START) | ||
| 160 | { | ||
| 161 | ftime(&tstart); | ||
| 162 | return(0); | ||
| 163 | } | ||
| 164 | else | ||
| 165 | { | ||
| 166 | ftime(&tend); | ||
| 167 | i=(long)tend.millitm-(long)tstart.millitm; | ||
| 168 | ret=((double)(tend.time-tstart.time))+((double)i)/1e3; | ||
| 169 | return((ret == 0.0)?1e-6:ret); | ||
| 170 | } | ||
| 171 | #endif | ||
| 172 | } | ||
| 173 | |||
| 174 | int main(int argc, char **argv) | ||
| 175 | { | ||
| 176 | long count; | ||
| 177 | static unsigned char buf[BUFSIZE]; | ||
| 178 | static unsigned char key[] ={ | ||
| 179 | 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0, | ||
| 180 | 0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10, | ||
| 181 | }; | ||
| 182 | IDEA_KEY_SCHEDULE sch; | ||
| 183 | double a,aa,b,c,d; | ||
| 184 | #ifndef SIGALRM | ||
| 185 | long ca,cca,cb,cc; | ||
| 186 | #endif | ||
| 187 | |||
| 188 | #ifndef TIMES | ||
| 189 | printf("To get the most accurate results, try to run this\n"); | ||
| 190 | printf("program when this computer is idle.\n"); | ||
| 191 | #endif | ||
| 192 | |||
| 193 | #ifndef SIGALRM | ||
| 194 | printf("First we calculate the approximate speed ...\n"); | ||
| 195 | idea_set_encrypt_key(key,&sch); | ||
| 196 | count=10; | ||
| 197 | do { | ||
| 198 | long i; | ||
| 199 | IDEA_INT data[2]; | ||
| 200 | |||
| 201 | count*=2; | ||
| 202 | Time_F(START); | ||
| 203 | for (i=count; i; i--) | ||
| 204 | idea_encrypt(data,&sch); | ||
| 205 | d=Time_F(STOP); | ||
| 206 | } while (d < 3.0); | ||
| 207 | ca=count/4; | ||
| 208 | cca=count/200; | ||
| 209 | cb=count; | ||
| 210 | cc=count*8/BUFSIZE+1; | ||
| 211 | printf("idea_set_encrypt_key %ld times\n",ca); | ||
| 212 | #define COND(d) (count <= (d)) | ||
| 213 | #define COUNT(d) (d) | ||
| 214 | #else | ||
| 215 | #define COND(c) (run) | ||
| 216 | #define COUNT(d) (count) | ||
| 217 | signal(SIGALRM,sig_done); | ||
| 218 | printf("Doing idea_set_encrypt_key for 10 seconds\n"); | ||
| 219 | alarm(10); | ||
| 220 | #endif | ||
| 221 | |||
| 222 | Time_F(START); | ||
| 223 | for (count=0,run=1; COND(ca); count+=4) | ||
| 224 | { | ||
| 225 | idea_set_encrypt_key(key,&sch); | ||
| 226 | idea_set_encrypt_key(key,&sch); | ||
| 227 | idea_set_encrypt_key(key,&sch); | ||
| 228 | idea_set_encrypt_key(key,&sch); | ||
| 229 | } | ||
| 230 | d=Time_F(STOP); | ||
| 231 | printf("%ld idea idea_set_encrypt_key's in %.2f seconds\n",count,d); | ||
| 232 | a=((double)COUNT(ca))/d; | ||
| 233 | |||
| 234 | #ifdef SIGALRM | ||
| 235 | printf("Doing idea_set_decrypt_key for 10 seconds\n"); | ||
| 236 | alarm(10); | ||
| 237 | #else | ||
| 238 | printf("Doing idea_set_decrypt_key %ld times\n",cca); | ||
| 239 | #endif | ||
| 240 | |||
| 241 | Time_F(START); | ||
| 242 | for (count=0,run=1; COND(cca); count+=4) | ||
| 243 | { | ||
| 244 | idea_set_decrypt_key(&sch,&sch); | ||
| 245 | idea_set_decrypt_key(&sch,&sch); | ||
| 246 | idea_set_decrypt_key(&sch,&sch); | ||
| 247 | idea_set_decrypt_key(&sch,&sch); | ||
| 248 | } | ||
| 249 | d=Time_F(STOP); | ||
| 250 | printf("%ld idea idea_set_decrypt_key's in %.2f seconds\n",count,d); | ||
| 251 | aa=((double)COUNT(cca))/d; | ||
| 252 | |||
| 253 | #ifdef SIGALRM | ||
| 254 | printf("Doing idea_encrypt's for 10 seconds\n"); | ||
| 255 | alarm(10); | ||
| 256 | #else | ||
| 257 | printf("Doing idea_encrypt %ld times\n",cb); | ||
| 258 | #endif | ||
| 259 | Time_F(START); | ||
| 260 | for (count=0,run=1; COND(cb); count+=4) | ||
| 261 | { | ||
| 262 | unsigned long data[2]; | ||
| 263 | |||
| 264 | idea_encrypt(data,&sch); | ||
| 265 | idea_encrypt(data,&sch); | ||
| 266 | idea_encrypt(data,&sch); | ||
| 267 | idea_encrypt(data,&sch); | ||
| 268 | } | ||
| 269 | d=Time_F(STOP); | ||
| 270 | printf("%ld idea_encrypt's in %.2f second\n",count,d); | ||
| 271 | b=((double)COUNT(cb)*8)/d; | ||
| 272 | |||
| 273 | #ifdef SIGALRM | ||
| 274 | printf("Doing idea_cbc_encrypt on %ld byte blocks for 10 seconds\n", | ||
| 275 | BUFSIZE); | ||
| 276 | alarm(10); | ||
| 277 | #else | ||
| 278 | printf("Doing idea_cbc_encrypt %ld times on %ld byte blocks\n",cc, | ||
| 279 | BUFSIZE); | ||
| 280 | #endif | ||
| 281 | Time_F(START); | ||
| 282 | for (count=0,run=1; COND(cc); count++) | ||
| 283 | idea_cbc_encrypt(buf,buf,BUFSIZE,&sch, | ||
| 284 | &(key[0]),IDEA_ENCRYPT); | ||
| 285 | d=Time_F(STOP); | ||
| 286 | printf("%ld idea_cbc_encrypt's of %ld byte blocks in %.2f second\n", | ||
| 287 | count,BUFSIZE,d); | ||
| 288 | c=((double)COUNT(cc)*BUFSIZE)/d; | ||
| 289 | |||
| 290 | printf("IDEA set_encrypt_key per sec = %12.2f (%9.3fuS)\n",a,1.0e6/a); | ||
| 291 | printf("IDEA set_decrypt_key per sec = %12.2f (%9.3fuS)\n",aa,1.0e6/aa); | ||
| 292 | printf("IDEA raw ecb bytes per sec = %12.2f (%9.3fuS)\n",b,8.0e6/b); | ||
| 293 | printf("IDEA cbc bytes per sec = %12.2f (%9.3fuS)\n",c,8.0e6/c); | ||
| 294 | exit(0); | ||
| 295 | #if defined(LINT) || defined(OPENSSL_SYS_MSDOS) | ||
| 296 | return(0); | ||
| 297 | #endif | ||
| 298 | } | ||
| 299 | |||
