diff options
Diffstat (limited to 'src/lib/libcrypto/bf/bf_cbc.c')
-rw-r--r-- | src/lib/libcrypto/bf/bf_cbc.c | 160 |
1 files changed, 77 insertions, 83 deletions
diff --git a/src/lib/libcrypto/bf/bf_cbc.c b/src/lib/libcrypto/bf/bf_cbc.c index 6f45f9ae4c..58e85b63c8 100644 --- a/src/lib/libcrypto/bf/bf_cbc.c +++ b/src/lib/libcrypto/bf/bf_cbc.c | |||
@@ -1,25 +1,25 @@ | |||
1 | /* $OpenBSD: bf_cbc.c,v 1.5 2014/10/28 07:35:58 jsg Exp $ */ | 1 | /* $OpenBSD: bf_cbc.c,v 1.6 2022/11/11 12:08:29 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 | * |
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 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 | 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 | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 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. | 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 | 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. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 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: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 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 | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 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 | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -59,85 +59,79 @@ | |||
59 | #include <openssl/blowfish.h> | 59 | #include <openssl/blowfish.h> |
60 | #include "bf_locl.h" | 60 | #include "bf_locl.h" |
61 | 61 | ||
62 | void BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, | 62 | void |
63 | const BF_KEY *schedule, unsigned char *ivec, int encrypt) | 63 | BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, |
64 | { | 64 | const BF_KEY *schedule, unsigned char *ivec, int encrypt) |
65 | BF_LONG tin0,tin1; | 65 | { |
66 | BF_LONG tout0,tout1,xor0,xor1; | 66 | BF_LONG tin0, tin1; |
67 | long l=length; | 67 | BF_LONG tout0, tout1, xor0, xor1; |
68 | long l = length; | ||
68 | BF_LONG tin[2]; | 69 | BF_LONG tin[2]; |
69 | 70 | ||
70 | if (encrypt) | 71 | if (encrypt) { |
71 | { | 72 | n2l(ivec, tout0); |
72 | n2l(ivec,tout0); | 73 | n2l(ivec, tout1); |
73 | n2l(ivec,tout1); | 74 | ivec -= 8; |
74 | ivec-=8; | 75 | for (l -= 8; l >= 0; l -= 8) { |
75 | for (l-=8; l>=0; l-=8) | 76 | n2l(in, tin0); |
76 | { | 77 | n2l(in, tin1); |
77 | n2l(in,tin0); | 78 | tin0 ^= tout0; |
78 | n2l(in,tin1); | 79 | tin1 ^= tout1; |
79 | tin0^=tout0; | 80 | tin[0] = tin0; |
80 | tin1^=tout1; | 81 | tin[1] = tin1; |
81 | tin[0]=tin0; | 82 | BF_encrypt(tin, schedule); |
82 | tin[1]=tin1; | 83 | tout0 = tin[0]; |
83 | BF_encrypt(tin,schedule); | 84 | tout1 = tin[1]; |
84 | tout0=tin[0]; | 85 | l2n(tout0, out); |
85 | tout1=tin[1]; | 86 | l2n(tout1, out); |
86 | l2n(tout0,out); | 87 | } |
87 | l2n(tout1,out); | 88 | if (l != -8) { |
88 | } | 89 | n2ln(in, tin0, tin1, l + 8); |
89 | if (l != -8) | 90 | tin0 ^= tout0; |
90 | { | 91 | tin1 ^= tout1; |
91 | n2ln(in,tin0,tin1,l+8); | 92 | tin[0] = tin0; |
92 | tin0^=tout0; | 93 | tin[1] = tin1; |
93 | tin1^=tout1; | 94 | BF_encrypt(tin, schedule); |
94 | tin[0]=tin0; | 95 | tout0 = tin[0]; |
95 | tin[1]=tin1; | 96 | tout1 = tin[1]; |
96 | BF_encrypt(tin,schedule); | 97 | l2n(tout0, out); |
97 | tout0=tin[0]; | 98 | l2n(tout1, out); |
98 | tout1=tin[1]; | 99 | } |
99 | l2n(tout0,out); | 100 | l2n(tout0, ivec); |
100 | l2n(tout1,out); | 101 | l2n(tout1, ivec); |
101 | } | 102 | } else { |
102 | l2n(tout0,ivec); | 103 | n2l(ivec, xor0); |
103 | l2n(tout1,ivec); | 104 | n2l(ivec, xor1); |
105 | ivec -= 8; | ||
106 | for (l -= 8; l >= 0; l -= 8) { | ||
107 | n2l(in, tin0); | ||
108 | n2l(in, tin1); | ||
109 | tin[0] = tin0; | ||
110 | tin[1] = tin1; | ||
111 | BF_decrypt(tin, schedule); | ||
112 | tout0 = tin[0]^xor0; | ||
113 | tout1 = tin[1]^xor1; | ||
114 | l2n(tout0, out); | ||
115 | l2n(tout1, out); | ||
116 | xor0 = tin0; | ||
117 | xor1 = tin1; | ||
104 | } | 118 | } |
105 | else | 119 | if (l != -8) { |
106 | { | 120 | n2l(in, tin0); |
107 | n2l(ivec,xor0); | 121 | n2l(in, tin1); |
108 | n2l(ivec,xor1); | 122 | tin[0] = tin0; |
109 | ivec-=8; | 123 | tin[1] = tin1; |
110 | for (l-=8; l>=0; l-=8) | 124 | BF_decrypt(tin, schedule); |
111 | { | 125 | tout0 = tin[0]^xor0; |
112 | n2l(in,tin0); | 126 | tout1 = tin[1]^xor1; |
113 | n2l(in,tin1); | 127 | l2nn(tout0, tout1, out, l + 8); |
114 | tin[0]=tin0; | 128 | xor0 = tin0; |
115 | tin[1]=tin1; | 129 | xor1 = tin1; |
116 | BF_decrypt(tin,schedule); | ||
117 | tout0=tin[0]^xor0; | ||
118 | tout1=tin[1]^xor1; | ||
119 | l2n(tout0,out); | ||
120 | l2n(tout1,out); | ||
121 | xor0=tin0; | ||
122 | xor1=tin1; | ||
123 | } | ||
124 | if (l != -8) | ||
125 | { | ||
126 | n2l(in,tin0); | ||
127 | n2l(in,tin1); | ||
128 | tin[0]=tin0; | ||
129 | tin[1]=tin1; | ||
130 | BF_decrypt(tin,schedule); | ||
131 | tout0=tin[0]^xor0; | ||
132 | tout1=tin[1]^xor1; | ||
133 | l2nn(tout0,tout1,out,l+8); | ||
134 | xor0=tin0; | ||
135 | xor1=tin1; | ||
136 | } | ||
137 | l2n(xor0,ivec); | ||
138 | l2n(xor1,ivec); | ||
139 | } | 130 | } |
140 | tin0=tin1=tout0=tout1=xor0=xor1=0; | 131 | l2n(xor0, ivec); |
141 | tin[0]=tin[1]=0; | 132 | l2n(xor1, ivec); |
142 | } | 133 | } |
134 | tin0 = tin1 = tout0 = tout1 = xor0 = xor1 = 0; | ||
135 | tin[0] = tin[1] = 0; | ||
136 | } | ||
143 | 137 | ||