File: | out/../deps/openssl/openssl/crypto/bf/bf_enc.c |
Warning: | line 179, column 42 Although the value stored to 'xor1' is used in the enclosing expression, the value is never actually read from 'xor1' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* |
2 | * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. |
3 | * |
4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
5 | * this file except in compliance with the License. You can obtain a copy |
6 | * in the file LICENSE in the source distribution or at |
7 | * https://www.openssl.org/source/license.html |
8 | */ |
9 | |
10 | /* |
11 | * BF low level APIs are deprecated for public use, but still ok for internal |
12 | * use. |
13 | */ |
14 | #include "internal/deprecated.h" |
15 | |
16 | #include <openssl/blowfish.h> |
17 | #include "bf_local.h" |
18 | |
19 | /* |
20 | * Blowfish as implemented from 'Blowfish: Springer-Verlag paper' (From |
21 | * LECTURE NOTES IN COMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION, CAMBRIDGE |
22 | * SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993) |
23 | */ |
24 | |
25 | #if (BF_ROUNDS16 != 16) && (BF_ROUNDS16 != 20) |
26 | # error If you set BF_ROUNDS16 to some value other than 16 or 20, you will have \ |
27 | to modify the code. |
28 | #endif |
29 | |
30 | void BF_encrypt(BF_LONGunsigned int *data, const BF_KEY *key) |
31 | { |
32 | register BF_LONGunsigned int l, r; |
33 | register const BF_LONGunsigned int *p, *s; |
34 | |
35 | p = key->P; |
36 | s = &(key->S[0]); |
37 | l = data[0]; |
38 | r = data[1]; |
39 | |
40 | l ^= p[0]; |
41 | BF_ENC(r, l, s, p[1])( r^=p[1], r^=((( s[ ((l>>24)&0xff)] + s[0x0100+((l >>16)&0xff)])^ s[0x0200+((l>> 8)&0xff)])+ s[0x0300+((l )&0xff)])&0xffffffffU ); |
42 | BF_ENC(l, r, s, p[2])( l^=p[2], l^=((( s[ ((r>>24)&0xff)] + s[0x0100+((r >>16)&0xff)])^ s[0x0200+((r>> 8)&0xff)])+ s[0x0300+((r )&0xff)])&0xffffffffU ); |
43 | BF_ENC(r, l, s, p[3])( r^=p[3], r^=((( s[ ((l>>24)&0xff)] + s[0x0100+((l >>16)&0xff)])^ s[0x0200+((l>> 8)&0xff)])+ s[0x0300+((l )&0xff)])&0xffffffffU ); |
44 | BF_ENC(l, r, s, p[4])( l^=p[4], l^=((( s[ ((r>>24)&0xff)] + s[0x0100+((r >>16)&0xff)])^ s[0x0200+((r>> 8)&0xff)])+ s[0x0300+((r )&0xff)])&0xffffffffU ); |
45 | BF_ENC(r, l, s, p[5])( r^=p[5], r^=((( s[ ((l>>24)&0xff)] + s[0x0100+((l >>16)&0xff)])^ s[0x0200+((l>> 8)&0xff)])+ s[0x0300+((l )&0xff)])&0xffffffffU ); |
46 | BF_ENC(l, r, s, p[6])( l^=p[6], l^=((( s[ ((r>>24)&0xff)] + s[0x0100+((r >>16)&0xff)])^ s[0x0200+((r>> 8)&0xff)])+ s[0x0300+((r )&0xff)])&0xffffffffU ); |
47 | BF_ENC(r, l, s, p[7])( r^=p[7], r^=((( s[ ((l>>24)&0xff)] + s[0x0100+((l >>16)&0xff)])^ s[0x0200+((l>> 8)&0xff)])+ s[0x0300+((l )&0xff)])&0xffffffffU ); |
48 | BF_ENC(l, r, s, p[8])( l^=p[8], l^=((( s[ ((r>>24)&0xff)] + s[0x0100+((r >>16)&0xff)])^ s[0x0200+((r>> 8)&0xff)])+ s[0x0300+((r )&0xff)])&0xffffffffU ); |
49 | BF_ENC(r, l, s, p[9])( r^=p[9], r^=((( s[ ((l>>24)&0xff)] + s[0x0100+((l >>16)&0xff)])^ s[0x0200+((l>> 8)&0xff)])+ s[0x0300+((l )&0xff)])&0xffffffffU ); |
50 | BF_ENC(l, r, s, p[10])( l^=p[10], l^=((( s[ ((r>>24)&0xff)] + s[0x0100+(( r>>16)&0xff)])^ s[0x0200+((r>> 8)&0xff)]) + s[0x0300+((r )&0xff)])&0xffffffffU ); |
51 | BF_ENC(r, l, s, p[11])( r^=p[11], r^=((( s[ ((l>>24)&0xff)] + s[0x0100+(( l>>16)&0xff)])^ s[0x0200+((l>> 8)&0xff)]) + s[0x0300+((l )&0xff)])&0xffffffffU ); |
52 | BF_ENC(l, r, s, p[12])( l^=p[12], l^=((( s[ ((r>>24)&0xff)] + s[0x0100+(( r>>16)&0xff)])^ s[0x0200+((r>> 8)&0xff)]) + s[0x0300+((r )&0xff)])&0xffffffffU ); |
53 | BF_ENC(r, l, s, p[13])( r^=p[13], r^=((( s[ ((l>>24)&0xff)] + s[0x0100+(( l>>16)&0xff)])^ s[0x0200+((l>> 8)&0xff)]) + s[0x0300+((l )&0xff)])&0xffffffffU ); |
54 | BF_ENC(l, r, s, p[14])( l^=p[14], l^=((( s[ ((r>>24)&0xff)] + s[0x0100+(( r>>16)&0xff)])^ s[0x0200+((r>> 8)&0xff)]) + s[0x0300+((r )&0xff)])&0xffffffffU ); |
55 | BF_ENC(r, l, s, p[15])( r^=p[15], r^=((( s[ ((l>>24)&0xff)] + s[0x0100+(( l>>16)&0xff)])^ s[0x0200+((l>> 8)&0xff)]) + s[0x0300+((l )&0xff)])&0xffffffffU ); |
56 | BF_ENC(l, r, s, p[16])( l^=p[16], l^=((( s[ ((r>>24)&0xff)] + s[0x0100+(( r>>16)&0xff)])^ s[0x0200+((r>> 8)&0xff)]) + s[0x0300+((r )&0xff)])&0xffffffffU ); |
57 | # if BF_ROUNDS16 == 20 |
58 | BF_ENC(r, l, s, p[17])( r^=p[17], r^=((( s[ ((l>>24)&0xff)] + s[0x0100+(( l>>16)&0xff)])^ s[0x0200+((l>> 8)&0xff)]) + s[0x0300+((l )&0xff)])&0xffffffffU ); |
59 | BF_ENC(l, r, s, p[18])( l^=p[18], l^=((( s[ ((r>>24)&0xff)] + s[0x0100+(( r>>16)&0xff)])^ s[0x0200+((r>> 8)&0xff)]) + s[0x0300+((r )&0xff)])&0xffffffffU ); |
60 | BF_ENC(r, l, s, p[19])( r^=p[19], r^=((( s[ ((l>>24)&0xff)] + s[0x0100+(( l>>16)&0xff)])^ s[0x0200+((l>> 8)&0xff)]) + s[0x0300+((l )&0xff)])&0xffffffffU ); |
61 | BF_ENC(l, r, s, p[20])( l^=p[20], l^=((( s[ ((r>>24)&0xff)] + s[0x0100+(( r>>16)&0xff)])^ s[0x0200+((r>> 8)&0xff)]) + s[0x0300+((r )&0xff)])&0xffffffffU ); |
62 | # endif |
63 | r ^= p[BF_ROUNDS16 + 1]; |
64 | |
65 | data[1] = l & 0xffffffffU; |
66 | data[0] = r & 0xffffffffU; |
67 | } |
68 | |
69 | void BF_decrypt(BF_LONGunsigned int *data, const BF_KEY *key) |
70 | { |
71 | register BF_LONGunsigned int l, r; |
72 | register const BF_LONGunsigned int *p, *s; |
73 | |
74 | p = key->P; |
75 | s = &(key->S[0]); |
76 | l = data[0]; |
77 | r = data[1]; |
78 | |
79 | l ^= p[BF_ROUNDS16 + 1]; |
80 | # if BF_ROUNDS16 == 20 |
81 | BF_ENC(r, l, s, p[20])( r^=p[20], r^=((( s[ ((l>>24)&0xff)] + s[0x0100+(( l>>16)&0xff)])^ s[0x0200+((l>> 8)&0xff)]) + s[0x0300+((l )&0xff)])&0xffffffffU ); |
82 | BF_ENC(l, r, s, p[19])( l^=p[19], l^=((( s[ ((r>>24)&0xff)] + s[0x0100+(( r>>16)&0xff)])^ s[0x0200+((r>> 8)&0xff)]) + s[0x0300+((r )&0xff)])&0xffffffffU ); |
83 | BF_ENC(r, l, s, p[18])( r^=p[18], r^=((( s[ ((l>>24)&0xff)] + s[0x0100+(( l>>16)&0xff)])^ s[0x0200+((l>> 8)&0xff)]) + s[0x0300+((l )&0xff)])&0xffffffffU ); |
84 | BF_ENC(l, r, s, p[17])( l^=p[17], l^=((( s[ ((r>>24)&0xff)] + s[0x0100+(( r>>16)&0xff)])^ s[0x0200+((r>> 8)&0xff)]) + s[0x0300+((r )&0xff)])&0xffffffffU ); |
85 | # endif |
86 | BF_ENC(r, l, s, p[16])( r^=p[16], r^=((( s[ ((l>>24)&0xff)] + s[0x0100+(( l>>16)&0xff)])^ s[0x0200+((l>> 8)&0xff)]) + s[0x0300+((l )&0xff)])&0xffffffffU ); |
87 | BF_ENC(l, r, s, p[15])( l^=p[15], l^=((( s[ ((r>>24)&0xff)] + s[0x0100+(( r>>16)&0xff)])^ s[0x0200+((r>> 8)&0xff)]) + s[0x0300+((r )&0xff)])&0xffffffffU ); |
88 | BF_ENC(r, l, s, p[14])( r^=p[14], r^=((( s[ ((l>>24)&0xff)] + s[0x0100+(( l>>16)&0xff)])^ s[0x0200+((l>> 8)&0xff)]) + s[0x0300+((l )&0xff)])&0xffffffffU ); |
89 | BF_ENC(l, r, s, p[13])( l^=p[13], l^=((( s[ ((r>>24)&0xff)] + s[0x0100+(( r>>16)&0xff)])^ s[0x0200+((r>> 8)&0xff)]) + s[0x0300+((r )&0xff)])&0xffffffffU ); |
90 | BF_ENC(r, l, s, p[12])( r^=p[12], r^=((( s[ ((l>>24)&0xff)] + s[0x0100+(( l>>16)&0xff)])^ s[0x0200+((l>> 8)&0xff)]) + s[0x0300+((l )&0xff)])&0xffffffffU ); |
91 | BF_ENC(l, r, s, p[11])( l^=p[11], l^=((( s[ ((r>>24)&0xff)] + s[0x0100+(( r>>16)&0xff)])^ s[0x0200+((r>> 8)&0xff)]) + s[0x0300+((r )&0xff)])&0xffffffffU ); |
92 | BF_ENC(r, l, s, p[10])( r^=p[10], r^=((( s[ ((l>>24)&0xff)] + s[0x0100+(( l>>16)&0xff)])^ s[0x0200+((l>> 8)&0xff)]) + s[0x0300+((l )&0xff)])&0xffffffffU ); |
93 | BF_ENC(l, r, s, p[9])( l^=p[9], l^=((( s[ ((r>>24)&0xff)] + s[0x0100+((r >>16)&0xff)])^ s[0x0200+((r>> 8)&0xff)])+ s[0x0300+((r )&0xff)])&0xffffffffU ); |
94 | BF_ENC(r, l, s, p[8])( r^=p[8], r^=((( s[ ((l>>24)&0xff)] + s[0x0100+((l >>16)&0xff)])^ s[0x0200+((l>> 8)&0xff)])+ s[0x0300+((l )&0xff)])&0xffffffffU ); |
95 | BF_ENC(l, r, s, p[7])( l^=p[7], l^=((( s[ ((r>>24)&0xff)] + s[0x0100+((r >>16)&0xff)])^ s[0x0200+((r>> 8)&0xff)])+ s[0x0300+((r )&0xff)])&0xffffffffU ); |
96 | BF_ENC(r, l, s, p[6])( r^=p[6], r^=((( s[ ((l>>24)&0xff)] + s[0x0100+((l >>16)&0xff)])^ s[0x0200+((l>> 8)&0xff)])+ s[0x0300+((l )&0xff)])&0xffffffffU ); |
97 | BF_ENC(l, r, s, p[5])( l^=p[5], l^=((( s[ ((r>>24)&0xff)] + s[0x0100+((r >>16)&0xff)])^ s[0x0200+((r>> 8)&0xff)])+ s[0x0300+((r )&0xff)])&0xffffffffU ); |
98 | BF_ENC(r, l, s, p[4])( r^=p[4], r^=((( s[ ((l>>24)&0xff)] + s[0x0100+((l >>16)&0xff)])^ s[0x0200+((l>> 8)&0xff)])+ s[0x0300+((l )&0xff)])&0xffffffffU ); |
99 | BF_ENC(l, r, s, p[3])( l^=p[3], l^=((( s[ ((r>>24)&0xff)] + s[0x0100+((r >>16)&0xff)])^ s[0x0200+((r>> 8)&0xff)])+ s[0x0300+((r )&0xff)])&0xffffffffU ); |
100 | BF_ENC(r, l, s, p[2])( r^=p[2], r^=((( s[ ((l>>24)&0xff)] + s[0x0100+((l >>16)&0xff)])^ s[0x0200+((l>> 8)&0xff)])+ s[0x0300+((l )&0xff)])&0xffffffffU ); |
101 | BF_ENC(l, r, s, p[1])( l^=p[1], l^=((( s[ ((r>>24)&0xff)] + s[0x0100+((r >>16)&0xff)])^ s[0x0200+((r>> 8)&0xff)])+ s[0x0300+((r )&0xff)])&0xffffffffU ); |
102 | r ^= p[0]; |
103 | |
104 | data[1] = l & 0xffffffffU; |
105 | data[0] = r & 0xffffffffU; |
106 | } |
107 | |
108 | void BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, |
109 | const BF_KEY *schedule, unsigned char *ivec, int encrypt) |
110 | { |
111 | register BF_LONGunsigned int tin0, tin1; |
112 | register BF_LONGunsigned int tout0, tout1, xor0, xor1; |
113 | register long l = length; |
114 | BF_LONGunsigned int tin[2]; |
115 | |
116 | if (encrypt) { |
117 | n2l(ivec, tout0)(tout0 =((unsigned long)(*((ivec)++)))<<24L, tout0|=((unsigned long)(*((ivec)++)))<<16L, tout0|=((unsigned long)(*((ivec )++)))<< 8L, tout0|=((unsigned long)(*((ivec)++)))); |
118 | n2l(ivec, tout1)(tout1 =((unsigned long)(*((ivec)++)))<<24L, tout1|=((unsigned long)(*((ivec)++)))<<16L, tout1|=((unsigned long)(*((ivec )++)))<< 8L, tout1|=((unsigned long)(*((ivec)++)))); |
119 | ivec -= 8; |
120 | for (l -= 8; l >= 0; l -= 8) { |
121 | n2l(in, tin0)(tin0 =((unsigned long)(*((in)++)))<<24L, tin0|=((unsigned long)(*((in)++)))<<16L, tin0|=((unsigned long)(*((in)++ )))<< 8L, tin0|=((unsigned long)(*((in)++)))); |
122 | n2l(in, tin1)(tin1 =((unsigned long)(*((in)++)))<<24L, tin1|=((unsigned long)(*((in)++)))<<16L, tin1|=((unsigned long)(*((in)++ )))<< 8L, tin1|=((unsigned long)(*((in)++)))); |
123 | tin0 ^= tout0; |
124 | tin1 ^= tout1; |
125 | tin[0] = tin0; |
126 | tin[1] = tin1; |
127 | BF_encrypt(tin, schedule); |
128 | tout0 = tin[0]; |
129 | tout1 = tin[1]; |
130 | l2n(tout0, out)(*((out)++)=(unsigned char)(((tout0)>>24L)&0xff), * ((out)++)=(unsigned char)(((tout0)>>16L)&0xff), *(( out)++)=(unsigned char)(((tout0)>> 8L)&0xff), *((out )++)=(unsigned char)(((tout0) )&0xff)); |
131 | l2n(tout1, out)(*((out)++)=(unsigned char)(((tout1)>>24L)&0xff), * ((out)++)=(unsigned char)(((tout1)>>16L)&0xff), *(( out)++)=(unsigned char)(((tout1)>> 8L)&0xff), *((out )++)=(unsigned char)(((tout1) )&0xff)); |
132 | } |
133 | if (l != -8) { |
134 | n2ln(in, tin0, tin1, l + 8){ in+=l + 8; tin0=tin1=0; switch (l + 8) { case 8: tin1 =((unsigned long)(*(--(in)))) ; case 7: tin1|=((unsigned long)(*(--(in)) ))<< 8; case 6: tin1|=((unsigned long)(*(--(in))))<< 16; case 5: tin1|=((unsigned long)(*(--(in))))<<24; case 4: tin0 =((unsigned long)(*(--(in)))) ; case 3: tin0|=((unsigned long)(*(--(in))))<< 8; case 2: tin0|=((unsigned long)( *(--(in))))<<16; case 1: tin0|=((unsigned long)(*(--(in ))))<<24; } }; |
135 | tin0 ^= tout0; |
136 | tin1 ^= tout1; |
137 | tin[0] = tin0; |
138 | tin[1] = tin1; |
139 | BF_encrypt(tin, schedule); |
140 | tout0 = tin[0]; |
141 | tout1 = tin[1]; |
142 | l2n(tout0, out)(*((out)++)=(unsigned char)(((tout0)>>24L)&0xff), * ((out)++)=(unsigned char)(((tout0)>>16L)&0xff), *(( out)++)=(unsigned char)(((tout0)>> 8L)&0xff), *((out )++)=(unsigned char)(((tout0) )&0xff)); |
143 | l2n(tout1, out)(*((out)++)=(unsigned char)(((tout1)>>24L)&0xff), * ((out)++)=(unsigned char)(((tout1)>>16L)&0xff), *(( out)++)=(unsigned char)(((tout1)>> 8L)&0xff), *((out )++)=(unsigned char)(((tout1) )&0xff)); |
144 | } |
145 | l2n(tout0, ivec)(*((ivec)++)=(unsigned char)(((tout0)>>24L)&0xff), * ((ivec)++)=(unsigned char)(((tout0)>>16L)&0xff), *( (ivec)++)=(unsigned char)(((tout0)>> 8L)&0xff), *(( ivec)++)=(unsigned char)(((tout0) )&0xff)); |
146 | l2n(tout1, ivec)(*((ivec)++)=(unsigned char)(((tout1)>>24L)&0xff), * ((ivec)++)=(unsigned char)(((tout1)>>16L)&0xff), *( (ivec)++)=(unsigned char)(((tout1)>> 8L)&0xff), *(( ivec)++)=(unsigned char)(((tout1) )&0xff)); |
147 | } else { |
148 | n2l(ivec, xor0)(xor0 =((unsigned long)(*((ivec)++)))<<24L, xor0|=((unsigned long)(*((ivec)++)))<<16L, xor0|=((unsigned long)(*((ivec )++)))<< 8L, xor0|=((unsigned long)(*((ivec)++)))); |
149 | n2l(ivec, xor1)(xor1 =((unsigned long)(*((ivec)++)))<<24L, xor1|=((unsigned long)(*((ivec)++)))<<16L, xor1|=((unsigned long)(*((ivec )++)))<< 8L, xor1|=((unsigned long)(*((ivec)++)))); |
150 | ivec -= 8; |
151 | for (l -= 8; l >= 0; l -= 8) { |
152 | n2l(in, tin0)(tin0 =((unsigned long)(*((in)++)))<<24L, tin0|=((unsigned long)(*((in)++)))<<16L, tin0|=((unsigned long)(*((in)++ )))<< 8L, tin0|=((unsigned long)(*((in)++)))); |
153 | n2l(in, tin1)(tin1 =((unsigned long)(*((in)++)))<<24L, tin1|=((unsigned long)(*((in)++)))<<16L, tin1|=((unsigned long)(*((in)++ )))<< 8L, tin1|=((unsigned long)(*((in)++)))); |
154 | tin[0] = tin0; |
155 | tin[1] = tin1; |
156 | BF_decrypt(tin, schedule); |
157 | tout0 = tin[0] ^ xor0; |
158 | tout1 = tin[1] ^ xor1; |
159 | l2n(tout0, out)(*((out)++)=(unsigned char)(((tout0)>>24L)&0xff), * ((out)++)=(unsigned char)(((tout0)>>16L)&0xff), *(( out)++)=(unsigned char)(((tout0)>> 8L)&0xff), *((out )++)=(unsigned char)(((tout0) )&0xff)); |
160 | l2n(tout1, out)(*((out)++)=(unsigned char)(((tout1)>>24L)&0xff), * ((out)++)=(unsigned char)(((tout1)>>16L)&0xff), *(( out)++)=(unsigned char)(((tout1)>> 8L)&0xff), *((out )++)=(unsigned char)(((tout1) )&0xff)); |
161 | xor0 = tin0; |
162 | xor1 = tin1; |
163 | } |
164 | if (l != -8) { |
165 | n2l(in, tin0)(tin0 =((unsigned long)(*((in)++)))<<24L, tin0|=((unsigned long)(*((in)++)))<<16L, tin0|=((unsigned long)(*((in)++ )))<< 8L, tin0|=((unsigned long)(*((in)++)))); |
166 | n2l(in, tin1)(tin1 =((unsigned long)(*((in)++)))<<24L, tin1|=((unsigned long)(*((in)++)))<<16L, tin1|=((unsigned long)(*((in)++ )))<< 8L, tin1|=((unsigned long)(*((in)++)))); |
167 | tin[0] = tin0; |
168 | tin[1] = tin1; |
169 | BF_decrypt(tin, schedule); |
170 | tout0 = tin[0] ^ xor0; |
171 | tout1 = tin[1] ^ xor1; |
172 | l2nn(tout0, tout1, out, l + 8){ out+=l + 8; switch (l + 8) { case 8: *(--(out))=(unsigned char )(((tout1) )&0xff); case 7: *(--(out))=(unsigned char)((( tout1)>> 8)&0xff); case 6: *(--(out))=(unsigned char )(((tout1)>>16)&0xff); case 5: *(--(out))=(unsigned char)(((tout1)>>24)&0xff); case 4: *(--(out))=(unsigned char)(((tout0) )&0xff); case 3: *(--(out))=(unsigned char )(((tout0)>> 8)&0xff); case 2: *(--(out))=(unsigned char)(((tout0)>>16)&0xff); case 1: *(--(out))=(unsigned char)(((tout0)>>24)&0xff); } }; |
173 | xor0 = tin0; |
174 | xor1 = tin1; |
175 | } |
176 | l2n(xor0, ivec)(*((ivec)++)=(unsigned char)(((xor0)>>24L)&0xff), * ((ivec)++)=(unsigned char)(((xor0)>>16L)&0xff), *(( ivec)++)=(unsigned char)(((xor0)>> 8L)&0xff), *((ivec )++)=(unsigned char)(((xor0) )&0xff)); |
177 | l2n(xor1, ivec)(*((ivec)++)=(unsigned char)(((xor1)>>24L)&0xff), * ((ivec)++)=(unsigned char)(((xor1)>>16L)&0xff), *(( ivec)++)=(unsigned char)(((xor1)>> 8L)&0xff), *((ivec )++)=(unsigned char)(((xor1) )&0xff)); |
178 | } |
179 | tin0 = tin1 = tout0 = tout1 = xor0 = xor1 = 0; |
Although the value stored to 'xor1' is used in the enclosing expression, the value is never actually read from 'xor1' | |
180 | tin[0] = tin[1] = 0; |
181 | } |