diff options
author | jsing <> | 2024-03-27 11:24:15 +0000 |
---|---|---|
committer | jsing <> | 2024-03-27 11:24:15 +0000 |
commit | e333d9e70e8e1f3a91303e95e5541bc99a649c73 (patch) | |
tree | 25fd2e6c6ce66cbe42a81228ebd582722502c7ff /src/lib | |
parent | aeccd86b593fda3b76aa590b49519a661b121928 (diff) | |
download | openbsd-e333d9e70e8e1f3a91303e95e5541bc99a649c73.tar.gz openbsd-e333d9e70e8e1f3a91303e95e5541bc99a649c73.tar.bz2 openbsd-e333d9e70e8e1f3a91303e95e5541bc99a649c73.zip |
Consolidate blowfish code.
Requested by tb@
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/Makefile | 8 | ||||
-rw-r--r-- | src/lib/libcrypto/bf/bf_cfb64.c | 124 | ||||
-rw-r--r-- | src/lib/libcrypto/bf/bf_ecb.c | 89 | ||||
-rw-r--r-- | src/lib/libcrypto/bf/bf_enc.c | 304 | ||||
-rw-r--r-- | src/lib/libcrypto/bf/bf_ofb64.c | 111 | ||||
-rw-r--r-- | src/lib/libcrypto/bf/blowfish.c (renamed from src/lib/libcrypto/bf/bf_skey.c) | 384 |
6 files changed, 381 insertions, 639 deletions
diff --git a/src/lib/libcrypto/Makefile b/src/lib/libcrypto/Makefile index 4ea8d0c2ad..606dc61792 100644 --- a/src/lib/libcrypto/Makefile +++ b/src/lib/libcrypto/Makefile | |||
@@ -1,4 +1,4 @@ | |||
1 | # $OpenBSD: Makefile,v 1.176 2024/03/27 11:12:08 jsing Exp $ | 1 | # $OpenBSD: Makefile,v 1.177 2024/03/27 11:24:15 jsing Exp $ |
2 | 2 | ||
3 | LIB= crypto | 3 | LIB= crypto |
4 | LIBREBUILD=y | 4 | LIBREBUILD=y |
@@ -142,11 +142,7 @@ SRCS+= x_x509.c | |||
142 | SRCS+= x_x509a.c | 142 | SRCS+= x_x509a.c |
143 | 143 | ||
144 | # bf/ | 144 | # bf/ |
145 | SRCS+= bf_cfb64.c | 145 | SRCS+= blowfish.c |
146 | SRCS+= bf_ecb.c | ||
147 | SRCS+= bf_enc.c | ||
148 | SRCS+= bf_ofb64.c | ||
149 | SRCS+= bf_skey.c | ||
150 | 146 | ||
151 | # bio/ | 147 | # bio/ |
152 | SRCS+= b_dump.c | 148 | SRCS+= b_dump.c |
diff --git a/src/lib/libcrypto/bf/bf_cfb64.c b/src/lib/libcrypto/bf/bf_cfb64.c deleted file mode 100644 index 87dccae263..0000000000 --- a/src/lib/libcrypto/bf/bf_cfb64.c +++ /dev/null | |||
@@ -1,124 +0,0 @@ | |||
1 | /* $OpenBSD: bf_cfb64.c,v 1.8 2022/11/26 16:08:51 tb Exp $ */ | ||
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/blowfish.h> | ||
60 | |||
61 | #include "bf_local.h" | ||
62 | |||
63 | /* | ||
64 | * The input and output encrypted as though 64bit cfb mode is being | ||
65 | * used. The extra state information to record how much of the | ||
66 | * 64bit block we have used is contained in *num; | ||
67 | */ | ||
68 | |||
69 | void | ||
70 | BF_cfb64_encrypt(const unsigned char *in, unsigned char *out, long length, | ||
71 | const BF_KEY *schedule, unsigned char *ivec, int *num, int encrypt) | ||
72 | { | ||
73 | BF_LONG v0, v1, t; | ||
74 | int n= *num; | ||
75 | long l = length; | ||
76 | BF_LONG ti[2]; | ||
77 | unsigned char *iv, c, cc; | ||
78 | |||
79 | iv = (unsigned char *)ivec; | ||
80 | if (encrypt) { | ||
81 | while (l--) { | ||
82 | if (n == 0) { | ||
83 | n2l(iv, v0); | ||
84 | ti[0] = v0; | ||
85 | n2l(iv, v1); | ||
86 | ti[1] = v1; | ||
87 | BF_encrypt((BF_LONG *)ti, schedule); | ||
88 | iv = (unsigned char *)ivec; | ||
89 | t = ti[0]; | ||
90 | l2n(t, iv); | ||
91 | t = ti[1]; | ||
92 | l2n(t, iv); | ||
93 | iv = (unsigned char *)ivec; | ||
94 | } | ||
95 | c= *(in++)^iv[n]; | ||
96 | *(out++) = c; | ||
97 | iv[n] = c; | ||
98 | n = (n + 1)&0x07; | ||
99 | } | ||
100 | } else { | ||
101 | while (l--) { | ||
102 | if (n == 0) { | ||
103 | n2l(iv, v0); | ||
104 | ti[0] = v0; | ||
105 | n2l(iv, v1); | ||
106 | ti[1] = v1; | ||
107 | BF_encrypt((BF_LONG *)ti, schedule); | ||
108 | iv = (unsigned char *)ivec; | ||
109 | t = ti[0]; | ||
110 | l2n(t, iv); | ||
111 | t = ti[1]; | ||
112 | l2n(t, iv); | ||
113 | iv = (unsigned char *)ivec; | ||
114 | } | ||
115 | cc= *(in++); | ||
116 | c = iv[n]; | ||
117 | iv[n] = cc; | ||
118 | *(out++) = c^cc; | ||
119 | n = (n + 1)&0x07; | ||
120 | } | ||
121 | } | ||
122 | v0 = v1 = ti[0] = ti[1] = t=c = cc = 0; | ||
123 | *num = n; | ||
124 | } | ||
diff --git a/src/lib/libcrypto/bf/bf_ecb.c b/src/lib/libcrypto/bf/bf_ecb.c deleted file mode 100644 index eda6f193b3..0000000000 --- a/src/lib/libcrypto/bf/bf_ecb.c +++ /dev/null | |||
@@ -1,89 +0,0 @@ | |||
1 | /* $OpenBSD: bf_ecb.c,v 1.10 2023/07/28 10:35:14 tb Exp $ */ | ||
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/blowfish.h> | ||
60 | #include <openssl/opensslv.h> | ||
61 | |||
62 | #include "bf_local.h" | ||
63 | |||
64 | /* | ||
65 | * Blowfish as implemented from 'Blowfish: Springer-Verlag paper' | ||
66 | * (From LECTURE NOTES IN COMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION, | ||
67 | * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993) | ||
68 | */ | ||
69 | |||
70 | void | ||
71 | BF_ecb_encrypt(const unsigned char *in, unsigned char *out, | ||
72 | const BF_KEY *key, int encrypt) | ||
73 | { | ||
74 | BF_LONG l, d[2]; | ||
75 | |||
76 | n2l(in, l); | ||
77 | d[0] = l; | ||
78 | n2l(in, l); | ||
79 | d[1] = l; | ||
80 | if (encrypt) | ||
81 | BF_encrypt(d, key); | ||
82 | else | ||
83 | BF_decrypt(d, key); | ||
84 | l = d[0]; | ||
85 | l2n(l, out); | ||
86 | l = d[1]; | ||
87 | l2n(l, out); | ||
88 | l = d[0] = d[1] = 0; | ||
89 | } | ||
diff --git a/src/lib/libcrypto/bf/bf_enc.c b/src/lib/libcrypto/bf/bf_enc.c deleted file mode 100644 index bbefe7d526..0000000000 --- a/src/lib/libcrypto/bf/bf_enc.c +++ /dev/null | |||
@@ -1,304 +0,0 @@ | |||
1 | /* $OpenBSD: bf_enc.c,v 1.9 2022/11/26 16:08:51 tb Exp $ */ | ||
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/blowfish.h> | ||
60 | |||
61 | #include "bf_local.h" | ||
62 | |||
63 | /* | ||
64 | * Blowfish as implemented from 'Blowfish: Springer-Verlag paper' | ||
65 | * (From LECTURE NOTES IN COMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION, | ||
66 | * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993) | ||
67 | */ | ||
68 | |||
69 | #if (BF_ROUNDS != 16) && (BF_ROUNDS != 20) | ||
70 | #error If you set BF_ROUNDS to some value other than 16 or 20, you will have \ | ||
71 | to modify the code. | ||
72 | #endif | ||
73 | |||
74 | void | ||
75 | BF_encrypt(BF_LONG *data, const BF_KEY *key) | ||
76 | { | ||
77 | #ifndef BF_PTR2 | ||
78 | BF_LONG l, r; | ||
79 | const BF_LONG *p, *s; | ||
80 | |||
81 | p = key->P; | ||
82 | s = &(key->S[0]); | ||
83 | l = data[0]; | ||
84 | r = data[1]; | ||
85 | |||
86 | l ^= p[0]; | ||
87 | BF_ENC(r, l,s, p[1]); | ||
88 | BF_ENC(l, r,s, p[2]); | ||
89 | BF_ENC(r, l,s, p[3]); | ||
90 | BF_ENC(l, r,s, p[4]); | ||
91 | BF_ENC(r, l,s, p[5]); | ||
92 | BF_ENC(l, r,s, p[6]); | ||
93 | BF_ENC(r, l,s, p[7]); | ||
94 | BF_ENC(l, r,s, p[8]); | ||
95 | BF_ENC(r, l,s, p[9]); | ||
96 | BF_ENC(l, r,s, p[10]); | ||
97 | BF_ENC(r, l,s, p[11]); | ||
98 | BF_ENC(l, r,s, p[12]); | ||
99 | BF_ENC(r, l,s, p[13]); | ||
100 | BF_ENC(l, r,s, p[14]); | ||
101 | BF_ENC(r, l,s, p[15]); | ||
102 | BF_ENC(l, r,s, p[16]); | ||
103 | #if BF_ROUNDS == 20 | ||
104 | BF_ENC(r, l,s, p[17]); | ||
105 | BF_ENC(l, r,s, p[18]); | ||
106 | BF_ENC(r, l,s, p[19]); | ||
107 | BF_ENC(l, r,s, p[20]); | ||
108 | #endif | ||
109 | r ^= p[BF_ROUNDS + 1]; | ||
110 | |||
111 | data[1] = l&0xffffffffL; | ||
112 | data[0] = r&0xffffffffL; | ||
113 | #else | ||
114 | BF_LONG l, r,t, *k; | ||
115 | |||
116 | l = data[0]; | ||
117 | r = data[1]; | ||
118 | k = (BF_LONG*)key; | ||
119 | |||
120 | l ^= k[0]; | ||
121 | BF_ENC(r, l, k, 1); | ||
122 | BF_ENC(l, r, k, 2); | ||
123 | BF_ENC(r, l, k, 3); | ||
124 | BF_ENC(l, r, k, 4); | ||
125 | BF_ENC(r, l, k, 5); | ||
126 | BF_ENC(l, r, k, 6); | ||
127 | BF_ENC(r, l, k, 7); | ||
128 | BF_ENC(l, r, k, 8); | ||
129 | BF_ENC(r, l, k, 9); | ||
130 | BF_ENC(l, r,k, 10); | ||
131 | BF_ENC(r, l,k, 11); | ||
132 | BF_ENC(l, r,k, 12); | ||
133 | BF_ENC(r, l,k, 13); | ||
134 | BF_ENC(l, r,k, 14); | ||
135 | BF_ENC(r, l,k, 15); | ||
136 | BF_ENC(l, r,k, 16); | ||
137 | #if BF_ROUNDS == 20 | ||
138 | BF_ENC(r, l,k, 17); | ||
139 | BF_ENC(l, r,k, 18); | ||
140 | BF_ENC(r, l,k, 19); | ||
141 | BF_ENC(l, r,k, 20); | ||
142 | #endif | ||
143 | r ^= k[BF_ROUNDS + 1]; | ||
144 | |||
145 | data[1] = l&0xffffffffL; | ||
146 | data[0] = r&0xffffffffL; | ||
147 | #endif | ||
148 | } | ||
149 | |||
150 | #ifndef BF_DEFAULT_OPTIONS | ||
151 | |||
152 | void | ||
153 | BF_decrypt(BF_LONG *data, const BF_KEY *key) | ||
154 | { | ||
155 | #ifndef BF_PTR2 | ||
156 | BF_LONG l, r; | ||
157 | const BF_LONG *p, *s; | ||
158 | |||
159 | p = key->P; | ||
160 | s = &(key->S[0]); | ||
161 | l = data[0]; | ||
162 | r = data[1]; | ||
163 | |||
164 | l ^= p[BF_ROUNDS + 1]; | ||
165 | #if BF_ROUNDS == 20 | ||
166 | BF_ENC(r, l,s, p[20]); | ||
167 | BF_ENC(l, r,s, p[19]); | ||
168 | BF_ENC(r, l,s, p[18]); | ||
169 | BF_ENC(l, r,s, p[17]); | ||
170 | #endif | ||
171 | BF_ENC(r, l,s, p[16]); | ||
172 | BF_ENC(l, r,s, p[15]); | ||
173 | BF_ENC(r, l,s, p[14]); | ||
174 | BF_ENC(l, r,s, p[13]); | ||
175 | BF_ENC(r, l,s, p[12]); | ||
176 | BF_ENC(l, r,s, p[11]); | ||
177 | BF_ENC(r, l,s, p[10]); | ||
178 | BF_ENC(l, r,s, p[9]); | ||
179 | BF_ENC(r, l,s, p[8]); | ||
180 | BF_ENC(l, r,s, p[7]); | ||
181 | BF_ENC(r, l,s, p[6]); | ||
182 | BF_ENC(l, r,s, p[5]); | ||
183 | BF_ENC(r, l,s, p[4]); | ||
184 | BF_ENC(l, r,s, p[3]); | ||
185 | BF_ENC(r, l,s, p[2]); | ||
186 | BF_ENC(l, r,s, p[1]); | ||
187 | r ^= p[0]; | ||
188 | |||
189 | data[1] = l&0xffffffffL; | ||
190 | data[0] = r&0xffffffffL; | ||
191 | #else | ||
192 | BF_LONG l, r,t, *k; | ||
193 | |||
194 | l = data[0]; | ||
195 | r = data[1]; | ||
196 | k = (BF_LONG *)key; | ||
197 | |||
198 | l ^= k[BF_ROUNDS + 1]; | ||
199 | #if BF_ROUNDS == 20 | ||
200 | BF_ENC(r, l,k, 20); | ||
201 | BF_ENC(l, r,k, 19); | ||
202 | BF_ENC(r, l,k, 18); | ||
203 | BF_ENC(l, r,k, 17); | ||
204 | #endif | ||
205 | BF_ENC(r, l,k, 16); | ||
206 | BF_ENC(l, r,k, 15); | ||
207 | BF_ENC(r, l,k, 14); | ||
208 | BF_ENC(l, r,k, 13); | ||
209 | BF_ENC(r, l,k, 12); | ||
210 | BF_ENC(l, r,k, 11); | ||
211 | BF_ENC(r, l,k, 10); | ||
212 | BF_ENC(l, r, k, 9); | ||
213 | BF_ENC(r, l, k, 8); | ||
214 | BF_ENC(l, r, k, 7); | ||
215 | BF_ENC(r, l, k, 6); | ||
216 | BF_ENC(l, r, k, 5); | ||
217 | BF_ENC(r, l, k, 4); | ||
218 | BF_ENC(l, r, k, 3); | ||
219 | BF_ENC(r, l, k, 2); | ||
220 | BF_ENC(l, r, k, 1); | ||
221 | r ^= k[0]; | ||
222 | |||
223 | data[1] = l&0xffffffffL; | ||
224 | data[0] = r&0xffffffffL; | ||
225 | #endif | ||
226 | } | ||
227 | |||
228 | void | ||
229 | BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, | ||
230 | const BF_KEY *schedule, unsigned char *ivec, int encrypt) | ||
231 | { | ||
232 | BF_LONG tin0, tin1; | ||
233 | BF_LONG tout0, tout1, xor0, xor1; | ||
234 | long l = length; | ||
235 | BF_LONG tin[2]; | ||
236 | |||
237 | if (encrypt) { | ||
238 | n2l(ivec, tout0); | ||
239 | n2l(ivec, tout1); | ||
240 | ivec -= 8; | ||
241 | for (l -= 8; l >= 0; l -= 8) { | ||
242 | n2l(in, tin0); | ||
243 | n2l(in, tin1); | ||
244 | tin0 ^= tout0; | ||
245 | tin1 ^= tout1; | ||
246 | tin[0] = tin0; | ||
247 | tin[1] = tin1; | ||
248 | BF_encrypt(tin, schedule); | ||
249 | tout0 = tin[0]; | ||
250 | tout1 = tin[1]; | ||
251 | l2n(tout0, out); | ||
252 | l2n(tout1, out); | ||
253 | } | ||
254 | if (l != -8) { | ||
255 | n2ln(in, tin0, tin1, l + 8); | ||
256 | tin0 ^= tout0; | ||
257 | tin1 ^= tout1; | ||
258 | tin[0] = tin0; | ||
259 | tin[1] = tin1; | ||
260 | BF_encrypt(tin, schedule); | ||
261 | tout0 = tin[0]; | ||
262 | tout1 = tin[1]; | ||
263 | l2n(tout0, out); | ||
264 | l2n(tout1, out); | ||
265 | } | ||
266 | l2n(tout0, ivec); | ||
267 | l2n(tout1, ivec); | ||
268 | } else { | ||
269 | n2l(ivec, xor0); | ||
270 | n2l(ivec, xor1); | ||
271 | ivec -= 8; | ||
272 | for (l -= 8; l >= 0; l -= 8) { | ||
273 | n2l(in, tin0); | ||
274 | n2l(in, tin1); | ||
275 | tin[0] = tin0; | ||
276 | tin[1] = tin1; | ||
277 | BF_decrypt(tin, schedule); | ||
278 | tout0 = tin[0]^xor0; | ||
279 | tout1 = tin[1]^xor1; | ||
280 | l2n(tout0, out); | ||
281 | l2n(tout1, out); | ||
282 | xor0 = tin0; | ||
283 | xor1 = tin1; | ||
284 | } | ||
285 | if (l != -8) { | ||
286 | n2l(in, tin0); | ||
287 | n2l(in, tin1); | ||
288 | tin[0] = tin0; | ||
289 | tin[1] = tin1; | ||
290 | BF_decrypt(tin, schedule); | ||
291 | tout0 = tin[0]^xor0; | ||
292 | tout1 = tin[1]^xor1; | ||
293 | l2nn(tout0, tout1, out, l + 8); | ||
294 | xor0 = tin0; | ||
295 | xor1 = tin1; | ||
296 | } | ||
297 | l2n(xor0, ivec); | ||
298 | l2n(xor1, ivec); | ||
299 | } | ||
300 | tin0 = tin1 = tout0 = tout1 = xor0 = xor1 = 0; | ||
301 | tin[0] = tin[1] = 0; | ||
302 | } | ||
303 | |||
304 | #endif | ||
diff --git a/src/lib/libcrypto/bf/bf_ofb64.c b/src/lib/libcrypto/bf/bf_ofb64.c deleted file mode 100644 index 8fe2478263..0000000000 --- a/src/lib/libcrypto/bf/bf_ofb64.c +++ /dev/null | |||
@@ -1,111 +0,0 @@ | |||
1 | /* $OpenBSD: bf_ofb64.c,v 1.8 2022/11/26 16:08:51 tb Exp $ */ | ||
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/blowfish.h> | ||
60 | |||
61 | #include "bf_local.h" | ||
62 | |||
63 | /* | ||
64 | * The input and output encrypted as though 64bit ofb mode is being | ||
65 | * used. The extra state information to record how much of the | ||
66 | * 64bit block we have used is contained in *num; | ||
67 | */ | ||
68 | void | ||
69 | BF_ofb64_encrypt(const unsigned char *in, unsigned char *out, long length, | ||
70 | const BF_KEY *schedule, unsigned char *ivec, int *num) | ||
71 | { | ||
72 | BF_LONG v0, v1, t; | ||
73 | int n= *num; | ||
74 | long l = length; | ||
75 | unsigned char d[8]; | ||
76 | char *dp; | ||
77 | BF_LONG ti[2]; | ||
78 | unsigned char *iv; | ||
79 | int save = 0; | ||
80 | |||
81 | iv = (unsigned char *)ivec; | ||
82 | n2l(iv, v0); | ||
83 | n2l(iv, v1); | ||
84 | ti[0] = v0; | ||
85 | ti[1] = v1; | ||
86 | dp = (char *)d; | ||
87 | l2n(v0, dp); | ||
88 | l2n(v1, dp); | ||
89 | while (l--) { | ||
90 | if (n == 0) { | ||
91 | BF_encrypt((BF_LONG *)ti, schedule); | ||
92 | dp = (char *)d; | ||
93 | t = ti[0]; | ||
94 | l2n(t, dp); | ||
95 | t = ti[1]; | ||
96 | l2n(t, dp); | ||
97 | save++; | ||
98 | } | ||
99 | *(out++)= *(in++)^d[n]; | ||
100 | n = (n + 1)&0x07; | ||
101 | } | ||
102 | if (save) { | ||
103 | v0 = ti[0]; | ||
104 | v1 = ti[1]; | ||
105 | iv = (unsigned char *)ivec; | ||
106 | l2n(v0, iv); | ||
107 | l2n(v1, iv); | ||
108 | } | ||
109 | t = v0 = v1 = ti[0] = ti[1] = 0; | ||
110 | *num = n; | ||
111 | } | ||
diff --git a/src/lib/libcrypto/bf/bf_skey.c b/src/lib/libcrypto/bf/blowfish.c index cc31034f18..4fa8a563f1 100644 --- a/src/lib/libcrypto/bf/bf_skey.c +++ b/src/lib/libcrypto/bf/blowfish.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bf_skey.c,v 1.17 2022/11/26 16:08:51 tb Exp $ */ | 1 | /* $OpenBSD: blowfish.c,v 1.1 2024/03/27 11:24:15 jsing Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -56,14 +56,23 @@ | |||
56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | ||
60 | #include <string.h> | ||
61 | |||
62 | #include <openssl/crypto.h> | ||
63 | #include <openssl/blowfish.h> | 59 | #include <openssl/blowfish.h> |
64 | 60 | ||
61 | #include <string.h> | ||
62 | |||
65 | #include "bf_local.h" | 63 | #include "bf_local.h" |
66 | 64 | ||
65 | /* | ||
66 | * Blowfish as implemented from 'Blowfish: Springer-Verlag paper' | ||
67 | * (From LECTURE NOTES IN COMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION, | ||
68 | * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993) | ||
69 | */ | ||
70 | |||
71 | #if (BF_ROUNDS != 16) && (BF_ROUNDS != 20) | ||
72 | #error If you set BF_ROUNDS to some value other than 16 or 20, you will have \ | ||
73 | to modify the code. | ||
74 | #endif | ||
75 | |||
67 | static const BF_KEY bf_init = { | 76 | static const BF_KEY bf_init = { |
68 | .P = { | 77 | .P = { |
69 | 0x243f6a88L, 0x85a308d3L, 0x13198a2eL, 0x03707344L, | 78 | 0x243f6a88L, 0x85a308d3L, 0x13198a2eL, 0x03707344L, |
@@ -333,6 +342,370 @@ static const BF_KEY bf_init = { | |||
333 | }; | 342 | }; |
334 | 343 | ||
335 | void | 344 | void |
345 | BF_encrypt(BF_LONG *data, const BF_KEY *key) | ||
346 | { | ||
347 | #ifndef BF_PTR2 | ||
348 | BF_LONG l, r; | ||
349 | const BF_LONG *p, *s; | ||
350 | |||
351 | p = key->P; | ||
352 | s = &(key->S[0]); | ||
353 | l = data[0]; | ||
354 | r = data[1]; | ||
355 | |||
356 | l ^= p[0]; | ||
357 | BF_ENC(r, l,s, p[1]); | ||
358 | BF_ENC(l, r,s, p[2]); | ||
359 | BF_ENC(r, l,s, p[3]); | ||
360 | BF_ENC(l, r,s, p[4]); | ||
361 | BF_ENC(r, l,s, p[5]); | ||
362 | BF_ENC(l, r,s, p[6]); | ||
363 | BF_ENC(r, l,s, p[7]); | ||
364 | BF_ENC(l, r,s, p[8]); | ||
365 | BF_ENC(r, l,s, p[9]); | ||
366 | BF_ENC(l, r,s, p[10]); | ||
367 | BF_ENC(r, l,s, p[11]); | ||
368 | BF_ENC(l, r,s, p[12]); | ||
369 | BF_ENC(r, l,s, p[13]); | ||
370 | BF_ENC(l, r,s, p[14]); | ||
371 | BF_ENC(r, l,s, p[15]); | ||
372 | BF_ENC(l, r,s, p[16]); | ||
373 | #if BF_ROUNDS == 20 | ||
374 | BF_ENC(r, l,s, p[17]); | ||
375 | BF_ENC(l, r,s, p[18]); | ||
376 | BF_ENC(r, l,s, p[19]); | ||
377 | BF_ENC(l, r,s, p[20]); | ||
378 | #endif | ||
379 | r ^= p[BF_ROUNDS + 1]; | ||
380 | |||
381 | data[1] = l&0xffffffffL; | ||
382 | data[0] = r&0xffffffffL; | ||
383 | #else | ||
384 | BF_LONG l, r,t, *k; | ||
385 | |||
386 | l = data[0]; | ||
387 | r = data[1]; | ||
388 | k = (BF_LONG*)key; | ||
389 | |||
390 | l ^= k[0]; | ||
391 | BF_ENC(r, l, k, 1); | ||
392 | BF_ENC(l, r, k, 2); | ||
393 | BF_ENC(r, l, k, 3); | ||
394 | BF_ENC(l, r, k, 4); | ||
395 | BF_ENC(r, l, k, 5); | ||
396 | BF_ENC(l, r, k, 6); | ||
397 | BF_ENC(r, l, k, 7); | ||
398 | BF_ENC(l, r, k, 8); | ||
399 | BF_ENC(r, l, k, 9); | ||
400 | BF_ENC(l, r,k, 10); | ||
401 | BF_ENC(r, l,k, 11); | ||
402 | BF_ENC(l, r,k, 12); | ||
403 | BF_ENC(r, l,k, 13); | ||
404 | BF_ENC(l, r,k, 14); | ||
405 | BF_ENC(r, l,k, 15); | ||
406 | BF_ENC(l, r,k, 16); | ||
407 | #if BF_ROUNDS == 20 | ||
408 | BF_ENC(r, l,k, 17); | ||
409 | BF_ENC(l, r,k, 18); | ||
410 | BF_ENC(r, l,k, 19); | ||
411 | BF_ENC(l, r,k, 20); | ||
412 | #endif | ||
413 | r ^= k[BF_ROUNDS + 1]; | ||
414 | |||
415 | data[1] = l&0xffffffffL; | ||
416 | data[0] = r&0xffffffffL; | ||
417 | #endif | ||
418 | } | ||
419 | |||
420 | #ifndef BF_DEFAULT_OPTIONS | ||
421 | |||
422 | void | ||
423 | BF_decrypt(BF_LONG *data, const BF_KEY *key) | ||
424 | { | ||
425 | #ifndef BF_PTR2 | ||
426 | BF_LONG l, r; | ||
427 | const BF_LONG *p, *s; | ||
428 | |||
429 | p = key->P; | ||
430 | s = &(key->S[0]); | ||
431 | l = data[0]; | ||
432 | r = data[1]; | ||
433 | |||
434 | l ^= p[BF_ROUNDS + 1]; | ||
435 | #if BF_ROUNDS == 20 | ||
436 | BF_ENC(r, l,s, p[20]); | ||
437 | BF_ENC(l, r,s, p[19]); | ||
438 | BF_ENC(r, l,s, p[18]); | ||
439 | BF_ENC(l, r,s, p[17]); | ||
440 | #endif | ||
441 | BF_ENC(r, l,s, p[16]); | ||
442 | BF_ENC(l, r,s, p[15]); | ||
443 | BF_ENC(r, l,s, p[14]); | ||
444 | BF_ENC(l, r,s, p[13]); | ||
445 | BF_ENC(r, l,s, p[12]); | ||
446 | BF_ENC(l, r,s, p[11]); | ||
447 | BF_ENC(r, l,s, p[10]); | ||
448 | BF_ENC(l, r,s, p[9]); | ||
449 | BF_ENC(r, l,s, p[8]); | ||
450 | BF_ENC(l, r,s, p[7]); | ||
451 | BF_ENC(r, l,s, p[6]); | ||
452 | BF_ENC(l, r,s, p[5]); | ||
453 | BF_ENC(r, l,s, p[4]); | ||
454 | BF_ENC(l, r,s, p[3]); | ||
455 | BF_ENC(r, l,s, p[2]); | ||
456 | BF_ENC(l, r,s, p[1]); | ||
457 | r ^= p[0]; | ||
458 | |||
459 | data[1] = l&0xffffffffL; | ||
460 | data[0] = r&0xffffffffL; | ||
461 | #else | ||
462 | BF_LONG l, r,t, *k; | ||
463 | |||
464 | l = data[0]; | ||
465 | r = data[1]; | ||
466 | k = (BF_LONG *)key; | ||
467 | |||
468 | l ^= k[BF_ROUNDS + 1]; | ||
469 | #if BF_ROUNDS == 20 | ||
470 | BF_ENC(r, l,k, 20); | ||
471 | BF_ENC(l, r,k, 19); | ||
472 | BF_ENC(r, l,k, 18); | ||
473 | BF_ENC(l, r,k, 17); | ||
474 | #endif | ||
475 | BF_ENC(r, l,k, 16); | ||
476 | BF_ENC(l, r,k, 15); | ||
477 | BF_ENC(r, l,k, 14); | ||
478 | BF_ENC(l, r,k, 13); | ||
479 | BF_ENC(r, l,k, 12); | ||
480 | BF_ENC(l, r,k, 11); | ||
481 | BF_ENC(r, l,k, 10); | ||
482 | BF_ENC(l, r, k, 9); | ||
483 | BF_ENC(r, l, k, 8); | ||
484 | BF_ENC(l, r, k, 7); | ||
485 | BF_ENC(r, l, k, 6); | ||
486 | BF_ENC(l, r, k, 5); | ||
487 | BF_ENC(r, l, k, 4); | ||
488 | BF_ENC(l, r, k, 3); | ||
489 | BF_ENC(r, l, k, 2); | ||
490 | BF_ENC(l, r, k, 1); | ||
491 | r ^= k[0]; | ||
492 | |||
493 | data[1] = l&0xffffffffL; | ||
494 | data[0] = r&0xffffffffL; | ||
495 | #endif | ||
496 | } | ||
497 | |||
498 | void | ||
499 | BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, | ||
500 | const BF_KEY *schedule, unsigned char *ivec, int encrypt) | ||
501 | { | ||
502 | BF_LONG tin0, tin1; | ||
503 | BF_LONG tout0, tout1, xor0, xor1; | ||
504 | long l = length; | ||
505 | BF_LONG tin[2]; | ||
506 | |||
507 | if (encrypt) { | ||
508 | n2l(ivec, tout0); | ||
509 | n2l(ivec, tout1); | ||
510 | ivec -= 8; | ||
511 | for (l -= 8; l >= 0; l -= 8) { | ||
512 | n2l(in, tin0); | ||
513 | n2l(in, tin1); | ||
514 | tin0 ^= tout0; | ||
515 | tin1 ^= tout1; | ||
516 | tin[0] = tin0; | ||
517 | tin[1] = tin1; | ||
518 | BF_encrypt(tin, schedule); | ||
519 | tout0 = tin[0]; | ||
520 | tout1 = tin[1]; | ||
521 | l2n(tout0, out); | ||
522 | l2n(tout1, out); | ||
523 | } | ||
524 | if (l != -8) { | ||
525 | n2ln(in, tin0, tin1, l + 8); | ||
526 | tin0 ^= tout0; | ||
527 | tin1 ^= tout1; | ||
528 | tin[0] = tin0; | ||
529 | tin[1] = tin1; | ||
530 | BF_encrypt(tin, schedule); | ||
531 | tout0 = tin[0]; | ||
532 | tout1 = tin[1]; | ||
533 | l2n(tout0, out); | ||
534 | l2n(tout1, out); | ||
535 | } | ||
536 | l2n(tout0, ivec); | ||
537 | l2n(tout1, ivec); | ||
538 | } else { | ||
539 | n2l(ivec, xor0); | ||
540 | n2l(ivec, xor1); | ||
541 | ivec -= 8; | ||
542 | for (l -= 8; l >= 0; l -= 8) { | ||
543 | n2l(in, tin0); | ||
544 | n2l(in, tin1); | ||
545 | tin[0] = tin0; | ||
546 | tin[1] = tin1; | ||
547 | BF_decrypt(tin, schedule); | ||
548 | tout0 = tin[0]^xor0; | ||
549 | tout1 = tin[1]^xor1; | ||
550 | l2n(tout0, out); | ||
551 | l2n(tout1, out); | ||
552 | xor0 = tin0; | ||
553 | xor1 = tin1; | ||
554 | } | ||
555 | if (l != -8) { | ||
556 | n2l(in, tin0); | ||
557 | n2l(in, tin1); | ||
558 | tin[0] = tin0; | ||
559 | tin[1] = tin1; | ||
560 | BF_decrypt(tin, schedule); | ||
561 | tout0 = tin[0]^xor0; | ||
562 | tout1 = tin[1]^xor1; | ||
563 | l2nn(tout0, tout1, out, l + 8); | ||
564 | xor0 = tin0; | ||
565 | xor1 = tin1; | ||
566 | } | ||
567 | l2n(xor0, ivec); | ||
568 | l2n(xor1, ivec); | ||
569 | } | ||
570 | tin0 = tin1 = tout0 = tout1 = xor0 = xor1 = 0; | ||
571 | tin[0] = tin[1] = 0; | ||
572 | } | ||
573 | |||
574 | /* | ||
575 | * The input and output encrypted as though 64bit cfb mode is being | ||
576 | * used. The extra state information to record how much of the | ||
577 | * 64bit block we have used is contained in *num; | ||
578 | */ | ||
579 | |||
580 | void | ||
581 | BF_cfb64_encrypt(const unsigned char *in, unsigned char *out, long length, | ||
582 | const BF_KEY *schedule, unsigned char *ivec, int *num, int encrypt) | ||
583 | { | ||
584 | BF_LONG v0, v1, t; | ||
585 | int n= *num; | ||
586 | long l = length; | ||
587 | BF_LONG ti[2]; | ||
588 | unsigned char *iv, c, cc; | ||
589 | |||
590 | iv = (unsigned char *)ivec; | ||
591 | if (encrypt) { | ||
592 | while (l--) { | ||
593 | if (n == 0) { | ||
594 | n2l(iv, v0); | ||
595 | ti[0] = v0; | ||
596 | n2l(iv, v1); | ||
597 | ti[1] = v1; | ||
598 | BF_encrypt((BF_LONG *)ti, schedule); | ||
599 | iv = (unsigned char *)ivec; | ||
600 | t = ti[0]; | ||
601 | l2n(t, iv); | ||
602 | t = ti[1]; | ||
603 | l2n(t, iv); | ||
604 | iv = (unsigned char *)ivec; | ||
605 | } | ||
606 | c= *(in++)^iv[n]; | ||
607 | *(out++) = c; | ||
608 | iv[n] = c; | ||
609 | n = (n + 1)&0x07; | ||
610 | } | ||
611 | } else { | ||
612 | while (l--) { | ||
613 | if (n == 0) { | ||
614 | n2l(iv, v0); | ||
615 | ti[0] = v0; | ||
616 | n2l(iv, v1); | ||
617 | ti[1] = v1; | ||
618 | BF_encrypt((BF_LONG *)ti, schedule); | ||
619 | iv = (unsigned char *)ivec; | ||
620 | t = ti[0]; | ||
621 | l2n(t, iv); | ||
622 | t = ti[1]; | ||
623 | l2n(t, iv); | ||
624 | iv = (unsigned char *)ivec; | ||
625 | } | ||
626 | cc= *(in++); | ||
627 | c = iv[n]; | ||
628 | iv[n] = cc; | ||
629 | *(out++) = c^cc; | ||
630 | n = (n + 1)&0x07; | ||
631 | } | ||
632 | } | ||
633 | v0 = v1 = ti[0] = ti[1] = t=c = cc = 0; | ||
634 | *num = n; | ||
635 | } | ||
636 | |||
637 | void | ||
638 | BF_ecb_encrypt(const unsigned char *in, unsigned char *out, | ||
639 | const BF_KEY *key, int encrypt) | ||
640 | { | ||
641 | BF_LONG l, d[2]; | ||
642 | |||
643 | n2l(in, l); | ||
644 | d[0] = l; | ||
645 | n2l(in, l); | ||
646 | d[1] = l; | ||
647 | if (encrypt) | ||
648 | BF_encrypt(d, key); | ||
649 | else | ||
650 | BF_decrypt(d, key); | ||
651 | l = d[0]; | ||
652 | l2n(l, out); | ||
653 | l = d[1]; | ||
654 | l2n(l, out); | ||
655 | l = d[0] = d[1] = 0; | ||
656 | } | ||
657 | |||
658 | /* | ||
659 | * The input and output encrypted as though 64bit ofb mode is being | ||
660 | * used. The extra state information to record how much of the | ||
661 | * 64bit block we have used is contained in *num; | ||
662 | */ | ||
663 | void | ||
664 | BF_ofb64_encrypt(const unsigned char *in, unsigned char *out, long length, | ||
665 | const BF_KEY *schedule, unsigned char *ivec, int *num) | ||
666 | { | ||
667 | BF_LONG v0, v1, t; | ||
668 | int n= *num; | ||
669 | long l = length; | ||
670 | unsigned char d[8]; | ||
671 | char *dp; | ||
672 | BF_LONG ti[2]; | ||
673 | unsigned char *iv; | ||
674 | int save = 0; | ||
675 | |||
676 | iv = (unsigned char *)ivec; | ||
677 | n2l(iv, v0); | ||
678 | n2l(iv, v1); | ||
679 | ti[0] = v0; | ||
680 | ti[1] = v1; | ||
681 | dp = (char *)d; | ||
682 | l2n(v0, dp); | ||
683 | l2n(v1, dp); | ||
684 | while (l--) { | ||
685 | if (n == 0) { | ||
686 | BF_encrypt((BF_LONG *)ti, schedule); | ||
687 | dp = (char *)d; | ||
688 | t = ti[0]; | ||
689 | l2n(t, dp); | ||
690 | t = ti[1]; | ||
691 | l2n(t, dp); | ||
692 | save++; | ||
693 | } | ||
694 | *(out++)= *(in++)^d[n]; | ||
695 | n = (n + 1)&0x07; | ||
696 | } | ||
697 | if (save) { | ||
698 | v0 = ti[0]; | ||
699 | v1 = ti[1]; | ||
700 | iv = (unsigned char *)ivec; | ||
701 | l2n(v0, iv); | ||
702 | l2n(v1, iv); | ||
703 | } | ||
704 | t = v0 = v1 = ti[0] = ti[1] = 0; | ||
705 | *num = n; | ||
706 | } | ||
707 | |||
708 | void | ||
336 | BF_set_key(BF_KEY *key, int len, const unsigned char *data) | 709 | BF_set_key(BF_KEY *key, int len, const unsigned char *data) |
337 | { | 710 | { |
338 | int i; | 711 | int i; |
@@ -385,3 +758,4 @@ BF_set_key(BF_KEY *key, int len, const unsigned char *data) | |||
385 | p[i + 1] = in[1]; | 758 | p[i + 1] = in[1]; |
386 | } | 759 | } |
387 | } | 760 | } |
761 | #endif | ||