summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/des/des_enc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/des/des_enc.c')
-rw-r--r--src/lib/libcrypto/des/des_enc.c140
1 files changed, 22 insertions, 118 deletions
diff --git a/src/lib/libcrypto/des/des_enc.c b/src/lib/libcrypto/des/des_enc.c
index e4db09299e..8311e10628 100644
--- a/src/lib/libcrypto/des/des_enc.c
+++ b/src/lib/libcrypto/des/des_enc.c
@@ -58,14 +58,11 @@
58 58
59#include "des_locl.h" 59#include "des_locl.h"
60 60
61void des_encrypt(data, ks, enc) 61void des_encrypt(DES_LONG *data, des_key_schedule ks, int enc)
62DES_LONG *data;
63des_key_schedule ks;
64int enc;
65 { 62 {
66 register DES_LONG l,r,t,u; 63 register DES_LONG l,r,t,u;
67#ifdef DES_PTR 64#ifdef DES_PTR
68 register unsigned char *des_SP=(unsigned char *)des_SPtrans; 65 register const unsigned char *des_SP=(const unsigned char *)des_SPtrans;
69#endif 66#endif
70#ifndef DES_UNROLL 67#ifndef DES_UNROLL
71 register int i; 68 register int i;
@@ -87,7 +84,7 @@ int enc;
87 r=ROTATE(r,29)&0xffffffffL; 84 r=ROTATE(r,29)&0xffffffffL;
88 l=ROTATE(l,29)&0xffffffffL; 85 l=ROTATE(l,29)&0xffffffffL;
89 86
90 s=(DES_LONG *)ks; 87 s=ks->ks.deslong;
91 /* I don't know if it is worth the effort of loop unrolling the 88 /* I don't know if it is worth the effort of loop unrolling the
92 * inner loop */ 89 * inner loop */
93 if (enc) 90 if (enc)
@@ -159,14 +156,11 @@ int enc;
159 l=r=t=u=0; 156 l=r=t=u=0;
160 } 157 }
161 158
162void des_encrypt2(data, ks, enc) 159void des_encrypt2(DES_LONG *data, des_key_schedule ks, int enc)
163DES_LONG *data;
164des_key_schedule ks;
165int enc;
166 { 160 {
167 register DES_LONG l,r,t,u; 161 register DES_LONG l,r,t,u;
168#ifdef DES_PTR 162#ifdef DES_PTR
169 register unsigned char *des_SP=(unsigned char *)des_SPtrans; 163 register const unsigned char *des_SP=(const unsigned char *)des_SPtrans;
170#endif 164#endif
171#ifndef DES_UNROLL 165#ifndef DES_UNROLL
172 register int i; 166 register int i;
@@ -186,7 +180,7 @@ int enc;
186 r=ROTATE(r,29)&0xffffffffL; 180 r=ROTATE(r,29)&0xffffffffL;
187 l=ROTATE(l,29)&0xffffffffL; 181 l=ROTATE(l,29)&0xffffffffL;
188 182
189 s=(DES_LONG *)ks; 183 s=ks->ks.deslong;
190 /* I don't know if it is worth the effort of loop unrolling the 184 /* I don't know if it is worth the effort of loop unrolling the
191 * inner loop */ 185 * inner loop */
192 if (enc) 186 if (enc)
@@ -253,11 +247,8 @@ int enc;
253 l=r=t=u=0; 247 l=r=t=u=0;
254 } 248 }
255 249
256void des_encrypt3(data,ks1,ks2,ks3) 250void des_encrypt3(DES_LONG *data, des_key_schedule ks1, des_key_schedule ks2,
257DES_LONG *data; 251 des_key_schedule ks3)
258des_key_schedule ks1;
259des_key_schedule ks2;
260des_key_schedule ks3;
261 { 252 {
262 register DES_LONG l,r; 253 register DES_LONG l,r;
263 254
@@ -276,11 +267,8 @@ des_key_schedule ks3;
276 data[1]=r; 267 data[1]=r;
277 } 268 }
278 269
279void des_decrypt3(data,ks1,ks2,ks3) 270void des_decrypt3(DES_LONG *data, des_key_schedule ks1, des_key_schedule ks2,
280DES_LONG *data; 271 des_key_schedule ks3)
281des_key_schedule ks1;
282des_key_schedule ks2;
283des_key_schedule ks3;
284 { 272 {
285 register DES_LONG l,r; 273 register DES_LONG l,r;
286 274
@@ -301,108 +289,24 @@ des_key_schedule ks3;
301 289
302#ifndef DES_DEFAULT_OPTIONS 290#ifndef DES_DEFAULT_OPTIONS
303 291
304void des_ncbc_encrypt(input, output, length, schedule, ivec, enc) 292#undef CBC_ENC_C__DONT_UPDATE_IV
305des_cblock (*input); 293#include "ncbc_enc.c" /* des_ncbc_encrypt */
306des_cblock (*output);
307long length;
308des_key_schedule schedule;
309des_cblock (*ivec);
310int enc;
311 {
312 register DES_LONG tin0,tin1;
313 register DES_LONG tout0,tout1,xor0,xor1;
314 register unsigned char *in,*out;
315 register long l=length;
316 DES_LONG tin[2];
317 unsigned char *iv;
318
319 in=(unsigned char *)input;
320 out=(unsigned char *)output;
321 iv=(unsigned char *)ivec;
322
323 if (enc)
324 {
325 c2l(iv,tout0);
326 c2l(iv,tout1);
327 for (l-=8; l>=0; l-=8)
328 {
329 c2l(in,tin0);
330 c2l(in,tin1);
331 tin0^=tout0; tin[0]=tin0;
332 tin1^=tout1; tin[1]=tin1;
333 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
334 tout0=tin[0]; l2c(tout0,out);
335 tout1=tin[1]; l2c(tout1,out);
336 }
337 if (l != -8)
338 {
339 c2ln(in,tin0,tin1,l+8);
340 tin0^=tout0; tin[0]=tin0;
341 tin1^=tout1; tin[1]=tin1;
342 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
343 tout0=tin[0]; l2c(tout0,out);
344 tout1=tin[1]; l2c(tout1,out);
345 }
346 iv=(unsigned char *)ivec;
347 l2c(tout0,iv);
348 l2c(tout1,iv);
349 }
350 else
351 {
352 c2l(iv,xor0);
353 c2l(iv,xor1);
354 for (l-=8; l>=0; l-=8)
355 {
356 c2l(in,tin0); tin[0]=tin0;
357 c2l(in,tin1); tin[1]=tin1;
358 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
359 tout0=tin[0]^xor0;
360 tout1=tin[1]^xor1;
361 l2c(tout0,out);
362 l2c(tout1,out);
363 xor0=tin0;
364 xor1=tin1;
365 }
366 if (l != -8)
367 {
368 c2l(in,tin0); tin[0]=tin0;
369 c2l(in,tin1); tin[1]=tin1;
370 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
371 tout0=tin[0]^xor0;
372 tout1=tin[1]^xor1;
373 l2cn(tout0,tout1,out,l+8);
374 xor0=tin0;
375 xor1=tin1;
376 }
377
378 iv=(unsigned char *)ivec;
379 l2c(xor0,iv);
380 l2c(xor1,iv);
381 }
382 tin0=tin1=tout0=tout1=xor0=xor1=0;
383 tin[0]=tin[1]=0;
384 }
385 294
386void des_ede3_cbc_encrypt(input, output, length, ks1, ks2, ks3, ivec, enc) 295void des_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output,
387des_cblock (*input); 296 long length, des_key_schedule ks1, des_key_schedule ks2,
388des_cblock (*output); 297 des_key_schedule ks3, des_cblock *ivec, int enc)
389long length;
390des_key_schedule ks1;
391des_key_schedule ks2;
392des_key_schedule ks3;
393des_cblock (*ivec);
394int enc;
395 { 298 {
396 register DES_LONG tin0,tin1; 299 register DES_LONG tin0,tin1;
397 register DES_LONG tout0,tout1,xor0,xor1; 300 register DES_LONG tout0,tout1,xor0,xor1;
398 register unsigned char *in,*out; 301 register const unsigned char *in;
302 unsigned char *out;
399 register long l=length; 303 register long l=length;
400 DES_LONG tin[2]; 304 DES_LONG tin[2];
401 unsigned char *iv; 305 unsigned char *iv;
402 306
403 in=(unsigned char *)input; 307 in=input;
404 out=(unsigned char *)output; 308 out=output;
405 iv=(unsigned char *)ivec; 309 iv = &(*ivec)[0];
406 310
407 if (enc) 311 if (enc)
408 { 312 {
@@ -439,7 +343,7 @@ int enc;
439 l2c(tout0,out); 343 l2c(tout0,out);
440 l2c(tout1,out); 344 l2c(tout1,out);
441 } 345 }
442 iv=(unsigned char *)ivec; 346 iv = &(*ivec)[0];
443 l2c(tout0,iv); 347 l2c(tout0,iv);
444 l2c(tout1,iv); 348 l2c(tout1,iv);
445 } 349 }
@@ -491,7 +395,7 @@ int enc;
491 xor1=t1; 395 xor1=t1;
492 } 396 }
493 397
494 iv=(unsigned char *)ivec; 398 iv = &(*ivec)[0];
495 l2c(xor0,iv); 399 l2c(xor0,iv);
496 l2c(xor1,iv); 400 l2c(xor1,iv);
497 } 401 }