Package list libcryptx-perl / 1abbbb1
libtomcrypt update Karel Miko 2 years ago
14 changed file(s) with 209 addition(s) and 219 deletion(s). Raw diff Collapse all Expand all
9090
9191 static ulong32 setup_mix(ulong32 temp)
9292 {
93 return (Te4_3[byte(temp, 2)]) ^
94 (Te4_2[byte(temp, 1)]) ^
95 (Te4_1[byte(temp, 0)]) ^
96 (Te4_0[byte(temp, 3)]);
93 return (Te4_3[LTC_BYTE(temp, 2)]) ^
94 (Te4_2[LTC_BYTE(temp, 1)]) ^
95 (Te4_1[LTC_BYTE(temp, 0)]) ^
96 (Te4_0[LTC_BYTE(temp, 3)]);
9797 }
9898
9999 #ifndef ENCRYPT_ONLY
100100 #ifdef LTC_SMALL_CODE
101101 static ulong32 setup_mix2(ulong32 temp)
102102 {
103 return Td0(255 & Te4[byte(temp, 3)]) ^
104 Td1(255 & Te4[byte(temp, 2)]) ^
105 Td2(255 & Te4[byte(temp, 1)]) ^
106 Td3(255 & Te4[byte(temp, 0)]);
103 return Td0(255 & Te4[LTC_BYTE(temp, 3)]) ^
104 Td1(255 & Te4[LTC_BYTE(temp, 2)]) ^
105 Td2(255 & Te4[LTC_BYTE(temp, 1)]) ^
106 Td3(255 & Te4[LTC_BYTE(temp, 0)]);
107107 }
108108 #endif
109109 #endif
234234 #else
235235 temp = rrk[0];
236236 rk[0] =
237 Tks0[byte(temp, 3)] ^
238 Tks1[byte(temp, 2)] ^
239 Tks2[byte(temp, 1)] ^
240 Tks3[byte(temp, 0)];
237 Tks0[LTC_BYTE(temp, 3)] ^
238 Tks1[LTC_BYTE(temp, 2)] ^
239 Tks2[LTC_BYTE(temp, 1)] ^
240 Tks3[LTC_BYTE(temp, 0)];
241241 temp = rrk[1];
242242 rk[1] =
243 Tks0[byte(temp, 3)] ^
244 Tks1[byte(temp, 2)] ^
245 Tks2[byte(temp, 1)] ^
246 Tks3[byte(temp, 0)];
243 Tks0[LTC_BYTE(temp, 3)] ^
244 Tks1[LTC_BYTE(temp, 2)] ^
245 Tks2[LTC_BYTE(temp, 1)] ^
246 Tks3[LTC_BYTE(temp, 0)];
247247 temp = rrk[2];
248248 rk[2] =
249 Tks0[byte(temp, 3)] ^
250 Tks1[byte(temp, 2)] ^
251 Tks2[byte(temp, 1)] ^
252 Tks3[byte(temp, 0)];
249 Tks0[LTC_BYTE(temp, 3)] ^
250 Tks1[LTC_BYTE(temp, 2)] ^
251 Tks2[LTC_BYTE(temp, 1)] ^
252 Tks3[LTC_BYTE(temp, 0)];
253253 temp = rrk[3];
254254 rk[3] =
255 Tks0[byte(temp, 3)] ^
256 Tks1[byte(temp, 2)] ^
257 Tks2[byte(temp, 1)] ^
258 Tks3[byte(temp, 0)];
255 Tks0[LTC_BYTE(temp, 3)] ^
256 Tks1[LTC_BYTE(temp, 2)] ^
257 Tks2[LTC_BYTE(temp, 1)] ^
258 Tks3[LTC_BYTE(temp, 0)];
259259 #endif
260260
261261 }
310310 for (r = 0; ; r++) {
311311 rk += 4;
312312 t0 =
313 Te0(byte(s0, 3)) ^
314 Te1(byte(s1, 2)) ^
315 Te2(byte(s2, 1)) ^
316 Te3(byte(s3, 0)) ^
313 Te0(LTC_BYTE(s0, 3)) ^
314 Te1(LTC_BYTE(s1, 2)) ^
315 Te2(LTC_BYTE(s2, 1)) ^
316 Te3(LTC_BYTE(s3, 0)) ^
317317 rk[0];
318318 t1 =
319 Te0(byte(s1, 3)) ^
320 Te1(byte(s2, 2)) ^
321 Te2(byte(s3, 1)) ^
322 Te3(byte(s0, 0)) ^
319 Te0(LTC_BYTE(s1, 3)) ^
320 Te1(LTC_BYTE(s2, 2)) ^
321 Te2(LTC_BYTE(s3, 1)) ^
322 Te3(LTC_BYTE(s0, 0)) ^
323323 rk[1];
324324 t2 =
325 Te0(byte(s2, 3)) ^
326 Te1(byte(s3, 2)) ^
327 Te2(byte(s0, 1)) ^
328 Te3(byte(s1, 0)) ^
325 Te0(LTC_BYTE(s2, 3)) ^
326 Te1(LTC_BYTE(s3, 2)) ^
327 Te2(LTC_BYTE(s0, 1)) ^
328 Te3(LTC_BYTE(s1, 0)) ^
329329 rk[2];
330330 t3 =
331 Te0(byte(s3, 3)) ^
332 Te1(byte(s0, 2)) ^
333 Te2(byte(s1, 1)) ^
334 Te3(byte(s2, 0)) ^
331 Te0(LTC_BYTE(s3, 3)) ^
332 Te1(LTC_BYTE(s0, 2)) ^
333 Te2(LTC_BYTE(s1, 1)) ^
334 Te3(LTC_BYTE(s2, 0)) ^
335335 rk[3];
336336 if (r == Nr-2) {
337337 break;
348348 r = Nr >> 1;
349349 for (;;) {
350350 t0 =
351 Te0(byte(s0, 3)) ^
352 Te1(byte(s1, 2)) ^
353 Te2(byte(s2, 1)) ^
354 Te3(byte(s3, 0)) ^
351 Te0(LTC_BYTE(s0, 3)) ^
352 Te1(LTC_BYTE(s1, 2)) ^
353 Te2(LTC_BYTE(s2, 1)) ^
354 Te3(LTC_BYTE(s3, 0)) ^
355355 rk[4];
356356 t1 =
357 Te0(byte(s1, 3)) ^
358 Te1(byte(s2, 2)) ^
359 Te2(byte(s3, 1)) ^
360 Te3(byte(s0, 0)) ^
357 Te0(LTC_BYTE(s1, 3)) ^
358 Te1(LTC_BYTE(s2, 2)) ^
359 Te2(LTC_BYTE(s3, 1)) ^
360 Te3(LTC_BYTE(s0, 0)) ^
361361 rk[5];
362362 t2 =
363 Te0(byte(s2, 3)) ^
364 Te1(byte(s3, 2)) ^
365 Te2(byte(s0, 1)) ^
366 Te3(byte(s1, 0)) ^
363 Te0(LTC_BYTE(s2, 3)) ^
364 Te1(LTC_BYTE(s3, 2)) ^
365 Te2(LTC_BYTE(s0, 1)) ^
366 Te3(LTC_BYTE(s1, 0)) ^
367367 rk[6];
368368 t3 =
369 Te0(byte(s3, 3)) ^
370 Te1(byte(s0, 2)) ^
371 Te2(byte(s1, 1)) ^
372 Te3(byte(s2, 0)) ^
369 Te0(LTC_BYTE(s3, 3)) ^
370 Te1(LTC_BYTE(s0, 2)) ^
371 Te2(LTC_BYTE(s1, 1)) ^
372 Te3(LTC_BYTE(s2, 0)) ^
373373 rk[7];
374374
375375 rk += 8;
378378 }
379379
380380 s0 =
381 Te0(byte(t0, 3)) ^
382 Te1(byte(t1, 2)) ^
383 Te2(byte(t2, 1)) ^
384 Te3(byte(t3, 0)) ^
381 Te0(LTC_BYTE(t0, 3)) ^
382 Te1(LTC_BYTE(t1, 2)) ^
383 Te2(LTC_BYTE(t2, 1)) ^
384 Te3(LTC_BYTE(t3, 0)) ^
385385 rk[0];
386386 s1 =
387 Te0(byte(t1, 3)) ^
388 Te1(byte(t2, 2)) ^
389 Te2(byte(t3, 1)) ^
390 Te3(byte(t0, 0)) ^
387 Te0(LTC_BYTE(t1, 3)) ^
388 Te1(LTC_BYTE(t2, 2)) ^
389 Te2(LTC_BYTE(t3, 1)) ^
390 Te3(LTC_BYTE(t0, 0)) ^
391391 rk[1];
392392 s2 =
393 Te0(byte(t2, 3)) ^
394 Te1(byte(t3, 2)) ^
395 Te2(byte(t0, 1)) ^
396 Te3(byte(t1, 0)) ^
393 Te0(LTC_BYTE(t2, 3)) ^
394 Te1(LTC_BYTE(t3, 2)) ^
395 Te2(LTC_BYTE(t0, 1)) ^
396 Te3(LTC_BYTE(t1, 0)) ^
397397 rk[2];
398398 s3 =
399 Te0(byte(t3, 3)) ^
400 Te1(byte(t0, 2)) ^
401 Te2(byte(t1, 1)) ^
402 Te3(byte(t2, 0)) ^
399 Te0(LTC_BYTE(t3, 3)) ^
400 Te1(LTC_BYTE(t0, 2)) ^
401 Te2(LTC_BYTE(t1, 1)) ^
402 Te3(LTC_BYTE(t2, 0)) ^
403403 rk[3];
404404 }
405405
410410 * map cipher state to byte array block:
411411 */
412412 s0 =
413 (Te4_3[byte(t0, 3)]) ^
414 (Te4_2[byte(t1, 2)]) ^
415 (Te4_1[byte(t2, 1)]) ^
416 (Te4_0[byte(t3, 0)]) ^
413 (Te4_3[LTC_BYTE(t0, 3)]) ^
414 (Te4_2[LTC_BYTE(t1, 2)]) ^
415 (Te4_1[LTC_BYTE(t2, 1)]) ^
416 (Te4_0[LTC_BYTE(t3, 0)]) ^
417417 rk[0];
418418 STORE32H(s0, ct);
419419 s1 =
420 (Te4_3[byte(t1, 3)]) ^
421 (Te4_2[byte(t2, 2)]) ^
422 (Te4_1[byte(t3, 1)]) ^
423 (Te4_0[byte(t0, 0)]) ^
420 (Te4_3[LTC_BYTE(t1, 3)]) ^
421 (Te4_2[LTC_BYTE(t2, 2)]) ^
422 (Te4_1[LTC_BYTE(t3, 1)]) ^
423 (Te4_0[LTC_BYTE(t0, 0)]) ^
424424 rk[1];
425425 STORE32H(s1, ct+4);
426426 s2 =
427 (Te4_3[byte(t2, 3)]) ^
428 (Te4_2[byte(t3, 2)]) ^
429 (Te4_1[byte(t0, 1)]) ^
430 (Te4_0[byte(t1, 0)]) ^
427 (Te4_3[LTC_BYTE(t2, 3)]) ^
428 (Te4_2[LTC_BYTE(t3, 2)]) ^
429 (Te4_1[LTC_BYTE(t0, 1)]) ^
430 (Te4_0[LTC_BYTE(t1, 0)]) ^
431431 rk[2];
432432 STORE32H(s2, ct+8);
433433 s3 =
434 (Te4_3[byte(t3, 3)]) ^
435 (Te4_2[byte(t0, 2)]) ^
436 (Te4_1[byte(t1, 1)]) ^
437 (Te4_0[byte(t2, 0)]) ^
434 (Te4_3[LTC_BYTE(t3, 3)]) ^
435 (Te4_2[LTC_BYTE(t0, 2)]) ^
436 (Te4_1[LTC_BYTE(t1, 1)]) ^
437 (Te4_0[LTC_BYTE(t2, 0)]) ^
438438 rk[3];
439439 STORE32H(s3, ct+12);
440440
489489 for (r = 0; ; r++) {
490490 rk += 4;
491491 t0 =
492 Td0(byte(s0, 3)) ^
493 Td1(byte(s3, 2)) ^
494 Td2(byte(s2, 1)) ^
495 Td3(byte(s1, 0)) ^
492 Td0(LTC_BYTE(s0, 3)) ^
493 Td1(LTC_BYTE(s3, 2)) ^
494 Td2(LTC_BYTE(s2, 1)) ^
495 Td3(LTC_BYTE(s1, 0)) ^
496496 rk[0];
497497 t1 =
498 Td0(byte(s1, 3)) ^
499 Td1(byte(s0, 2)) ^
500 Td2(byte(s3, 1)) ^
501 Td3(byte(s2, 0)) ^
498 Td0(LTC_BYTE(s1, 3)) ^
499 Td1(LTC_BYTE(s0, 2)) ^
500 Td2(LTC_BYTE(s3, 1)) ^
501 Td3(LTC_BYTE(s2, 0)) ^
502502 rk[1];
503503 t2 =
504 Td0(byte(s2, 3)) ^
505 Td1(byte(s1, 2)) ^
506 Td2(byte(s0, 1)) ^
507 Td3(byte(s3, 0)) ^
504 Td0(LTC_BYTE(s2, 3)) ^
505 Td1(LTC_BYTE(s1, 2)) ^
506 Td2(LTC_BYTE(s0, 1)) ^
507 Td3(LTC_BYTE(s3, 0)) ^
508508 rk[2];
509509 t3 =
510 Td0(byte(s3, 3)) ^
511 Td1(byte(s2, 2)) ^
512 Td2(byte(s1, 1)) ^
513 Td3(byte(s0, 0)) ^
510 Td0(LTC_BYTE(s3, 3)) ^
511 Td1(LTC_BYTE(s2, 2)) ^
512 Td2(LTC_BYTE(s1, 1)) ^
513 Td3(LTC_BYTE(s0, 0)) ^
514514 rk[3];
515515 if (r == Nr-2) {
516516 break;
528528 for (;;) {
529529
530530 t0 =
531 Td0(byte(s0, 3)) ^
532 Td1(byte(s3, 2)) ^
533 Td2(byte(s2, 1)) ^
534 Td3(byte(s1, 0)) ^
531 Td0(LTC_BYTE(s0, 3)) ^
532 Td1(LTC_BYTE(s3, 2)) ^
533 Td2(LTC_BYTE(s2, 1)) ^
534 Td3(LTC_BYTE(s1, 0)) ^
535535 rk[4];
536536 t1 =
537 Td0(byte(s1, 3)) ^
538 Td1(byte(s0, 2)) ^
539 Td2(byte(s3, 1)) ^
540 Td3(byte(s2, 0)) ^
537 Td0(LTC_BYTE(s1, 3)) ^
538 Td1(LTC_BYTE(s0, 2)) ^
539 Td2(LTC_BYTE(s3, 1)) ^
540 Td3(LTC_BYTE(s2, 0)) ^
541541 rk[5];
542542 t2 =
543 Td0(byte(s2, 3)) ^
544 Td1(byte(s1, 2)) ^
545 Td2(byte(s0, 1)) ^
546 Td3(byte(s3, 0)) ^
543 Td0(LTC_BYTE(s2, 3)) ^
544 Td1(LTC_BYTE(s1, 2)) ^
545 Td2(LTC_BYTE(s0, 1)) ^
546 Td3(LTC_BYTE(s3, 0)) ^
547547 rk[6];
548548 t3 =
549 Td0(byte(s3, 3)) ^
550 Td1(byte(s2, 2)) ^
551 Td2(byte(s1, 1)) ^
552 Td3(byte(s0, 0)) ^
549 Td0(LTC_BYTE(s3, 3)) ^
550 Td1(LTC_BYTE(s2, 2)) ^
551 Td2(LTC_BYTE(s1, 1)) ^
552 Td3(LTC_BYTE(s0, 0)) ^
553553 rk[7];
554554
555555 rk += 8;
559559
560560
561561 s0 =
562 Td0(byte(t0, 3)) ^
563 Td1(byte(t3, 2)) ^
564 Td2(byte(t2, 1)) ^
565 Td3(byte(t1, 0)) ^
562 Td0(LTC_BYTE(t0, 3)) ^
563 Td1(LTC_BYTE(t3, 2)) ^
564 Td2(LTC_BYTE(t2, 1)) ^
565 Td3(LTC_BYTE(t1, 0)) ^
566566 rk[0];
567567 s1 =
568 Td0(byte(t1, 3)) ^
569 Td1(byte(t0, 2)) ^
570 Td2(byte(t3, 1)) ^
571 Td3(byte(t2, 0)) ^
568 Td0(LTC_BYTE(t1, 3)) ^
569 Td1(LTC_BYTE(t0, 2)) ^
570 Td2(LTC_BYTE(t3, 1)) ^
571 Td3(LTC_BYTE(t2, 0)) ^
572572 rk[1];
573573 s2 =
574 Td0(byte(t2, 3)) ^
575 Td1(byte(t1, 2)) ^
576 Td2(byte(t0, 1)) ^
577 Td3(byte(t3, 0)) ^
574 Td0(LTC_BYTE(t2, 3)) ^
575 Td1(LTC_BYTE(t1, 2)) ^
576 Td2(LTC_BYTE(t0, 1)) ^
577 Td3(LTC_BYTE(t3, 0)) ^
578578 rk[2];
579579 s3 =
580 Td0(byte(t3, 3)) ^
581 Td1(byte(t2, 2)) ^
582 Td2(byte(t1, 1)) ^
583 Td3(byte(t0, 0)) ^
580 Td0(LTC_BYTE(t3, 3)) ^
581 Td1(LTC_BYTE(t2, 2)) ^
582 Td2(LTC_BYTE(t1, 1)) ^
583 Td3(LTC_BYTE(t0, 0)) ^
584584 rk[3];
585585 }
586586 #endif
590590 * map cipher state to byte array block:
591591 */
592592 s0 =
593 (Td4[byte(t0, 3)] & 0xff000000) ^
594 (Td4[byte(t3, 2)] & 0x00ff0000) ^
595 (Td4[byte(t2, 1)] & 0x0000ff00) ^
596 (Td4[byte(t1, 0)] & 0x000000ff) ^
593 (Td4[LTC_BYTE(t0, 3)] & 0xff000000) ^
594 (Td4[LTC_BYTE(t3, 2)] & 0x00ff0000) ^
595 (Td4[LTC_BYTE(t2, 1)] & 0x0000ff00) ^
596 (Td4[LTC_BYTE(t1, 0)] & 0x000000ff) ^
597597 rk[0];
598598 STORE32H(s0, pt);
599599 s1 =
600 (Td4[byte(t1, 3)] & 0xff000000) ^
601 (Td4[byte(t0, 2)] & 0x00ff0000) ^
602 (Td4[byte(t3, 1)] & 0x0000ff00) ^
603 (Td4[byte(t2, 0)] & 0x000000ff) ^
600 (Td4[LTC_BYTE(t1, 3)] & 0xff000000) ^
601 (Td4[LTC_BYTE(t0, 2)] & 0x00ff0000) ^
602 (Td4[LTC_BYTE(t3, 1)] & 0x0000ff00) ^
603 (Td4[LTC_BYTE(t2, 0)] & 0x000000ff) ^
604604 rk[1];
605605 STORE32H(s1, pt+4);
606606 s2 =
607 (Td4[byte(t2, 3)] & 0xff000000) ^
608 (Td4[byte(t1, 2)] & 0x00ff0000) ^
609 (Td4[byte(t0, 1)] & 0x0000ff00) ^
610 (Td4[byte(t3, 0)] & 0x000000ff) ^
607 (Td4[LTC_BYTE(t2, 3)] & 0xff000000) ^
608 (Td4[LTC_BYTE(t1, 2)] & 0x00ff0000) ^
609 (Td4[LTC_BYTE(t0, 1)] & 0x0000ff00) ^
610 (Td4[LTC_BYTE(t3, 0)] & 0x000000ff) ^
611611 rk[2];
612612 STORE32H(s2, pt+8);
613613 s3 =
614 (Td4[byte(t3, 3)] & 0xff000000) ^
615 (Td4[byte(t2, 2)] & 0x00ff0000) ^
616 (Td4[byte(t1, 1)] & 0x0000ff00) ^
617 (Td4[byte(t0, 0)] & 0x000000ff) ^
614 (Td4[LTC_BYTE(t3, 3)] & 0xff000000) ^
615 (Td4[LTC_BYTE(t2, 2)] & 0x00ff0000) ^
616 (Td4[LTC_BYTE(t1, 1)] & 0x0000ff00) ^
617 (Td4[LTC_BYTE(t0, 0)] & 0x000000ff) ^
618618 rk[3];
619619 STORE32H(s3, pt+12);
620620
2929 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
3030 };
3131
32 #define MIN_N 4
3332 #define MAX_N 10
34 #define MIN_ROUNDS (8 + MIN_N)
35 #define MAX_ROUNDS (8 + MAX_N)
36 #define MIN_KEYSIZEB (4*MIN_N)
37 #define MAX_KEYSIZEB (4*MAX_N)
38 #define BLOCKSIZE 128
39 #define BLOCKSIZEB (BLOCKSIZE/8)
40
4133
4234 /*
4335 * Though Anubis is endianness-neutral, the encryption tables are listed
372372 }
373373
374374 #ifndef __GNUC__
375 #define F(x) ((S1[byte(x,3)] + S2[byte(x,2)]) ^ S3[byte(x,1)]) + S4[byte(x,0)]
375 #define F(x) ((S1[LTC_BYTE(x,3)] + S2[LTC_BYTE(x,2)]) ^ S3[LTC_BYTE(x,1)]) + S4[LTC_BYTE(x,0)]
376376 #else
377 #define F(x) ((skey->blowfish.S[0][byte(x,3)] + skey->blowfish.S[1][byte(x,2)]) ^ skey->blowfish.S[2][byte(x,1)]) + skey->blowfish.S[3][byte(x,0)]
377 #define F(x) ((skey->blowfish.S[0][LTC_BYTE(x,3)] + skey->blowfish.S[1][LTC_BYTE(x,2)]) ^ skey->blowfish.S[2][LTC_BYTE(x,1)]) + skey->blowfish.S[3][LTC_BYTE(x,0)]
378378 #endif
379379
380380 /**
507507 ulong32 I;
508508 I = (Km + R);
509509 I = ROL(I, Kr);
510 return ((S1[byte(I, 3)] ^ S2[byte(I,2)]) - S3[byte(I,1)]) + S4[byte(I,0)];
510 return ((S1[LTC_BYTE(I, 3)] ^ S2[LTC_BYTE(I,2)]) - S3[LTC_BYTE(I,1)]) + S4[LTC_BYTE(I,0)];
511511 }
512512
513513 INLINE static ulong32 FII(ulong32 R, ulong32 Km, ulong32 Kr)
515515 ulong32 I;
516516 I = (Km ^ R);
517517 I = ROL(I, Kr);
518 return ((S1[byte(I, 3)] - S2[byte(I,2)]) + S3[byte(I,1)]) ^ S4[byte(I,0)];
518 return ((S1[LTC_BYTE(I, 3)] - S2[LTC_BYTE(I,2)]) + S3[LTC_BYTE(I,1)]) ^ S4[LTC_BYTE(I,0)];
519519 }
520520
521521 INLINE static ulong32 FIII(ulong32 R, ulong32 Km, ulong32 Kr)
523523 ulong32 I;
524524 I = (Km - R);
525525 I = ROL(I, Kr);
526 return ((S1[byte(I, 3)] + S2[byte(I,2)]) ^ S3[byte(I,1)]) - S4[byte(I,0)];
526 return ((S1[LTC_BYTE(I, 3)] + S2[LTC_BYTE(I,2)]) ^ S3[LTC_BYTE(I,1)]) - S4[LTC_BYTE(I,0)];
527527 }
528528
529529 /**
14311431 #else
14321432 {
14331433 ulong64 tmp;
1434 tmp = des_ip[0][byte(leftt, 0)] ^
1435 des_ip[1][byte(leftt, 1)] ^
1436 des_ip[2][byte(leftt, 2)] ^
1437 des_ip[3][byte(leftt, 3)] ^
1438 des_ip[4][byte(right, 0)] ^
1439 des_ip[5][byte(right, 1)] ^
1440 des_ip[6][byte(right, 2)] ^
1441 des_ip[7][byte(right, 3)];
1434 tmp = des_ip[0][LTC_BYTE(leftt, 0)] ^
1435 des_ip[1][LTC_BYTE(leftt, 1)] ^
1436 des_ip[2][LTC_BYTE(leftt, 2)] ^
1437 des_ip[3][LTC_BYTE(leftt, 3)] ^
1438 des_ip[4][LTC_BYTE(right, 0)] ^
1439 des_ip[5][LTC_BYTE(right, 1)] ^
1440 des_ip[6][LTC_BYTE(right, 2)] ^
1441 des_ip[7][LTC_BYTE(right, 3)];
14421442 leftt = (ulong32)(tmp >> 32);
14431443 right = (ulong32)(tmp & 0xFFFFFFFFUL);
14441444 }
14901490 #else
14911491 {
14921492 ulong64 tmp;
1493 tmp = des_fp[0][byte(leftt, 0)] ^
1494 des_fp[1][byte(leftt, 1)] ^
1495 des_fp[2][byte(leftt, 2)] ^
1496 des_fp[3][byte(leftt, 3)] ^
1497 des_fp[4][byte(right, 0)] ^
1498 des_fp[5][byte(right, 1)] ^
1499 des_fp[6][byte(right, 2)] ^
1500 des_fp[7][byte(right, 3)];
1493 tmp = des_fp[0][LTC_BYTE(leftt, 0)] ^
1494 des_fp[1][LTC_BYTE(leftt, 1)] ^
1495 des_fp[2][LTC_BYTE(leftt, 2)] ^
1496 des_fp[3][LTC_BYTE(leftt, 3)] ^
1497 des_fp[4][LTC_BYTE(right, 0)] ^
1498 des_fp[5][LTC_BYTE(right, 1)] ^
1499 des_fp[6][LTC_BYTE(right, 2)] ^
1500 des_fp[7][LTC_BYTE(right, 3)];
15011501 leftt = (ulong32)(tmp >> 32);
15021502 right = (ulong32)(tmp & 0xFFFFFFFFUL);
15031503 }
2929 };
3030
3131 #define R 8
32 #define KEYSIZE 128
33 #define KEYSIZEB (KEYSIZE/8)
34 #define BLOCKSIZE 64
35 #define BLOCKSIZEB (BLOCKSIZE/8)
3632
3733 static const ulong64 T0[256] = {
3834 CONST64(0xbad3d268bbb96a01), CONST64(0x54fc4d19e59a66b1), CONST64(0x2f71bc93e26514cd), CONST64(0x749ccdb925871b51),
3636 };
3737
3838 /* the two polynomials */
39 #ifndef LTC_TWOFISH_TABLES
3940 #define MDS_POLY 0x169
41 #endif
42 #ifndef LTC_TWOFISH_ALL_TABLES
4043 #define RS_POLY 0x14D
44 #endif
4145
4246 /* The 4x8 RS Linear Transform */
4347 static const unsigned char RS[4][8] = {
277281 #endif
278282
279283 /* the G function */
280 #define g_func(x, dum) (S1[byte(x,0)] ^ S2[byte(x,1)] ^ S3[byte(x,2)] ^ S4[byte(x,3)])
281 #define g1_func(x, dum) (S2[byte(x,0)] ^ S3[byte(x,1)] ^ S4[byte(x,2)] ^ S1[byte(x,3)])
284 #define g_func(x, dum) (S1[LTC_BYTE(x,0)] ^ S2[LTC_BYTE(x,1)] ^ S3[LTC_BYTE(x,2)] ^ S4[LTC_BYTE(x,3)])
285 #define g1_func(x, dum) (S2[LTC_BYTE(x,0)] ^ S3[LTC_BYTE(x,1)] ^ S4[LTC_BYTE(x,2)] ^ S1[LTC_BYTE(x,3)])
282286
283287 #else
284288
563563 {
564564 ulong64 tmp;
565565 tmp = (*c ^= x);
566 *a -= t1[byte(tmp, 0)] ^ t2[byte(tmp, 2)] ^ t3[byte(tmp, 4)] ^ t4[byte(tmp, 6)];
567 tmp = (*b += t4[byte(tmp, 1)] ^ t3[byte(tmp, 3)] ^ t2[byte(tmp,5)] ^ t1[byte(tmp,7)]);
566 *a -= t1[LTC_BYTE(tmp, 0)] ^ t2[LTC_BYTE(tmp, 2)] ^ t3[LTC_BYTE(tmp, 4)] ^ t4[LTC_BYTE(tmp, 6)];
567 tmp = (*b += t4[LTC_BYTE(tmp, 1)] ^ t3[LTC_BYTE(tmp, 3)] ^ t2[LTC_BYTE(tmp,5)] ^ t1[LTC_BYTE(tmp,7)]);
568568 switch (mul) {
569569 case 5: *b = (tmp << 2) + tmp; break;
570570 case 7: *b = (tmp << 3) - tmp; break;
428428 #define LTC_UNUSED_PARAM(x) (void)(x)
429429 #endif
430430
431 /* extract a byte portably */
432 #ifdef _MSC_VER
433 #define byte(x, n) ((unsigned char)((x) >> (8 * (n))))
434 #else
435 #define byte(x, n) (((x) >> (8 * (n))) & 255)
436 #endif
437
438431 /* there is no snprintf before Visual C++ 2015 */
439432 #if defined(_MSC_VER) && _MSC_VER < 1900
440433 #define snprintf _snprintf
387387 return CRYPT_OK; \
388388 }
389389
390 /* extract a byte portably */
391 #ifdef _MSC_VER
392 #define LTC_BYTE(x, n) ((unsigned char)((x) >> (8 * (n))))
393 #else
394 #define LTC_BYTE(x, n) (((x) >> (8 * (n))) & 255)
395 #endif
390396
391397 /* ref: $Format:%D$ */
392398 /* git commit: $Format:%H$ */
6161 LOAD32H(s3, pelmac->state + 12);
6262 for (r = 0; r < 4; r++) {
6363 t0 =
64 Te0(byte(s0, 3)) ^
65 Te1(byte(s1, 2)) ^
66 Te2(byte(s2, 1)) ^
67 Te3(byte(s3, 0));
64 Te0(LTC_BYTE(s0, 3)) ^
65 Te1(LTC_BYTE(s1, 2)) ^
66 Te2(LTC_BYTE(s2, 1)) ^
67 Te3(LTC_BYTE(s3, 0));
6868 t1 =
69 Te0(byte(s1, 3)) ^
70 Te1(byte(s2, 2)) ^
71 Te2(byte(s3, 1)) ^
72 Te3(byte(s0, 0));
69 Te0(LTC_BYTE(s1, 3)) ^
70 Te1(LTC_BYTE(s2, 2)) ^
71 Te2(LTC_BYTE(s3, 1)) ^
72 Te3(LTC_BYTE(s0, 0));
7373 t2 =
74 Te0(byte(s2, 3)) ^
75 Te1(byte(s3, 2)) ^
76 Te2(byte(s0, 1)) ^
77 Te3(byte(s1, 0));
74 Te0(LTC_BYTE(s2, 3)) ^
75 Te1(LTC_BYTE(s3, 2)) ^
76 Te2(LTC_BYTE(s0, 1)) ^
77 Te3(LTC_BYTE(s1, 0));
7878 t3 =
79 Te0(byte(s3, 3)) ^
80 Te1(byte(s0, 2)) ^
81 Te2(byte(s1, 1)) ^
82 Te3(byte(s2, 0));
79 Te0(LTC_BYTE(s3, 3)) ^
80 Te1(LTC_BYTE(s0, 2)) ^
81 Te2(LTC_BYTE(s1, 1)) ^
82 Te3(LTC_BYTE(s2, 0));
8383 s0 = t0; s1 = t1; s2 = t2; s3 = t3;
8484 }
8585 STORE32H(s0, pelmac->state );
2525 static int _der_flexi_sequence_cmp(const ltc_asn1_list *flexi, der_flexi_check *check)
2626 {
2727 const ltc_asn1_list *cur;
28 if (flexi->type != LTC_ASN1_SEQUENCE)
28 if (flexi->type != LTC_ASN1_SEQUENCE) {
2929 return CRYPT_INVALID_PACKET;
30 }
3031 cur = flexi->child;
3132 while(check->t != LTC_ASN1_EOL) {
32 if (!LTC_ASN1_IS_TYPE(cur, check->t))
33 if (!LTC_ASN1_IS_TYPE(cur, check->t)) {
3334 return CRYPT_INVALID_PACKET;
35 }
3436 if (check->pp != NULL) *check->pp = (ltc_asn1_list*)cur;
3537 cur = cur->next;
3638 check++;
7575 }
7676 else if (sigformat == LTC_ECCSIG_RFC7518) {
7777 /* RFC7518 format - raw (r,s) */
78 if (siglen % 2) {
78 i = mp_unsigned_bin_size(key->dp.order);
79 if (siglen != (2*i)) {
7980 err = CRYPT_INVALID_PACKET;
8081 goto error;
8182 }
82 i = siglen / 2;
8383 if ((err = mp_read_unsigned_bin(r, (unsigned char *)sig, i)) != CRYPT_OK) { goto error; }
8484 if ((err = mp_read_unsigned_bin(s, (unsigned char *)sig+i, i)) != CRYPT_OK) { goto error; }
8585 }
2020
2121 /* don't change these... */
2222 #define N 17
23 #define FOLD N /* how many iterations of folding to do */
2423 #define INITKONST 0x6996c53a /* value of KONST to use during key loading */
2524 #define KEYP 15 /* where to insert key words */
2625 #define FOLDP 4 /* where to insert non-linear feedback */
27
28 #define B(x,i) ((unsigned char)(((x) >> (8*i)) & 0xFF))
2926
3027 static ulong32 BYTE2WORD(const unsigned char *b)
3128 {