diff options
Diffstat (limited to 'src/lib/libcrypto/bf/bf_enc.c')
-rw-r--r-- | src/lib/libcrypto/bf/bf_enc.c | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/src/lib/libcrypto/bf/bf_enc.c b/src/lib/libcrypto/bf/bf_enc.c index ee01834561..b380acf959 100644 --- a/src/lib/libcrypto/bf/bf_enc.c +++ b/src/lib/libcrypto/bf/bf_enc.c | |||
@@ -60,7 +60,7 @@ | |||
60 | #include "bf_locl.h" | 60 | #include "bf_locl.h" |
61 | 61 | ||
62 | /* Blowfish as implemented from 'Blowfish: Springer-Verlag paper' | 62 | /* Blowfish as implemented from 'Blowfish: Springer-Verlag paper' |
63 | * (From LECTURE NOTES IN COIMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION, | 63 | * (From LECTURE NOTES IN COMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION, |
64 | * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993) | 64 | * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993) |
65 | */ | 65 | */ |
66 | 66 | ||
@@ -69,10 +69,11 @@ | |||
69 | to modify the code. | 69 | to modify the code. |
70 | #endif | 70 | #endif |
71 | 71 | ||
72 | void BF_encrypt(BF_LONG *data, BF_KEY *key) | 72 | void BF_encrypt(BF_LONG *data, const BF_KEY *key) |
73 | { | 73 | { |
74 | #ifndef BF_PTR2 | 74 | #ifndef BF_PTR2 |
75 | register BF_LONG l,r,*p,*s; | 75 | register BF_LONG l,r; |
76 | const register BF_LONG *p,*s; | ||
76 | 77 | ||
77 | p=key->P; | 78 | p=key->P; |
78 | s= &(key->S[0]); | 79 | s= &(key->S[0]); |
@@ -145,10 +146,11 @@ void BF_encrypt(BF_LONG *data, BF_KEY *key) | |||
145 | 146 | ||
146 | #ifndef BF_DEFAULT_OPTIONS | 147 | #ifndef BF_DEFAULT_OPTIONS |
147 | 148 | ||
148 | void BF_decrypt(BF_LONG *data, BF_KEY *key) | 149 | void BF_decrypt(BF_LONG *data, const BF_KEY *key) |
149 | { | 150 | { |
150 | #ifndef BF_PTR2 | 151 | #ifndef BF_PTR2 |
151 | register BF_LONG l,r,*p,*s; | 152 | register BF_LONG l,r; |
153 | const register BF_LONG *p,*s; | ||
152 | 154 | ||
153 | p=key->P; | 155 | p=key->P; |
154 | s= &(key->S[0]); | 156 | s= &(key->S[0]); |
@@ -219,8 +221,8 @@ void BF_decrypt(BF_LONG *data, BF_KEY *key) | |||
219 | #endif | 221 | #endif |
220 | } | 222 | } |
221 | 223 | ||
222 | void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length, | 224 | void BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, |
223 | BF_KEY *ks, unsigned char *iv, int encrypt) | 225 | const BF_KEY *schedule, unsigned char *ivec, int encrypt) |
224 | { | 226 | { |
225 | register BF_LONG tin0,tin1; | 227 | register BF_LONG tin0,tin1; |
226 | register BF_LONG tout0,tout1,xor0,xor1; | 228 | register BF_LONG tout0,tout1,xor0,xor1; |
@@ -229,9 +231,9 @@ void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length, | |||
229 | 231 | ||
230 | if (encrypt) | 232 | if (encrypt) |
231 | { | 233 | { |
232 | n2l(iv,tout0); | 234 | n2l(ivec,tout0); |
233 | n2l(iv,tout1); | 235 | n2l(ivec,tout1); |
234 | iv-=8; | 236 | ivec-=8; |
235 | for (l-=8; l>=0; l-=8) | 237 | for (l-=8; l>=0; l-=8) |
236 | { | 238 | { |
237 | n2l(in,tin0); | 239 | n2l(in,tin0); |
@@ -240,7 +242,7 @@ void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length, | |||
240 | tin1^=tout1; | 242 | tin1^=tout1; |
241 | tin[0]=tin0; | 243 | tin[0]=tin0; |
242 | tin[1]=tin1; | 244 | tin[1]=tin1; |
243 | BF_encrypt(tin,ks); | 245 | BF_encrypt(tin,schedule); |
244 | tout0=tin[0]; | 246 | tout0=tin[0]; |
245 | tout1=tin[1]; | 247 | tout1=tin[1]; |
246 | l2n(tout0,out); | 248 | l2n(tout0,out); |
@@ -253,27 +255,27 @@ void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length, | |||
253 | tin1^=tout1; | 255 | tin1^=tout1; |
254 | tin[0]=tin0; | 256 | tin[0]=tin0; |
255 | tin[1]=tin1; | 257 | tin[1]=tin1; |
256 | BF_encrypt(tin,ks); | 258 | BF_encrypt(tin,schedule); |
257 | tout0=tin[0]; | 259 | tout0=tin[0]; |
258 | tout1=tin[1]; | 260 | tout1=tin[1]; |
259 | l2n(tout0,out); | 261 | l2n(tout0,out); |
260 | l2n(tout1,out); | 262 | l2n(tout1,out); |
261 | } | 263 | } |
262 | l2n(tout0,iv); | 264 | l2n(tout0,ivec); |
263 | l2n(tout1,iv); | 265 | l2n(tout1,ivec); |
264 | } | 266 | } |
265 | else | 267 | else |
266 | { | 268 | { |
267 | n2l(iv,xor0); | 269 | n2l(ivec,xor0); |
268 | n2l(iv,xor1); | 270 | n2l(ivec,xor1); |
269 | iv-=8; | 271 | ivec-=8; |
270 | for (l-=8; l>=0; l-=8) | 272 | for (l-=8; l>=0; l-=8) |
271 | { | 273 | { |
272 | n2l(in,tin0); | 274 | n2l(in,tin0); |
273 | n2l(in,tin1); | 275 | n2l(in,tin1); |
274 | tin[0]=tin0; | 276 | tin[0]=tin0; |
275 | tin[1]=tin1; | 277 | tin[1]=tin1; |
276 | BF_decrypt(tin,ks); | 278 | BF_decrypt(tin,schedule); |
277 | tout0=tin[0]^xor0; | 279 | tout0=tin[0]^xor0; |
278 | tout1=tin[1]^xor1; | 280 | tout1=tin[1]^xor1; |
279 | l2n(tout0,out); | 281 | l2n(tout0,out); |
@@ -287,15 +289,15 @@ void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length, | |||
287 | n2l(in,tin1); | 289 | n2l(in,tin1); |
288 | tin[0]=tin0; | 290 | tin[0]=tin0; |
289 | tin[1]=tin1; | 291 | tin[1]=tin1; |
290 | BF_decrypt(tin,ks); | 292 | BF_decrypt(tin,schedule); |
291 | tout0=tin[0]^xor0; | 293 | tout0=tin[0]^xor0; |
292 | tout1=tin[1]^xor1; | 294 | tout1=tin[1]^xor1; |
293 | l2nn(tout0,tout1,out,l+8); | 295 | l2nn(tout0,tout1,out,l+8); |
294 | xor0=tin0; | 296 | xor0=tin0; |
295 | xor1=tin1; | 297 | xor1=tin1; |
296 | } | 298 | } |
297 | l2n(xor0,iv); | 299 | l2n(xor0,ivec); |
298 | l2n(xor1,iv); | 300 | l2n(xor1,ivec); |
299 | } | 301 | } |
300 | tin0=tin1=tout0=tout1=xor0=xor1=0; | 302 | tin0=tin1=tout0=tout1=xor0=xor1=0; |
301 | tin[0]=tin[1]=0; | 303 | tin[0]=tin[1]=0; |