69 #if CRYPTOPP_MSC_VERSION 70 # pragma warning(disable: 4127) 79 #if defined(CRYPTOPP_DISABLE_INTEL_ASM) 80 # undef CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE 81 # undef CRYPTOPP_BOOL_SSSE3_ASM_AVAILABLE 82 # define CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE 0 83 # define CRYPTOPP_BOOL_SSSE3_ASM_AVAILABLE 0 88 #if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING) 89 void Whirlpool_TestInstantiations()
97 memset(state, 0, 8*
sizeof(state[0]));
131 #if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE 134 static const word64 Whirlpool_C[4*256+
R] = {
396 W64LIT(0x1823c6e887b8014f),
397 W64LIT(0x36a6d2f5796f9152),
398 W64LIT(0x60bc9b8ea30c7b35),
399 W64LIT(0x1de0d7c22e4bfe57),
400 W64LIT(0x157737e59ff04ada),
401 W64LIT(0x58c9290ab1a06b85),
402 W64LIT(0xbd5d10f4cb3e0567),
403 W64LIT(0xe427418ba77d95d8),
404 W64LIT(0xfbee7c66dd17479e),
405 W64LIT(0xca2dbf07ad5a8333)
411 #if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE 416 #if CRYPTOPP_BOOL_X64 423 AS2( mov AS_REG_6, WORD_REG(ax))
425 AS2( lea AS_REG_6, [Whirlpool_C])
426 AS2( mov WORD_REG(cx), digest)
427 AS2( mov WORD_REG(dx), block)
435 #define SSE2_workspace esp+WORD_SZ
437 #define SSE2_workspace esp+(WORD_SZ*2)
440 #define SSE2_workspace %3
444 AS2( movq mm0, [WORD_REG(cx)+8*WORD_REG(si)])
445 AS2( movq [SSE2_workspace+8*WORD_REG(si)], mm0)
446 AS2( pxor mm0, [WORD_REG(dx)+8*WORD_REG(si)])
447 AS2( movq [SSE2_workspace+64+8*WORD_REG(si)], mm0)
448 AS2( movq [WORD_REG(cx)+8*WORD_REG(si)], mm0)
449 AS1( inc WORD_REG(si))
450 AS2( cmp WORD_REG(si), 8)
456 #define KSL0(
a,
b) AS2(movq mm##
a,
b)
457 #define KSL1(a,
b) AS2(pxor mm##a,
b)
459 #define
KSL(op, i, a,
b,
c,
d) \
460 AS2(mov eax, [SSE2_workspace+8*i])\
462 KSL##op(a, [AS_REG_6+3*2048+8*WORD_REG(di)])\
464 KSL##op(
b, [AS_REG_6+2*2048+8*WORD_REG(di)])\
468 KSL##op(
c, [AS_REG_6+1*2048+8*WORD_REG(di)])\
469 KSL##op(
d, [AS_REG_6+0*2048+8*WORD_REG(ax)])
472 ASS(pshufw mm##a, mm##a, 1, 0, 3, 2)\
478 AS2(movq [SSE2_workspace+8*a], mm##a)
480 #define
KSH(op, i, a,
b,
c,
d) \
481 AS2(mov eax, [SSE2_workspace+8*((i+4)-8*((i+4)/8))+4])\
483 KSH##op(a, [AS_REG_6+3*2048+8*WORD_REG(di)])\
485 KSH##op(
b, [AS_REG_6+2*2048+8*WORD_REG(di)])\
489 KSH##op(
c, [AS_REG_6+1*2048+8*WORD_REG(di)])\
490 KSH##op(
d, [AS_REG_6+0*2048+8*WORD_REG(ax)])
492 #define
TSL(op, i, a,
b,
c,
d) \
493 AS2(mov eax, [SSE2_workspace+64+8*i])\
495 KSL##op(a, [AS_REG_6+3*2048+8*WORD_REG(di)])\
497 KSL##op(
b, [AS_REG_6+2*2048+8*WORD_REG(di)])\
501 KSL##op(
c, [AS_REG_6+1*2048+8*WORD_REG(di)])\
502 KSL##op(
d, [AS_REG_6+0*2048+8*WORD_REG(ax)])
505 ASS(pshufw mm##a, mm##a, 1, 0, 3, 2)\
506 AS2(pxor mm##a, [SSE2_workspace+8*a])\
512 AS2(movq [SSE2_workspace+64+8*a], mm##a)
515 AS2(pxor mm##a, [WORD_REG(cx)+8*a])\
516 AS2(movq [WORD_REG(cx)+8*a], mm##a)
518 #define
TSH(op, i, a,
b,
c,
d) \
519 AS2(mov eax, [SSE2_workspace+64+8*((i+4)-8*((i+4)/8))+4])\
521 TSH##op(a, [AS_REG_6+3*2048+8*WORD_REG(di)])\
523 TSH##op(
b, [AS_REG_6+2*2048+8*WORD_REG(di)])\
527 TSH##op(
c, [AS_REG_6+1*2048+8*WORD_REG(di)])\
528 TSH##op(
d, [AS_REG_6+0*2048+8*WORD_REG(ax)])
530 KSL(0, 4, 3, 2, 1, 0)
531 KSL(0, 0, 7, 6, 5, 4)
532 KSL(1, 1, 0, 7, 6, 5)
533 KSL(1, 2, 1, 0, 7, 6)
534 KSL(1, 3, 2, 1, 0, 7)
535 KSL(1, 5, 4, 3, 2, 1)
536 KSL(1, 6, 5, 4, 3, 2)
537 KSL(1, 7, 6, 5, 4, 3)
538 KSH(0, 0, 7, 6, 5, 4)
539 KSH(0, 4, 3, 2, 1, 0)
540 KSH(1, 1, 0, 7, 6, 5)
541 KSH(1, 2, 1, 0, 7, 6)
542 KSH(1, 5, 4, 3, 2, 1)
543 KSH(1, 6, 5, 4, 3, 2)
544 KSH(2, 3, 2, 1, 0, 7)
545 KSH(2, 7, 6, 5, 4, 3)
547 AS2( pxor mm0, [AS_REG_6 + 8*1024 + WORD_REG(si)*8])
548 AS2( movq [SSE2_workspace], mm0)
550 TSL(0, 4, 3, 2, 1, 0)
551 TSL(0, 0, 7, 6, 5, 4)
552 TSL(1, 1, 0, 7, 6, 5)
553 TSL(1, 2, 1, 0, 7, 6)
554 TSL(1, 3, 2, 1, 0, 7)
555 TSL(1, 5, 4, 3, 2, 1)
556 TSL(1, 6, 5, 4, 3, 2)
557 TSL(1, 7, 6, 5, 4, 3)
558 TSH(0, 0, 7, 6, 5, 4)
559 TSH(0, 4, 3, 2, 1, 0)
560 TSH(1, 1, 0, 7, 6, 5)
561 TSH(1, 2, 1, 0, 7, 6)
562 TSH(1, 5, 4, 3, 2, 1)
563 TSH(1, 6, 5, 4, 3, 2)
565 AS1( inc WORD_REG(si))
566 AS2( cmp WORD_REG(si), 10)
569 TSH(2, 3, 2, 1, 0, 7)
570 TSH(2, 7, 6, 5, 4, 3)
575 TSH(3, 3, 2, 1, 0, 7)
576 TSH(3, 7, 6, 5, 4, 3)
586 #
if defined(__GNUC__)
592 :
"a" (Whirlpool_C),
"c" (digest),
"d" (block)
596 :
"%esi",
"%edi",
"memory",
"cc" 597 #
if CRYPTOPP_BOOL_X64
604 #endif // #ifdef CRYPTOPP_X86_ASM_AVAILABLE 611 for (
int i=0; i<8; i++)
612 digest[i] = s[i] = block[i] ^ (k[i] = digest[i]);
614 #define KSL(op, i, a, b, c, d) \ 616 w##a = Whirlpool_C[3*256 + (byte)t] ^ (op ? w##a : 0);\ 618 w##b = Whirlpool_C[2*256 + (byte)t] ^ (op ? w##b : 0);\ 620 w##c = Whirlpool_C[1*256 + (byte)t] ^ (op ? w##c : 0);\ 622 w##d = Whirlpool_C[0*256 + t] ^ (op ? w##d : 0); 624 #define KSH(op, i, a, b, c, d) \ 625 t = (word32)(k[(i+4)%8]>>32);\ 626 w##a = Whirlpool_C[3*256 + (byte)t] ^ (op ? w##a : rotrFixed(w##a, 32));\ 627 if (op==2) k[a] = w##a;\ 629 w##b = Whirlpool_C[2*256 + (byte)t] ^ (op ? w##b : rotrFixed(w##b, 32));\ 630 if (op==2) k[b] = w##b;\ 632 w##c = Whirlpool_C[1*256 + (byte)t] ^ (op ? w##c : rotrFixed(w##c, 32));\ 633 if (op==2) k[c] = w##c;\ 635 w##d = Whirlpool_C[0*256 + t] ^ (op ? w##d : rotrFixed(w##d, 32));\ 636 if (op==2) k[d] = w##d;\ 638 #define TSL(op, i, a, b, c, d) \ 640 w##a = Whirlpool_C[3*256 + (byte)t] ^ (op ? w##a : 0);\ 642 w##b = Whirlpool_C[2*256 + (byte)t] ^ (op ? w##b : 0);\ 644 w##c = Whirlpool_C[1*256 + (byte)t] ^ (op ? w##c : 0);\ 646 w##d = Whirlpool_C[0*256 + t] ^ (op ? w##d : 0); 648 #define TSH_OP(op, a, b) \ 649 w##a = Whirlpool_C[b*256 + (byte)t] ^ (op ? w##a : rotrFixed(w##a, 32) ^ k[a]);\ 650 if (op==2) s[a] = w##a;\ 651 if (op==3) digest[a] ^= w##a;\ 653 #define TSH(op, i, a, b, c, d) \ 654 t = (word32)(s[(i+4)%8]>>32);\ 668 word64 w0=0, w1=0, w2=0, w3=0, w4=0, w5=0, w6=0, w7=0;
671 KSL(0, 4, 3, 2, 1, 0)
672 KSL(0, 0, 7, 6, 5, 4)
673 KSL(1, 1, 0, 7, 6, 5)
674 KSL(1, 2, 1, 0, 7, 6)
675 KSL(1, 3, 2, 1, 0, 7)
676 KSL(1, 5, 4, 3, 2, 1)
677 KSL(1, 6, 5, 4, 3, 2)
678 KSL(1, 7, 6, 5, 4, 3)
679 KSH(0, 0, 7, 6, 5, 4)
680 KSH(0, 4, 3, 2, 1, 0)
681 KSH(1, 1, 0, 7, 6, 5)
682 KSH(1, 2, 1, 0, 7, 6)
683 KSH(1, 5, 4, 3, 2, 1)
684 KSH(1, 6, 5, 4, 3, 2)
685 KSH(2, 3, 2, 1, 0, 7)
686 KSH(2, 7, 6, 5, 4, 3)
688 k[0] ^= Whirlpool_C[1024+r];
690 TSL(0, 4, 3, 2, 1, 0)
691 TSL(0, 0, 7, 6, 5, 4)
692 TSL(1, 1, 0, 7, 6, 5)
693 TSL(1, 2, 1, 0, 7, 6)
694 TSL(1, 3, 2, 1, 0, 7)
695 TSL(1, 5, 4, 3, 2, 1)
696 TSL(1, 6, 5, 4, 3, 2)
697 TSL(1, 7, 6, 5, 4, 3)
698 TSH(0, 0, 7, 6, 5, 4)
699 TSH(0, 4, 3, 2, 1, 0)
700 TSH(1, 1, 0, 7, 6, 5)
701 TSH(1, 2, 1, 0, 7, 6)
702 TSH(1, 5, 4, 3, 2, 1)
703 TSH(1, 6, 5, 4, 3, 2)
707 TSH(2, 3, 2, 1, 0, 7)
708 TSH(2, 7, 6, 5, 4, 3)
712 TSH(3, 3, 2, 1, 0, 7)
713 TSH(3, 7, 6, 5, 4, 3)
#define TSL(op, i, a, b, c, d)
#define CRYPTOPP_BOOL_X64
#define TSH(op, i, a, b, c, d)
Utility functions for the Crypto++ library.
#define NAMESPACE_BEGIN(x)
static void Transform(word64 *digest, const word64 *data)
size_type size() const
Provides the count of elements in the SecBlock.
Library configuration file.
#define KSL(op, i, a, b, c, d)
#define KSH(op, i, a, b, c, d)
void TruncatedFinal(byte *hash, size_t size)
Computes the hash of the current message.
#define CRYPTOPP_ALIGN_DATA(x)
word64 GetBitCountLo() const
uint32_t shr(uint32_t x, std::size_t n)
word64 GetBitCountHi() const
void CorrectEndianess(HashWordType *out, const HashWordType *in, size_t byteCount)
Adjusts the byte ordering of the hash.
unsigned long long word64
FixedSizeSecBlock< word64, T_BlockSize/sizeof(word64)> m_data
Functions for CPU features and intrinsics.
void Restart()
Restart the hash.
void PadLastBlock(unsigned int lastBlockSize, byte padFirst=0x80)
#define CRYPTOPP_BOOL_X32
uint8_t const size_t const size
#define CRYPTOPP_BOOL_X86
void * memcpy(void *a, const void *b, size_t c)
static void InitState(HashWordType *state)
The Whirlpool hashing function.
#define CRYPTOPP_SECTION_ALIGN16