Mercurial > dropbear
comparison tiger.c @ 143:5d99163f7e32 libtomcrypt-orig
import of libtomcrypt 0.99
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sun, 19 Dec 2004 11:34:45 +0000 |
parents | 6362d3854bb4 |
children | 7ed585a2c53b |
comparison
equal
deleted
inserted
replaced
15:6362d3854bb4 | 143:5d99163f7e32 |
---|---|
556 #else | 556 #else |
557 #define INLINE | 557 #define INLINE |
558 #endif | 558 #endif |
559 | 559 |
560 /* one round of the hash function */ | 560 /* one round of the hash function */ |
561 INLINE static void round(ulong64 *a, ulong64 *b, ulong64 *c, ulong64 x, int mul) | 561 INLINE static void tiger_round(ulong64 *a, ulong64 *b, ulong64 *c, ulong64 x, int mul) |
562 { | 562 { |
563 ulong64 tmp; | 563 ulong64 tmp; |
564 tmp = (*c ^= x); | 564 tmp = (*c ^= x); |
565 *a -= t1[byte(tmp, 0)] ^ t2[byte(tmp, 2)] ^ t3[byte(tmp, 4)] ^ t4[byte(tmp, 6)]; | 565 *a -= t1[byte(tmp, 0)] ^ t2[byte(tmp, 2)] ^ t3[byte(tmp, 4)] ^ t4[byte(tmp, 6)]; |
566 tmp = (*b += t4[byte(tmp, 1)] ^ t3[byte(tmp, 3)] ^ t2[byte(tmp,5)] ^ t1[byte(tmp,7)]); | 566 tmp = (*b += t4[byte(tmp, 1)] ^ t3[byte(tmp, 3)] ^ t2[byte(tmp,5)] ^ t1[byte(tmp,7)]); |
572 } | 572 } |
573 | 573 |
574 /* one complete pass */ | 574 /* one complete pass */ |
575 static void pass(ulong64 *a, ulong64 *b, ulong64 *c, ulong64 *x, int mul) | 575 static void pass(ulong64 *a, ulong64 *b, ulong64 *c, ulong64 *x, int mul) |
576 { | 576 { |
577 round(a,b,c,x[0],mul); | 577 tiger_round(a,b,c,x[0],mul); |
578 round(b,c,a,x[1],mul); | 578 tiger_round(b,c,a,x[1],mul); |
579 round(c,a,b,x[2],mul); | 579 tiger_round(c,a,b,x[2],mul); |
580 round(a,b,c,x[3],mul); | 580 tiger_round(a,b,c,x[3],mul); |
581 round(b,c,a,x[4],mul); | 581 tiger_round(b,c,a,x[4],mul); |
582 round(c,a,b,x[5],mul); | 582 tiger_round(c,a,b,x[5],mul); |
583 round(a,b,c,x[6],mul); | 583 tiger_round(a,b,c,x[6],mul); |
584 round(b,c,a,x[7],mul); | 584 tiger_round(b,c,a,x[7],mul); |
585 } | 585 } |
586 | 586 |
587 /* The key mixing schedule */ | 587 /* The key mixing schedule */ |
588 static void key_schedule(ulong64 *x) | 588 static void key_schedule(ulong64 *x) |
589 { | 589 { |
604 x[6] += x[5]; | 604 x[6] += x[5]; |
605 x[7] -= x[6] ^ CONST64(0x0123456789ABCDEF); | 605 x[7] -= x[6] ^ CONST64(0x0123456789ABCDEF); |
606 } | 606 } |
607 | 607 |
608 #ifdef CLEAN_STACK | 608 #ifdef CLEAN_STACK |
609 static void _tiger_compress(hash_state *md, unsigned char *buf) | 609 static int _tiger_compress(hash_state *md, unsigned char *buf) |
610 #else | 610 #else |
611 static void tiger_compress(hash_state *md, unsigned char *buf) | 611 static int tiger_compress(hash_state *md, unsigned char *buf) |
612 #endif | 612 #endif |
613 { | 613 { |
614 ulong64 a, b, c, x[8]; | 614 ulong64 a, b, c, x[8]; |
615 unsigned long i; | 615 unsigned long i; |
616 | 616 |
630 | 630 |
631 /* store state */ | 631 /* store state */ |
632 md->tiger.state[0] = a ^ md->tiger.state[0]; | 632 md->tiger.state[0] = a ^ md->tiger.state[0]; |
633 md->tiger.state[1] = b - md->tiger.state[1]; | 633 md->tiger.state[1] = b - md->tiger.state[1]; |
634 md->tiger.state[2] = c + md->tiger.state[2]; | 634 md->tiger.state[2] = c + md->tiger.state[2]; |
635 | |
636 return CRYPT_OK; | |
635 } | 637 } |
636 | 638 |
637 #ifdef CLEAN_STACK | 639 #ifdef CLEAN_STACK |
638 static void tiger_compress(hash_state *md, unsigned char *buf) | 640 static int tiger_compress(hash_state *md, unsigned char *buf) |
639 { | 641 { |
640 _tiger_compress(md, buf); | 642 int err; |
643 err = _tiger_compress(md, buf); | |
641 burn_stack(sizeof(ulong64) * 11 + sizeof(unsigned long)); | 644 burn_stack(sizeof(ulong64) * 11 + sizeof(unsigned long)); |
645 return err; | |
642 } | 646 } |
643 #endif | 647 #endif |
644 | 648 |
645 void tiger_init(hash_state *md) | 649 int tiger_init(hash_state *md) |
646 { | 650 { |
647 _ARGCHK(md != NULL); | 651 _ARGCHK(md != NULL); |
648 md->tiger.state[0] = CONST64(0x0123456789ABCDEF); | 652 md->tiger.state[0] = CONST64(0x0123456789ABCDEF); |
649 md->tiger.state[1] = CONST64(0xFEDCBA9876543210); | 653 md->tiger.state[1] = CONST64(0xFEDCBA9876543210); |
650 md->tiger.state[2] = CONST64(0xF096A5B4C3B2E187); | 654 md->tiger.state[2] = CONST64(0xF096A5B4C3B2E187); |
651 md->tiger.curlen = 0; | 655 md->tiger.curlen = 0; |
652 md->tiger.length = 0; | 656 md->tiger.length = 0; |
657 return CRYPT_OK; | |
653 } | 658 } |
654 | 659 |
655 HASH_PROCESS(tiger_process, tiger_compress, tiger, 64) | 660 HASH_PROCESS(tiger_process, tiger_compress, tiger, 64) |
656 | 661 |
657 int tiger_done(hash_state * md, unsigned char *hash) | 662 int tiger_done(hash_state * md, unsigned char *hash) |