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 | 103 | ||||
-rw-r--r-- | src/lib/libcrypto/idea/idea_lcl.h | 215 |
7 files changed, 0 insertions, 968 deletions
diff --git a/src/lib/libcrypto/idea/i_cbc.c b/src/lib/libcrypto/idea/i_cbc.c deleted file mode 100644 index ecb9cb8b83..0000000000 --- a/src/lib/libcrypto/idea/i_cbc.c +++ /dev/null | |||
@@ -1,168 +0,0 @@ | |||
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 deleted file mode 100644 index 66d49d520e..0000000000 --- a/src/lib/libcrypto/idea/i_cfb64.c +++ /dev/null | |||
@@ -1,122 +0,0 @@ | |||
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 deleted file mode 100644 index fef38230a7..0000000000 --- a/src/lib/libcrypto/idea/i_ecb.c +++ /dev/null | |||
@@ -1,85 +0,0 @@ | |||
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 deleted file mode 100644 index e749e88e34..0000000000 --- a/src/lib/libcrypto/idea/i_ofb64.c +++ /dev/null | |||
@@ -1,111 +0,0 @@ | |||
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 deleted file mode 100644 index afb830964d..0000000000 --- a/src/lib/libcrypto/idea/i_skey.c +++ /dev/null | |||
@@ -1,164 +0,0 @@ | |||
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 deleted file mode 100644 index e9a1e7f1a5..0000000000 --- a/src/lib/libcrypto/idea/idea.h +++ /dev/null | |||
@@ -1,103 +0,0 @@ | |||
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 deleted file mode 100644 index f3dbfa67e9..0000000000 --- a/src/lib/libcrypto/idea/idea_lcl.h +++ /dev/null | |||
@@ -1,215 +0,0 @@ | |||
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 | |||