68#if CRYPTOPP_MSC_VERSION
69# pragma warning(disable: 4127)
76#if defined(CRYPTOPP_DISABLE_WHIRLPOOL_ASM)
77# undef CRYPTOPP_X86_ASM_AVAILABLE
78# undef CRYPTOPP_X32_ASM_AVAILABLE
79# undef CRYPTOPP_X64_ASM_AVAILABLE
80# undef CRYPTOPP_SSE2_ASM_AVAILABLE
85#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
86void Whirlpool_TestInstantiations()
94#if CRYPTOPP_SSE2_ASM_AVAILABLE
101void Whirlpool::InitState(HashWordType *state)
103 std::memset(state, 0, 8*
sizeof(state[0]));
106void Whirlpool::TruncatedFinal(
byte *hash,
size_t size)
109 ThrowIfInvalidTruncatedSize(size);
112 CorrectEndianess(m_data, m_data, 32);
114 m_data[m_data.size()-4] = 0;
115 m_data[m_data.size()-3] = 0;
116 m_data[m_data.size()-2] = GetBitCountHi();
117 m_data[m_data.size()-1] = GetBitCountLo();
119 Transform(m_state, m_data);
120 CorrectEndianess(m_state, m_state,
DigestSize());
121 std::memcpy(hash, m_state, size);
138#if CRYPTOPP_SSE2_ASM_AVAILABLE
139CRYPTOPP_ALIGN_DATA(16)
141const
word64 Whirlpool_C[4*256+R] = {
143const word64 Whirlpool_C[4*256+R] = {
405 W64LIT(0x1823c6e887b8014f),
406 W64LIT(0x36a6d2f5796f9152),
407 W64LIT(0x60bc9b8ea30c7b35),
408 W64LIT(0x1de0d7c22e4bfe57),
409 W64LIT(0x157737e59ff04ada),
410 W64LIT(0x58c9290ab1a06b85),
411 W64LIT(0xbd5d10f4cb3e0567),
412 W64LIT(0xe427418ba77d95d8),
413 W64LIT(0xfbee7c66dd17479e),
414 W64LIT(0xca2dbf07ad5a8333)
418void Whirlpool::Transform(
word64 *digest,
const word64 *block)
423#if CRYPTOPP_SSE2_ASM_AVAILABLE
428 #if CRYPTOPP_BOOL_X64
435 AS2( mov AS_REG_6, WORD_REG(ax))
437 AS2( lea AS_REG_6, [Whirlpool_C])
438 AS2( mov WORD_REG(cx), digest)
439 AS2( mov WORD_REG(dx), block)
447 #define SSE2_workspace esp+WORD_SZ
450 #define SSE2_workspace %3
454 AS2( movq mm0, [WORD_REG(cx)+8*WORD_REG(si)])
455 AS2( movq [SSE2_workspace+8*WORD_REG(si)], mm0)
456 AS2( pxor mm0, [WORD_REG(dx)+8*WORD_REG(si)])
457 AS2( movq [SSE2_workspace+64+8*WORD_REG(si)], mm0)
458 AS2( movq [WORD_REG(cx)+8*WORD_REG(si)], mm0)
459 AS1( inc WORD_REG(si))
460 AS2( cmp WORD_REG(si), 8)
466#define KSL0(a, b) AS2(movq mm##a, b)
467#define KSL1(a, b) AS2(pxor mm##a, b)
469#define KSL(op, i, a, b, c, d) \
470 AS2(mov eax, [SSE2_workspace+8*i])\
472 KSL##op(a, [AS_REG_6+3*2048+8*WORD_REG(di)])\
474 KSL##op(b, [AS_REG_6+2*2048+8*WORD_REG(di)])\
478 KSL##op(c, [AS_REG_6+1*2048+8*WORD_REG(di)])\
479 KSL##op(d, [AS_REG_6+0*2048+8*WORD_REG(ax)])
482 ASS(pshufw mm##a, mm##a, 1, 0, 3, 2)\
488 AS2(movq [SSE2_workspace+8*a], mm##a)
490#define KSH(op, i, a, b, c, d) \
491 AS2(mov eax, [SSE2_workspace+8*((i+4)-8*((i+4)/8))+4])\
493 KSH##op(a, [AS_REG_6+3*2048+8*WORD_REG(di)])\
495 KSH##op(b, [AS_REG_6+2*2048+8*WORD_REG(di)])\
499 KSH##op(c, [AS_REG_6+1*2048+8*WORD_REG(di)])\
500 KSH##op(d, [AS_REG_6+0*2048+8*WORD_REG(ax)])
502#define TSL(op, i, a, b, c, d) \
503 AS2(mov eax, [SSE2_workspace+64+8*i])\
505 KSL##op(a, [AS_REG_6+3*2048+8*WORD_REG(di)])\
507 KSL##op(b, [AS_REG_6+2*2048+8*WORD_REG(di)])\
511 KSL##op(c, [AS_REG_6+1*2048+8*WORD_REG(di)])\
512 KSL##op(d, [AS_REG_6+0*2048+8*WORD_REG(ax)])
515 ASS(pshufw mm##a, mm##a, 1, 0, 3, 2)\
516 AS2(pxor mm##a, [SSE2_workspace+8*a])\
522 AS2(movq [SSE2_workspace+64+8*a], mm##a)
525 AS2(pxor mm##a, [WORD_REG(cx)+8*a])\
526 AS2(movq [WORD_REG(cx)+8*a], mm##a)
528#define TSH(op, i, a, b, c, d) \
529 AS2(mov eax, [SSE2_workspace+64+8*((i+4)-8*((i+4)/8))+4])\
531 TSH##op(a, [AS_REG_6+3*2048+8*WORD_REG(di)])\
533 TSH##op(b, [AS_REG_6+2*2048+8*WORD_REG(di)])\
537 TSH##op(c, [AS_REG_6+1*2048+8*WORD_REG(di)])\
538 TSH##op(d, [AS_REG_6+0*2048+8*WORD_REG(ax)])
540 KSL(0, 4, 3, 2, 1, 0)
541 KSL(0, 0, 7, 6, 5, 4)
542 KSL(1, 1, 0, 7, 6, 5)
543 KSL(1, 2, 1, 0, 7, 6)
544 KSL(1, 3, 2, 1, 0, 7)
545 KSL(1, 5, 4, 3, 2, 1)
546 KSL(1, 6, 5, 4, 3, 2)
547 KSL(1, 7, 6, 5, 4, 3)
548 KSH(0, 0, 7, 6, 5, 4)
549 KSH(0, 4, 3, 2, 1, 0)
550 KSH(1, 1, 0, 7, 6, 5)
551 KSH(1, 2, 1, 0, 7, 6)
552 KSH(1, 5, 4, 3, 2, 1)
553 KSH(1, 6, 5, 4, 3, 2)
554 KSH(2, 3, 2, 1, 0, 7)
555 KSH(2, 7, 6, 5, 4, 3)
557 AS2( pxor mm0, [AS_REG_6 + 8*1024 + WORD_REG(si)*8])
558 AS2( movq [SSE2_workspace], mm0)
560 TSL(0, 4, 3, 2, 1, 0)
561 TSL(0, 0, 7, 6, 5, 4)
562 TSL(1, 1, 0, 7, 6, 5)
563 TSL(1, 2, 1, 0, 7, 6)
564 TSL(1, 3, 2, 1, 0, 7)
565 TSL(1, 5, 4, 3, 2, 1)
566 TSL(1, 6, 5, 4, 3, 2)
567 TSL(1, 7, 6, 5, 4, 3)
568 TSH(0, 0, 7, 6, 5, 4)
569 TSH(0, 4, 3, 2, 1, 0)
570 TSH(1, 1, 0, 7, 6, 5)
571 TSH(1, 2, 1, 0, 7, 6)
572 TSH(1, 5, 4, 3, 2, 1)
573 TSH(1, 6, 5, 4, 3, 2)
575 AS1( inc WORD_REG(si))
576 AS2( cmp WORD_REG(si), 10)
579 TSH(2, 3, 2, 1, 0, 7)
580 TSH(2, 7, 6, 5, 4, 3)
585 TSH(3, 3, 2, 1, 0, 7)
586 TSH(3, 7, 6, 5, 4, 3)
602 :
"a" (Whirlpool_C),
"c" (digest),
"d" (block)
606 :
"%esi",
"%edi",
"memory",
"cc"
621 for (
int i=0; i<8; i++)
622 digest[i] = s[i] = block[i] ^ (k[i] = digest[i]);
624#define KSL(op, i, a, b, c, d) \
626 w##a = Whirlpool_C[3*256 + (byte)t] ^ (op ? w##a : 0);\
628 w##b = Whirlpool_C[2*256 + (byte)t] ^ (op ? w##b : 0);\
630 w##c = Whirlpool_C[1*256 + (byte)t] ^ (op ? w##c : 0);\
632 w##d = Whirlpool_C[0*256 + t] ^ (op ? w##d : 0);
634#define KSH(op, i, a, b, c, d) \
635 t = (word32)(k[(i+4)%8]>>32);\
636 w##a = Whirlpool_C[3*256 + (byte)t] ^ (op ? w##a : rotrConstant<32>(w##a));\
637 if (op==2) k[a] = w##a;\
639 w##b = Whirlpool_C[2*256 + (byte)t] ^ (op ? w##b : rotrConstant<32>(w##b));\
640 if (op==2) k[b] = w##b;\
642 w##c = Whirlpool_C[1*256 + (byte)t] ^ (op ? w##c : rotrConstant<32>(w##c));\
643 if (op==2) k[c] = w##c;\
645 w##d = Whirlpool_C[0*256 + t] ^ (op ? w##d : rotrConstant<32>(w##d));\
646 if (op==2) k[d] = w##d;\
648#define TSL(op, i, a, b, c, d) \
650 w##a = Whirlpool_C[3*256 + (byte)t] ^ (op ? w##a : 0);\
652 w##b = Whirlpool_C[2*256 + (byte)t] ^ (op ? w##b : 0);\
654 w##c = Whirlpool_C[1*256 + (byte)t] ^ (op ? w##c : 0);\
656 w##d = Whirlpool_C[0*256 + t] ^ (op ? w##d : 0);
658#define TSH_OP(op, a, b) \
659 w##a = Whirlpool_C[b*256 + (byte)t] ^ (op ? w##a : rotrConstant<32>(w##a) ^ k[a]);\
660 if (op==2) s[a] = w##a;\
661 if (op==3) digest[a] ^= w##a;\
663#define TSH(op, i, a, b, c, d) \
664 t = (word32)(s[(i+4)%8]>>32);\
678 word64 w0=0, w1=0, w2=0, w3=0, w4=0, w5=0, w6=0, w7=0;
681 KSL(0, 4, 3, 2, 1, 0)
682 KSL(0, 0, 7, 6, 5, 4)
683 KSL(1, 1, 0, 7, 6, 5)
684 KSL(1, 2, 1, 0, 7, 6)
685 KSL(1, 3, 2, 1, 0, 7)
686 KSL(1, 5, 4, 3, 2, 1)
687 KSL(1, 6, 5, 4, 3, 2)
688 KSL(1, 7, 6, 5, 4, 3)
689 KSH(0, 0, 7, 6, 5, 4)
690 KSH(0, 4, 3, 2, 1, 0)
691 KSH(1, 1, 0, 7, 6, 5)
692 KSH(1, 2, 1, 0, 7, 6)
693 KSH(1, 5, 4, 3, 2, 1)
694 KSH(1, 6, 5, 4, 3, 2)
695 KSH(2, 3, 2, 1, 0, 7)
696 KSH(2, 7, 6, 5, 4, 3)
698 k[0] ^= Whirlpool_C[1024+r];
700 TSL(0, 4, 3, 2, 1, 0)
701 TSL(0, 0, 7, 6, 5, 4)
702 TSL(1, 1, 0, 7, 6, 5)
703 TSL(1, 2, 1, 0, 7, 6)
704 TSL(1, 3, 2, 1, 0, 7)
705 TSL(1, 5, 4, 3, 2, 1)
706 TSL(1, 6, 5, 4, 3, 2)
707 TSL(1, 7, 6, 5, 4, 3)
708 TSH(0, 0, 7, 6, 5, 4)
709 TSH(0, 4, 3, 2, 1, 0)
710 TSH(1, 1, 0, 7, 6, 5)
711 TSH(1, 2, 1, 0, 7, 6)
712 TSH(1, 5, 4, 3, 2, 1)
713 TSH(1, 6, 5, 4, 3, 2)
717 TSH(2, 3, 2, 1, 0, 7)
718 TSH(2, 7, 6, 5, 4, 3)
722 TSH(3, 3, 2, 1, 0, 7)
723 TSH(3, 7, 6, 5, 4, 3)
Whirlpool message digest.
std::string AlgorithmProvider() const
The Whirlpool hashing function.
Library configuration file.
#define CRYPTOPP_BOOL_X86
32-bit x86 platform
#define CRYPTOPP_BOOL_X64
32-bit x86 platform
#define CRYPTOPP_TABLE
Override for internal linkage.
#define W64LIT(x)
Declare an unsigned word64.
unsigned int word32
32-bit unsigned datatype
unsigned long long word64
64-bit unsigned datatype
Functions for CPU features and intrinsics.
Utility functions for the Crypto++ library.
Crypto++ library namespace.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
Classes for the Whirlpool message digest.