Line | Count | Source (jump to first uncovered line) |
1 | | // blake2.cpp - written and placed in the public domain by Jeffrey Walton |
2 | | // and Zooko Wilcox-O'Hearn. Based on Aumasson, Neves, |
3 | | // Wilcox-O'Hearn and Winnerlein's reference BLAKE2 |
4 | | // implementation at http://github.com/BLAKE2/BLAKE2. |
5 | | // |
6 | | // The BLAKE2b and BLAKE2s numbers are consistent with the BLAKE2 team's |
7 | | // numbers. However, we have an Altivec implementation of BLAKE2s, |
8 | | // and a POWER8 implementation of BLAKE2b (BLAKE2 team is missing them). |
9 | | // Altivec code is about 2x faster than C++ when using GCC 5.0 or |
10 | | // above. The POWER8 code is about 2.5x faster than C++ when using GCC 5.0 |
11 | | // or above. If you use GCC 4.0 (PowerMac) or GCC 4.8 (GCC Compile Farm) |
12 | | // then the PowerPC code will be slower than C++. Be sure to use GCC 5.0 |
13 | | // or above for PowerPC builds or disable Altivec for BLAKE2b and BLAKE2s |
14 | | // if using the old compilers. |
15 | | |
16 | | #include "pch.h" |
17 | | #include "config.h" |
18 | | #include "cryptlib.h" |
19 | | #include "argnames.h" |
20 | | #include "algparam.h" |
21 | | #include "blake2.h" |
22 | | #include "cpu.h" |
23 | | |
24 | | // Uncomment for benchmarking C++ against SSE2 or NEON. |
25 | | // Do so in both blake2.cpp and blake2_simd.cpp. |
26 | | // #undef CRYPTOPP_SSE41_AVAILABLE |
27 | | // #undef CRYPTOPP_ARM_NEON_AVAILABLE |
28 | | // #undef CRYPTOPP_ALTIVEC_AVAILABLE |
29 | | // #undef CRYPTOPP_POWER8_AVAILABLE |
30 | | |
31 | | // Disable NEON/ASIMD for Cortex-A53 and A57. The shifts are too slow and C/C++ is about |
32 | | // 3 cpb faster than NEON/ASIMD. Also see http://github.com/weidai11/cryptopp/issues/367. |
33 | | #if (defined(__aarch32__) || defined(__aarch64__)) && defined(CRYPTOPP_SLOW_ARMV8_SHIFT) |
34 | | # undef CRYPTOPP_ARM_NEON_AVAILABLE |
35 | | #endif |
36 | | |
37 | | // BLAKE2s bug on AIX 7.1 (POWER7) with XLC 12.01 |
38 | | // https://github.com/weidai11/cryptopp/issues/743 |
39 | | #if defined(__xlC__) && (__xlC__ < 0x0d01) |
40 | | # define CRYPTOPP_DISABLE_ALTIVEC 1 |
41 | | # undef CRYPTOPP_POWER7_AVAILABLE |
42 | | # undef CRYPTOPP_POWER8_AVAILABLE |
43 | | # undef CRYPTOPP_ALTIVEC_AVAILABLE |
44 | | #endif |
45 | | |
46 | | // Can't use GetAlignmentOf<word64>() because of C++11 and constexpr |
47 | | // Can use 'const unsigned int' because of MSVC 2013 |
48 | | #if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64) |
49 | | # define ALIGN_SPEC32 16 |
50 | | # define ALIGN_SPEC64 16 |
51 | | #else |
52 | | # define ALIGN_SPEC32 4 |
53 | | # define ALIGN_SPEC64 8 |
54 | | #endif |
55 | | |
56 | | NAMESPACE_BEGIN(CryptoPP) |
57 | | |
58 | | // Export the tables to the SIMD files |
59 | | extern const word32 BLAKE2S_IV[8]; |
60 | | extern const word64 BLAKE2B_IV[8]; |
61 | | |
62 | | CRYPTOPP_ALIGN_DATA(ALIGN_SPEC32) |
63 | | const word32 BLAKE2S_IV[8] = { |
64 | | 0x6A09E667UL, 0xBB67AE85UL, 0x3C6EF372UL, 0xA54FF53AUL, |
65 | | 0x510E527FUL, 0x9B05688CUL, 0x1F83D9ABUL, 0x5BE0CD19UL |
66 | | }; |
67 | | |
68 | | CRYPTOPP_ALIGN_DATA(ALIGN_SPEC64) |
69 | | const word64 BLAKE2B_IV[8] = { |
70 | | W64LIT(0x6a09e667f3bcc908), W64LIT(0xbb67ae8584caa73b), |
71 | | W64LIT(0x3c6ef372fe94f82b), W64LIT(0xa54ff53a5f1d36f1), |
72 | | W64LIT(0x510e527fade682d1), W64LIT(0x9b05688c2b3e6c1f), |
73 | | W64LIT(0x1f83d9abfb41bd6b), W64LIT(0x5be0cd19137e2179) |
74 | | }; |
75 | | |
76 | | NAMESPACE_END |
77 | | |
78 | | ANONYMOUS_NAMESPACE_BEGIN |
79 | | |
80 | | using CryptoPP::byte; |
81 | | using CryptoPP::word32; |
82 | | using CryptoPP::word64; |
83 | | using CryptoPP::rotrConstant; |
84 | | |
85 | | CRYPTOPP_ALIGN_DATA(ALIGN_SPEC32) |
86 | | const byte BLAKE2S_SIGMA[10][16] = { |
87 | | { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, |
88 | | { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 }, |
89 | | { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 }, |
90 | | { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 }, |
91 | | { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 }, |
92 | | { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 }, |
93 | | { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 }, |
94 | | { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 }, |
95 | | { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 }, |
96 | | { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 }, |
97 | | }; |
98 | | |
99 | | CRYPTOPP_ALIGN_DATA(ALIGN_SPEC32) |
100 | | const byte BLAKE2B_SIGMA[12][16] = { |
101 | | { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, |
102 | | { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 }, |
103 | | { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 }, |
104 | | { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 }, |
105 | | { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 }, |
106 | | { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 }, |
107 | | { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 }, |
108 | | { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 }, |
109 | | { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 }, |
110 | | { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 }, |
111 | | { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, |
112 | | { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 } |
113 | | }; |
114 | | |
115 | | template <unsigned int R, unsigned int N> |
116 | | inline void BLAKE2B_G(const word64 m[16], word64& a, word64& b, word64& c, word64& d) |
117 | 0 | { |
118 | 0 | a = a + b + m[BLAKE2B_SIGMA[R][2*N+0]]; |
119 | 0 | d = rotrConstant<32>(d ^ a); |
120 | 0 | c = c + d; |
121 | 0 | b = rotrConstant<24>(b ^ c); |
122 | 0 | a = a + b + m[BLAKE2B_SIGMA[R][2*N+1]]; |
123 | 0 | d = rotrConstant<16>(d ^ a); |
124 | 0 | c = c + d; |
125 | 0 | b = rotrConstant<63>(b ^ c); |
126 | 0 | } Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<0u, 0u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<0u, 1u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<0u, 2u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<0u, 3u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<0u, 4u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<0u, 5u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<0u, 6u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<0u, 7u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<1u, 0u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<1u, 1u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<1u, 2u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<1u, 3u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<1u, 4u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<1u, 5u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<1u, 6u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<1u, 7u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<2u, 0u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<2u, 1u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<2u, 2u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<2u, 3u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<2u, 4u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<2u, 5u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<2u, 6u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<2u, 7u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<3u, 0u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<3u, 1u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<3u, 2u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<3u, 3u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<3u, 4u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<3u, 5u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<3u, 6u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<3u, 7u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<4u, 0u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<4u, 1u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<4u, 2u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<4u, 3u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<4u, 4u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<4u, 5u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<4u, 6u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<4u, 7u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<5u, 0u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<5u, 1u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<5u, 2u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<5u, 3u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<5u, 4u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<5u, 5u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<5u, 6u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<5u, 7u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<6u, 0u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<6u, 1u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<6u, 2u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<6u, 3u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<6u, 4u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<6u, 5u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<6u, 6u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<6u, 7u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<7u, 0u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<7u, 1u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<7u, 2u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<7u, 3u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<7u, 4u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<7u, 5u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<7u, 6u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<7u, 7u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<8u, 0u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<8u, 1u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<8u, 2u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<8u, 3u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<8u, 4u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<8u, 5u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<8u, 6u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<8u, 7u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<9u, 0u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<9u, 1u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<9u, 2u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<9u, 3u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<9u, 4u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<9u, 5u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<9u, 6u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<9u, 7u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<10u, 0u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<10u, 1u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<10u, 2u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<10u, 3u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<10u, 4u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<10u, 5u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<10u, 6u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<10u, 7u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<11u, 0u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<11u, 1u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<11u, 2u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<11u, 3u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<11u, 4u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<11u, 5u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<11u, 6u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_G<11u, 7u>(unsigned long const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&) |
127 | | |
128 | | template <unsigned int R> |
129 | | inline void BLAKE2B_ROUND(const word64 m[16], word64 v[16]) |
130 | 0 | { |
131 | 0 | BLAKE2B_G<R,0>(m,v[ 0],v[ 4],v[ 8],v[12]); |
132 | 0 | BLAKE2B_G<R,1>(m,v[ 1],v[ 5],v[ 9],v[13]); |
133 | 0 | BLAKE2B_G<R,2>(m,v[ 2],v[ 6],v[10],v[14]); |
134 | 0 | BLAKE2B_G<R,3>(m,v[ 3],v[ 7],v[11],v[15]); |
135 | 0 | BLAKE2B_G<R,4>(m,v[ 0],v[ 5],v[10],v[15]); |
136 | 0 | BLAKE2B_G<R,5>(m,v[ 1],v[ 6],v[11],v[12]); |
137 | 0 | BLAKE2B_G<R,6>(m,v[ 2],v[ 7],v[ 8],v[13]); |
138 | 0 | BLAKE2B_G<R,7>(m,v[ 3],v[ 4],v[ 9],v[14]); |
139 | 0 | } Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_ROUND<0u>(unsigned long const*, unsigned long*) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_ROUND<1u>(unsigned long const*, unsigned long*) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_ROUND<2u>(unsigned long const*, unsigned long*) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_ROUND<3u>(unsigned long const*, unsigned long*) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_ROUND<4u>(unsigned long const*, unsigned long*) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_ROUND<5u>(unsigned long const*, unsigned long*) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_ROUND<6u>(unsigned long const*, unsigned long*) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_ROUND<7u>(unsigned long const*, unsigned long*) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_ROUND<8u>(unsigned long const*, unsigned long*) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_ROUND<9u>(unsigned long const*, unsigned long*) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_ROUND<10u>(unsigned long const*, unsigned long*) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2B_ROUND<11u>(unsigned long const*, unsigned long*) |
140 | | |
141 | | template <unsigned int R, unsigned int N> |
142 | | inline void BLAKE2S_G(const word32 m[16], word32& a, word32& b, word32& c, word32& d) |
143 | 0 | { |
144 | 0 | a = a + b + m[BLAKE2S_SIGMA[R][2*N+0]]; |
145 | 0 | d = rotrConstant<16>(d ^ a); |
146 | 0 | c = c + d; |
147 | 0 | b = rotrConstant<12>(b ^ c); |
148 | 0 | a = a + b + m[BLAKE2S_SIGMA[R][2*N+1]]; |
149 | 0 | d = rotrConstant<8>(d ^ a); |
150 | 0 | c = c + d; |
151 | 0 | b = rotrConstant<7>(b ^ c); |
152 | 0 | } Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<0u, 0u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<0u, 1u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<0u, 2u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<0u, 3u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<0u, 4u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<0u, 5u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<0u, 6u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<0u, 7u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<1u, 0u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<1u, 1u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<1u, 2u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<1u, 3u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<1u, 4u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<1u, 5u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<1u, 6u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<1u, 7u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<2u, 0u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<2u, 1u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<2u, 2u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<2u, 3u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<2u, 4u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<2u, 5u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<2u, 6u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<2u, 7u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<3u, 0u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<3u, 1u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<3u, 2u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<3u, 3u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<3u, 4u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<3u, 5u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<3u, 6u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<3u, 7u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<4u, 0u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<4u, 1u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<4u, 2u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<4u, 3u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<4u, 4u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<4u, 5u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<4u, 6u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<4u, 7u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<5u, 0u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<5u, 1u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<5u, 2u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<5u, 3u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<5u, 4u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<5u, 5u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<5u, 6u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<5u, 7u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<6u, 0u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<6u, 1u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<6u, 2u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<6u, 3u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<6u, 4u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<6u, 5u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<6u, 6u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<6u, 7u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<7u, 0u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<7u, 1u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<7u, 2u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<7u, 3u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<7u, 4u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<7u, 5u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<7u, 6u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<7u, 7u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<8u, 0u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<8u, 1u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<8u, 2u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<8u, 3u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<8u, 4u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<8u, 5u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<8u, 6u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<8u, 7u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<9u, 0u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<9u, 1u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<9u, 2u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<9u, 3u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<9u, 4u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<9u, 5u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<9u, 6u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_G<9u, 7u>(unsigned int const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) |
153 | | |
154 | | template <unsigned int R> |
155 | | inline void BLAKE2S_ROUND(const word32 m[16], word32 v[]) |
156 | 0 | { |
157 | 0 | BLAKE2S_G<R,0>(m,v[ 0],v[ 4],v[ 8],v[12]); |
158 | 0 | BLAKE2S_G<R,1>(m,v[ 1],v[ 5],v[ 9],v[13]); |
159 | 0 | BLAKE2S_G<R,2>(m,v[ 2],v[ 6],v[10],v[14]); |
160 | 0 | BLAKE2S_G<R,3>(m,v[ 3],v[ 7],v[11],v[15]); |
161 | 0 | BLAKE2S_G<R,4>(m,v[ 0],v[ 5],v[10],v[15]); |
162 | 0 | BLAKE2S_G<R,5>(m,v[ 1],v[ 6],v[11],v[12]); |
163 | 0 | BLAKE2S_G<R,6>(m,v[ 2],v[ 7],v[ 8],v[13]); |
164 | 0 | BLAKE2S_G<R,7>(m,v[ 3],v[ 4],v[ 9],v[14]); |
165 | 0 | } Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_ROUND<0u>(unsigned int const*, unsigned int*) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_ROUND<1u>(unsigned int const*, unsigned int*) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_ROUND<2u>(unsigned int const*, unsigned int*) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_ROUND<3u>(unsigned int const*, unsigned int*) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_ROUND<4u>(unsigned int const*, unsigned int*) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_ROUND<5u>(unsigned int const*, unsigned int*) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_ROUND<6u>(unsigned int const*, unsigned int*) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_ROUND<7u>(unsigned int const*, unsigned int*) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_ROUND<8u>(unsigned int const*, unsigned int*) Unexecuted instantiation: blake2.cpp:void (anonymous namespace)::BLAKE2S_ROUND<9u>(unsigned int const*, unsigned int*) |
166 | | |
167 | | ANONYMOUS_NAMESPACE_END |
168 | | |
169 | | NAMESPACE_BEGIN(CryptoPP) |
170 | | |
171 | | void BLAKE2_Compress32_CXX(const byte* input, BLAKE2s_State& state); |
172 | | void BLAKE2_Compress64_CXX(const byte* input, BLAKE2b_State& state); |
173 | | |
174 | | #if CRYPTOPP_SSE41_AVAILABLE |
175 | | extern void BLAKE2_Compress32_SSE4(const byte* input, BLAKE2s_State& state); |
176 | | extern void BLAKE2_Compress64_SSE4(const byte* input, BLAKE2b_State& state); |
177 | | #endif |
178 | | |
179 | | #if CRYPTOPP_ARM_NEON_AVAILABLE |
180 | | extern void BLAKE2_Compress32_NEON(const byte* input, BLAKE2s_State& state); |
181 | | extern void BLAKE2_Compress64_NEON(const byte* input, BLAKE2b_State& state); |
182 | | #endif |
183 | | |
184 | | #if CRYPTOPP_ALTIVEC_AVAILABLE |
185 | | extern void BLAKE2_Compress32_ALTIVEC(const byte* input, BLAKE2s_State& state); |
186 | | #endif |
187 | | |
188 | | #if CRYPTOPP_POWER8_AVAILABLE |
189 | | extern void BLAKE2_Compress64_POWER8(const byte* input, BLAKE2b_State& state); |
190 | | #endif |
191 | | |
192 | | unsigned int BLAKE2b::OptimalDataAlignment() const |
193 | 0 | { |
194 | 0 | #if defined(CRYPTOPP_SSE41_AVAILABLE) |
195 | 0 | if (HasSSE41()) |
196 | 0 | return 16; // load __m128i |
197 | 0 | else |
198 | 0 | #endif |
199 | | #if (CRYPTOPP_ARM_NEON_AVAILABLE) |
200 | | if (HasNEON()) |
201 | | return 8; // load uint64x2_t |
202 | | else |
203 | | #endif |
204 | | #if (CRYPTOPP_POWER8_AVAILABLE) |
205 | | if (HasPower8()) |
206 | | return 16; // load vector long long |
207 | | else |
208 | | #endif |
209 | 0 | return GetAlignmentOf<word64>(); |
210 | 0 | } |
211 | | |
212 | | std::string BLAKE2b::AlgorithmProvider() const |
213 | 0 | { |
214 | 0 | #if defined(CRYPTOPP_SSE41_AVAILABLE) |
215 | 0 | if (HasSSE41()) |
216 | 0 | return "SSE4.1"; |
217 | 0 | else |
218 | 0 | #endif |
219 | | #if (CRYPTOPP_ARM_NEON_AVAILABLE) |
220 | | if (HasNEON()) |
221 | | return "NEON"; |
222 | | else |
223 | | #endif |
224 | | #if (CRYPTOPP_POWER8_AVAILABLE) |
225 | | if (HasPower8()) |
226 | | return "Power8"; |
227 | | else |
228 | | #endif |
229 | 0 | return "C++"; |
230 | 0 | } |
231 | | |
232 | | unsigned int BLAKE2s::OptimalDataAlignment() const |
233 | 0 | { |
234 | 0 | #if defined(CRYPTOPP_SSE41_AVAILABLE) |
235 | 0 | if (HasSSE41()) |
236 | 0 | return 16; // load __m128i |
237 | 0 | else |
238 | 0 | #endif |
239 | | #if (CRYPTOPP_ARM_NEON_AVAILABLE) |
240 | | if (HasNEON()) |
241 | | return 4; // load uint32x4_t |
242 | | else |
243 | | #endif |
244 | | #if (CRYPTOPP_ALTIVEC_AVAILABLE) |
245 | | if (HasAltivec()) |
246 | | return 16; // load vector unsigned int |
247 | | else |
248 | | #endif |
249 | 0 | return GetAlignmentOf<word32>(); |
250 | 0 | } |
251 | | |
252 | | std::string BLAKE2s::AlgorithmProvider() const |
253 | 0 | { |
254 | 0 | #if defined(CRYPTOPP_SSE41_AVAILABLE) |
255 | 0 | if (HasSSE41()) |
256 | 0 | return "SSE4.1"; |
257 | 0 | else |
258 | 0 | #endif |
259 | | #if (CRYPTOPP_ARM_NEON_AVAILABLE) |
260 | | if (HasNEON()) |
261 | | return "NEON"; |
262 | | else |
263 | | #endif |
264 | | #if (CRYPTOPP_ALTIVEC_AVAILABLE) |
265 | | if (HasAltivec()) |
266 | | return "Altivec"; |
267 | | else |
268 | | #endif |
269 | 0 | return "C++"; |
270 | 0 | } |
271 | | |
272 | | void BLAKE2s_State::Reset() |
273 | 20.9k | { |
274 | 20.9k | std::memset(m_hft, 0x00, m_hft.SizeInBytes()); |
275 | 20.9k | m_len = 0; |
276 | 20.9k | } |
277 | | |
278 | | void BLAKE2b_State::Reset() |
279 | 11.4k | { |
280 | 11.4k | std::memset(m_hft, 0x00, m_hft.SizeInBytes()); |
281 | 11.4k | m_len = 0; |
282 | 11.4k | } |
283 | | |
284 | | BLAKE2s_ParameterBlock::BLAKE2s_ParameterBlock(size_t digestLen, size_t keyLen, |
285 | | const byte* saltStr, size_t saltLen, |
286 | | const byte* personalizationStr, size_t personalizationLen) |
287 | 0 | { |
288 | 0 | Reset(digestLen, keyLen); |
289 | |
|
290 | 0 | if (saltStr && saltLen) |
291 | 0 | memcpy_s(salt(), SALTSIZE, saltStr, saltLen); |
292 | |
|
293 | 0 | if (personalizationStr && personalizationLen) |
294 | 0 | memcpy_s(personalization(), PERSONALIZATIONSIZE, personalizationStr, personalizationLen); |
295 | 0 | } |
296 | | |
297 | | BLAKE2b_ParameterBlock::BLAKE2b_ParameterBlock(size_t digestLen, size_t keyLen, |
298 | | const byte* saltStr, size_t saltLen, |
299 | | const byte* personalizationStr, size_t personalizationLen) |
300 | 0 | { |
301 | 0 | Reset(digestLen, keyLen); |
302 | |
|
303 | 0 | if (saltStr && saltLen) |
304 | 0 | memcpy_s(salt(), SALTSIZE, saltStr, saltLen); |
305 | |
|
306 | 0 | if (personalizationStr && personalizationLen) |
307 | 0 | memcpy_s(personalization(), PERSONALIZATIONSIZE, personalizationStr, personalizationLen); |
308 | 0 | } |
309 | | |
310 | | void BLAKE2s_ParameterBlock::Reset(size_t digestLen, size_t keyLen) |
311 | 710 | { |
312 | 710 | std::memset(m_data, 0x00, m_data.size()); |
313 | 710 | m_data[DigestOff] = static_cast<byte>(digestLen); |
314 | 710 | m_data[KeyOff] = static_cast<byte>(keyLen); |
315 | 710 | m_data[FanoutOff] = m_data[DepthOff] = 1; |
316 | 710 | } |
317 | | |
318 | | void BLAKE2b_ParameterBlock::Reset(size_t digestLen, size_t keyLen) |
319 | 738 | { |
320 | 738 | std::memset(m_data, 0x00, m_data.size()); |
321 | 738 | m_data[DigestOff] = static_cast<byte>(digestLen); |
322 | 738 | m_data[KeyOff] = static_cast<byte>(keyLen); |
323 | 738 | m_data[FanoutOff] = m_data[DepthOff] = 1; |
324 | 738 | } |
325 | | |
326 | | BLAKE2s::BLAKE2s(bool treeMode, unsigned int digestSize) |
327 | | : m_digestSize(digestSize), m_keyLength(0), m_treeMode(treeMode) |
328 | 355 | { |
329 | 355 | CRYPTOPP_ASSERT(digestSize <= DIGESTSIZE); |
330 | | |
331 | 355 | UncheckedSetKey(NULLPTR, 0, MakeParameters |
332 | 355 | (Name::DigestSize(), (int)digestSize) |
333 | 355 | (Name::TreeMode(), treeMode)); |
334 | 355 | } |
335 | | |
336 | | BLAKE2b::BLAKE2b(bool treeMode, unsigned int digestSize) |
337 | | : m_digestSize(digestSize), m_keyLength(0), m_treeMode(treeMode) |
338 | 369 | { |
339 | 369 | CRYPTOPP_ASSERT(digestSize <= DIGESTSIZE); |
340 | | |
341 | 369 | UncheckedSetKey(NULLPTR, 0, MakeParameters |
342 | 369 | (Name::DigestSize(), (int)digestSize) |
343 | 369 | (Name::TreeMode(), treeMode)); |
344 | 369 | } |
345 | | |
346 | | BLAKE2s::BLAKE2s(unsigned int digestSize) |
347 | | : m_digestSize(digestSize), m_keyLength(0), m_treeMode(false) |
348 | 0 | { |
349 | 0 | CRYPTOPP_ASSERT(digestSize <= DIGESTSIZE); |
350 | |
|
351 | 0 | UncheckedSetKey(NULLPTR, 0, MakeParameters |
352 | 0 | (Name::DigestSize(), (int)digestSize) |
353 | 0 | (Name::TreeMode(), false)); |
354 | 0 | } |
355 | | |
356 | | BLAKE2b::BLAKE2b(unsigned int digestSize) |
357 | | : m_digestSize(digestSize), m_keyLength(0), m_treeMode(false) |
358 | 0 | { |
359 | 0 | CRYPTOPP_ASSERT(digestSize <= DIGESTSIZE); |
360 | |
|
361 | 0 | UncheckedSetKey(NULLPTR, 0, MakeParameters |
362 | 0 | (Name::DigestSize(), (int)digestSize) |
363 | 0 | (Name::TreeMode(), false)); |
364 | 0 | } |
365 | | |
366 | | BLAKE2s::BLAKE2s(const byte *key, size_t keyLength, const byte* salt, size_t saltLength, |
367 | | const byte* personalization, size_t personalizationLength, bool treeMode, unsigned int digestSize) |
368 | | : m_digestSize(digestSize), m_keyLength(static_cast<unsigned int>(keyLength)), m_treeMode(treeMode) |
369 | 0 | { |
370 | 0 | CRYPTOPP_ASSERT(keyLength <= MAX_KEYLENGTH); |
371 | 0 | CRYPTOPP_ASSERT(digestSize <= DIGESTSIZE); |
372 | 0 | CRYPTOPP_ASSERT(saltLength <= SALTSIZE); |
373 | 0 | CRYPTOPP_ASSERT(personalizationLength <= PERSONALIZATIONSIZE); |
374 | |
|
375 | 0 | UncheckedSetKey(key, static_cast<unsigned int>(keyLength), MakeParameters |
376 | 0 | (Name::DigestSize(),(int)digestSize) |
377 | 0 | (Name::TreeMode(),treeMode) |
378 | 0 | (Name::Salt(), ConstByteArrayParameter(salt, saltLength)) |
379 | 0 | (Name::Personalization(), ConstByteArrayParameter(personalization, personalizationLength))); |
380 | 0 | } |
381 | | |
382 | | BLAKE2b::BLAKE2b(const byte *key, size_t keyLength, const byte* salt, size_t saltLength, |
383 | | const byte* personalization, size_t personalizationLength, bool treeMode, unsigned int digestSize) |
384 | | : m_digestSize(digestSize), m_keyLength(static_cast<unsigned int>(keyLength)), m_treeMode(treeMode) |
385 | 0 | { |
386 | 0 | CRYPTOPP_ASSERT(keyLength <= MAX_KEYLENGTH); |
387 | 0 | CRYPTOPP_ASSERT(digestSize <= DIGESTSIZE); |
388 | 0 | CRYPTOPP_ASSERT(saltLength <= SALTSIZE); |
389 | 0 | CRYPTOPP_ASSERT(personalizationLength <= PERSONALIZATIONSIZE); |
390 | |
|
391 | 0 | UncheckedSetKey(key, static_cast<unsigned int>(keyLength), MakeParameters |
392 | 0 | (Name::DigestSize(),(int)digestSize) |
393 | 0 | (Name::TreeMode(),treeMode) |
394 | 0 | (Name::Salt(), ConstByteArrayParameter(salt, saltLength)) |
395 | 0 | (Name::Personalization(), ConstByteArrayParameter(personalization, personalizationLength))); |
396 | 0 | } |
397 | | |
398 | | void BLAKE2s::UncheckedSetKey(const byte *key, unsigned int length, const CryptoPP::NameValuePairs& params) |
399 | 355 | { |
400 | 355 | if (key && length) |
401 | 0 | { |
402 | 0 | m_key.New(BLOCKSIZE); |
403 | 0 | std::memcpy(m_key, key, length); |
404 | 0 | std::memset(m_key + length, 0x00, BLOCKSIZE - length); |
405 | 0 | m_keyLength = length; |
406 | 0 | } |
407 | 355 | else |
408 | 355 | { |
409 | 355 | m_key.resize(0); |
410 | 355 | m_keyLength = 0; |
411 | 355 | } |
412 | | |
413 | 355 | m_digestSize = static_cast<unsigned int>(params.GetIntValueWithDefault( |
414 | 355 | Name::DigestSize(), static_cast<int>(m_digestSize))); |
415 | | |
416 | 355 | m_state.Reset(); |
417 | 355 | m_block.Reset(m_digestSize, m_keyLength); |
418 | 355 | (void)params.GetValue(Name::TreeMode(), m_treeMode); |
419 | | |
420 | 355 | ConstByteArrayParameter t; |
421 | 355 | if (params.GetValue(Name::Salt(), t) && t.begin() && t.size()) |
422 | 0 | memcpy_s(m_block.salt(), SALTSIZE, t.begin(), t.size()); |
423 | | |
424 | 355 | if (params.GetValue(Name::Personalization(), t) && t.begin() && t.size()) |
425 | 0 | memcpy_s(m_block.personalization(), PERSONALIZATIONSIZE, t.begin(), t.size()); |
426 | | |
427 | 355 | Restart(); |
428 | 355 | } |
429 | | |
430 | | void BLAKE2b::UncheckedSetKey(const byte *key, unsigned int length, const CryptoPP::NameValuePairs& params) |
431 | 369 | { |
432 | 369 | if (key && length) |
433 | 0 | { |
434 | 0 | m_key.New(BLOCKSIZE); |
435 | 0 | std::memcpy(m_key, key, length); |
436 | 0 | std::memset(m_key + length, 0x00, BLOCKSIZE - length); |
437 | 0 | m_keyLength = length; |
438 | 0 | } |
439 | 369 | else |
440 | 369 | { |
441 | 369 | m_key.resize(0); |
442 | 369 | m_keyLength = 0; |
443 | 369 | } |
444 | | |
445 | 369 | m_digestSize = static_cast<unsigned int>(params.GetIntValueWithDefault( |
446 | 369 | Name::DigestSize(), static_cast<int>(m_digestSize))); |
447 | | |
448 | 369 | m_state.Reset(); |
449 | 369 | m_block.Reset(m_digestSize, m_keyLength); |
450 | 369 | (void)params.GetValue(Name::TreeMode(), m_treeMode); |
451 | | |
452 | 369 | ConstByteArrayParameter t; |
453 | 369 | if (params.GetValue(Name::Salt(), t) && t.begin() && t.size()) |
454 | 0 | memcpy_s(m_block.salt(), SALTSIZE, t.begin(), t.size()); |
455 | | |
456 | 369 | if (params.GetValue(Name::Personalization(), t) && t.begin() && t.size()) |
457 | 0 | memcpy_s(m_block.personalization(), PERSONALIZATIONSIZE, t.begin(), t.size()); |
458 | | |
459 | 369 | Restart(); |
460 | 369 | } |
461 | | |
462 | | void BLAKE2s::Restart() |
463 | 20.2k | { |
464 | 20.2k | static const word32 zero[2] = {0,0}; |
465 | 20.2k | Restart(m_block, zero); |
466 | 20.2k | } |
467 | | |
468 | | void BLAKE2b::Restart() |
469 | 10.7k | { |
470 | 10.7k | static const word64 zero[2] = {0,0}; |
471 | 10.7k | Restart(m_block, zero); |
472 | 10.7k | } |
473 | | |
474 | | void BLAKE2s::Restart(const BLAKE2s_ParameterBlock& block, const word32 counter[2]) |
475 | 20.2k | { |
476 | | // We take a counter as a parameter to allow customized state. |
477 | 20.2k | m_state.Reset(); |
478 | 20.2k | if (counter != NULLPTR) |
479 | 20.2k | { |
480 | 20.2k | word32* t = m_state.t(); |
481 | 20.2k | t[0] = counter[0]; |
482 | 20.2k | t[1] = counter[1]; |
483 | 20.2k | } |
484 | | |
485 | | // We take a parameter block as a parameter to allow customized state. |
486 | | // Avoid the copy of the parameter block when we are passing our own block. |
487 | 20.2k | if (block.data() != m_block.data()) { |
488 | 0 | std::memcpy(m_block.data(), block.data(), m_block.size()); |
489 | 0 | } |
490 | | |
491 | 20.2k | m_block.m_data[BLAKE2s_ParameterBlock::DigestOff] = (byte)m_digestSize; |
492 | 20.2k | m_block.m_data[BLAKE2s_ParameterBlock::KeyOff] = (byte)m_keyLength; |
493 | | |
494 | 20.2k | const word32* iv = BLAKE2S_IV; |
495 | 20.2k | PutBlock<word32, LittleEndian, true> put(m_block.data(), m_state.h()); |
496 | 20.2k | put(iv[0])(iv[1])(iv[2])(iv[3])(iv[4])(iv[5])(iv[6])(iv[7]); |
497 | | |
498 | | // When BLAKE2 is keyed, the input stream is simply {key || 0 || message}. |
499 | | // The key is padded to a full Blocksize with 0. Key it during Restart to |
500 | | // avoid FirstPut and friends. Key size == 0 means no key. |
501 | 20.2k | if (m_keyLength) |
502 | 0 | Update(m_key, BLOCKSIZE); |
503 | 20.2k | } |
504 | | |
505 | | void BLAKE2b::Restart(const BLAKE2b_ParameterBlock& block, const word64 counter[2]) |
506 | 10.7k | { |
507 | | // We take a counter as a parameter to allow customized state. |
508 | 10.7k | m_state.Reset(); |
509 | 10.7k | if (counter != NULLPTR) |
510 | 10.7k | { |
511 | 10.7k | word64* t = m_state.t(); |
512 | 10.7k | t[0] = counter[0]; |
513 | 10.7k | t[1] = counter[1]; |
514 | 10.7k | } |
515 | | |
516 | | // We take a parameter block as a parameter to allow customized state. |
517 | | // Avoid the copy of the parameter block when we are passing our own block. |
518 | 10.7k | if (block.data() != m_block.data()) { |
519 | 0 | std::memcpy(m_block.data(), block.data(), m_block.size()); |
520 | 0 | } |
521 | | |
522 | 10.7k | m_block.m_data[BLAKE2b_ParameterBlock::DigestOff] = (byte)m_digestSize; |
523 | 10.7k | m_block.m_data[BLAKE2b_ParameterBlock::KeyOff] = (byte)m_keyLength; |
524 | | |
525 | 10.7k | const word64* iv = BLAKE2B_IV; |
526 | 10.7k | PutBlock<word64, LittleEndian, true> put(m_block.data(), m_state.h()); |
527 | 10.7k | put(iv[0])(iv[1])(iv[2])(iv[3])(iv[4])(iv[5])(iv[6])(iv[7]); |
528 | | |
529 | | // When BLAKE2 is keyed, the input stream is simply {key || 0 || message}. |
530 | | // The key is padded to a full Blocksize with 0. Key it during Restart to |
531 | | // avoid FirstPut and friends. Key size == 0 means no key. |
532 | 10.7k | if (m_keyLength) |
533 | 0 | Update(m_key, BLOCKSIZE); |
534 | 10.7k | } |
535 | | |
536 | | void BLAKE2s::Update(const byte *input, size_t length) |
537 | 76.9k | { |
538 | 76.9k | CRYPTOPP_ASSERT(input != NULLPTR || length == 0); |
539 | | |
540 | 76.9k | if (length > BLOCKSIZE - m_state.m_len) |
541 | 21.1k | { |
542 | 21.1k | if (m_state.m_len != 0) |
543 | 19.4k | { |
544 | | // Complete current block |
545 | 19.4k | const size_t fill = BLOCKSIZE - m_state.m_len; |
546 | 19.4k | std::memcpy(m_state.m_buf+m_state.m_len, input, fill); |
547 | | |
548 | 19.4k | IncrementCounter(BLOCKSIZE); |
549 | 19.4k | Compress(m_state.m_buf); |
550 | 19.4k | m_state.m_len = 0; |
551 | | |
552 | 19.4k | length -= fill, input += fill; |
553 | 19.4k | } |
554 | | |
555 | | // Compress in-place to avoid copies |
556 | 462k | while (length > BLOCKSIZE) |
557 | 441k | { |
558 | 441k | IncrementCounter(BLOCKSIZE); |
559 | 441k | Compress(input); |
560 | 441k | length -= BLOCKSIZE, input += BLOCKSIZE; |
561 | 441k | } |
562 | 21.1k | } |
563 | | |
564 | | // Copy tail bytes |
565 | 76.9k | if (length) |
566 | 48.9k | { |
567 | 48.9k | CRYPTOPP_ASSERT(length <= BLOCKSIZE - m_state.m_len); |
568 | 48.9k | std::memcpy(m_state.m_buf+m_state.m_len, input, length); |
569 | 48.9k | m_state.m_len += static_cast<unsigned int>(length); |
570 | 48.9k | } |
571 | 76.9k | } |
572 | | |
573 | | void BLAKE2b::Update(const byte *input, size_t length) |
574 | 51.9k | { |
575 | 51.9k | CRYPTOPP_ASSERT(input != NULLPTR || length == 0); |
576 | | |
577 | 51.9k | if (length > BLOCKSIZE - m_state.m_len) |
578 | 11.9k | { |
579 | 11.9k | if (m_state.m_len != 0) |
580 | 10.6k | { |
581 | | // Complete current block |
582 | 10.6k | const size_t fill = BLOCKSIZE - m_state.m_len; |
583 | 10.6k | std::memcpy(m_state.m_buf+m_state.m_len, input, fill); |
584 | | |
585 | 10.6k | IncrementCounter(BLOCKSIZE); |
586 | 10.6k | Compress(m_state.m_buf); |
587 | 10.6k | m_state.m_len = 0; |
588 | | |
589 | 10.6k | length -= fill, input += fill; |
590 | 10.6k | } |
591 | | |
592 | | // Compress in-place to avoid copies |
593 | 194k | while (length > BLOCKSIZE) |
594 | 182k | { |
595 | 182k | CRYPTOPP_ASSERT(m_state.m_len == 0); |
596 | 182k | IncrementCounter(BLOCKSIZE); |
597 | 182k | Compress(input); |
598 | 182k | length -= BLOCKSIZE, input += BLOCKSIZE; |
599 | 182k | } |
600 | 11.9k | } |
601 | | |
602 | | // Copy tail bytes |
603 | 51.9k | if (length) |
604 | 25.8k | { |
605 | 25.8k | CRYPTOPP_ASSERT(length <= BLOCKSIZE - m_state.m_len); |
606 | 25.8k | std::memcpy(m_state.m_buf + m_state.m_len, input, length); |
607 | 25.8k | m_state.m_len += static_cast<unsigned int>(length); |
608 | 25.8k | } |
609 | 51.9k | } |
610 | | |
611 | | void BLAKE2s::TruncatedFinal(byte *hash, size_t size) |
612 | 19.8k | { |
613 | 19.8k | CRYPTOPP_ASSERT(hash != NULLPTR); |
614 | 19.8k | this->ThrowIfInvalidTruncatedSize(size); |
615 | 19.8k | word32* f = m_state.f(); |
616 | | |
617 | | // Set last block unconditionally |
618 | 19.8k | f[0] = ~static_cast<word32>(0); |
619 | | |
620 | | // Set last node if tree mode |
621 | 19.8k | if (m_treeMode) |
622 | 0 | f[1] = ~static_cast<word32>(0); |
623 | | |
624 | | // Increment counter for tail bytes only |
625 | 19.8k | IncrementCounter(m_state.m_len); |
626 | | |
627 | 19.8k | std::memset(m_state.m_buf + m_state.m_len, 0x00, BLOCKSIZE - m_state.m_len); |
628 | 19.8k | Compress(m_state.m_buf); |
629 | | |
630 | | // Copy to caller buffer |
631 | 19.8k | std::memcpy(hash, m_state.h(), size); |
632 | | |
633 | 19.8k | Restart(); |
634 | 19.8k | } |
635 | | |
636 | | void BLAKE2b::TruncatedFinal(byte *hash, size_t size) |
637 | 10.3k | { |
638 | 10.3k | CRYPTOPP_ASSERT(hash != NULLPTR); |
639 | 10.3k | this->ThrowIfInvalidTruncatedSize(size); |
640 | 10.3k | word64* f = m_state.f(); |
641 | | |
642 | | // Set last block unconditionally |
643 | 10.3k | f[0] = ~static_cast<word64>(0); |
644 | | |
645 | | // Set last node if tree mode |
646 | 10.3k | if (m_treeMode) |
647 | 0 | f[1] = ~static_cast<word64>(0); |
648 | | |
649 | | // Increment counter for tail bytes only |
650 | 10.3k | IncrementCounter(m_state.m_len); |
651 | | |
652 | 10.3k | std::memset(m_state.m_buf + m_state.m_len, 0x00, BLOCKSIZE - m_state.m_len); |
653 | 10.3k | Compress(m_state.m_buf); |
654 | | |
655 | | // Copy to caller buffer |
656 | 10.3k | std::memcpy(hash, m_state.h(), size); |
657 | | |
658 | 10.3k | Restart(); |
659 | 10.3k | } |
660 | | |
661 | | void BLAKE2s::IncrementCounter(size_t count) |
662 | 480k | { |
663 | 480k | word32* t = m_state.t(); |
664 | 480k | t[0] += static_cast<word32>(count); |
665 | 480k | t[1] += !!(t[0] < count); |
666 | 480k | } |
667 | | |
668 | | void BLAKE2b::IncrementCounter(size_t count) |
669 | 204k | { |
670 | 204k | word64* t = m_state.t(); |
671 | 204k | t[0] += static_cast<word64>(count); |
672 | 204k | t[1] += !!(t[0] < count); |
673 | 204k | } |
674 | | |
675 | | void BLAKE2s::Compress(const byte *input) |
676 | 480k | { |
677 | 480k | #if CRYPTOPP_SSE41_AVAILABLE |
678 | 480k | if(HasSSE41()) |
679 | 480k | { |
680 | 480k | return BLAKE2_Compress32_SSE4(input, m_state); |
681 | 480k | } |
682 | 0 | #endif |
683 | | #if CRYPTOPP_ARM_NEON_AVAILABLE |
684 | | if(HasNEON()) |
685 | | { |
686 | | return BLAKE2_Compress32_NEON(input, m_state); |
687 | | } |
688 | | #endif |
689 | | #if CRYPTOPP_ALTIVEC_AVAILABLE |
690 | | if(HasAltivec()) |
691 | | { |
692 | | return BLAKE2_Compress32_ALTIVEC(input, m_state); |
693 | | } |
694 | | #endif |
695 | 0 | return BLAKE2_Compress32_CXX(input, m_state); |
696 | 480k | } |
697 | | |
698 | | void BLAKE2b::Compress(const byte *input) |
699 | 204k | { |
700 | 204k | #if CRYPTOPP_SSE41_AVAILABLE |
701 | 204k | if(HasSSE41()) |
702 | 204k | { |
703 | 204k | return BLAKE2_Compress64_SSE4(input, m_state); |
704 | 204k | } |
705 | 0 | #endif |
706 | | #if CRYPTOPP_ARM_NEON_AVAILABLE |
707 | | if(HasNEON()) |
708 | | { |
709 | | return BLAKE2_Compress64_NEON(input, m_state); |
710 | | } |
711 | | #endif |
712 | | #if CRYPTOPP_POWER8_AVAILABLE |
713 | | if(HasPower8()) |
714 | | { |
715 | | return BLAKE2_Compress64_POWER8(input, m_state); |
716 | | } |
717 | | #endif |
718 | 0 | return BLAKE2_Compress64_CXX(input, m_state); |
719 | 204k | } |
720 | | |
721 | | void BLAKE2_Compress64_CXX(const byte* input, BLAKE2b_State& state) |
722 | 0 | { |
723 | 0 | word64 m[16], v[16]; |
724 | |
|
725 | 0 | GetBlock<word64, LittleEndian, true> get1(input); |
726 | 0 | get1(m[0])(m[1])(m[2])(m[3])(m[4])(m[5])(m[6])(m[7])(m[8])(m[9])(m[10])(m[11])(m[12])(m[13])(m[14])(m[15]); |
727 | |
|
728 | 0 | GetBlock<word64, LittleEndian, true> get2(state.h()); |
729 | 0 | get2(v[0])(v[1])(v[2])(v[3])(v[4])(v[5])(v[6])(v[7]); |
730 | |
|
731 | 0 | const word64* iv = BLAKE2B_IV; |
732 | 0 | const word64* tf = state.t(); |
733 | 0 | v[ 8] = iv[0]; |
734 | 0 | v[ 9] = iv[1]; |
735 | 0 | v[10] = iv[2]; |
736 | 0 | v[11] = iv[3]; |
737 | 0 | v[12] = tf[0] ^ iv[4]; |
738 | 0 | v[13] = tf[1] ^ iv[5]; |
739 | 0 | v[14] = tf[2] ^ iv[6]; |
740 | 0 | v[15] = tf[3] ^ iv[7]; |
741 | |
|
742 | 0 | BLAKE2B_ROUND<0>(m, v); |
743 | 0 | BLAKE2B_ROUND<1>(m, v); |
744 | 0 | BLAKE2B_ROUND<2>(m, v); |
745 | 0 | BLAKE2B_ROUND<3>(m, v); |
746 | 0 | BLAKE2B_ROUND<4>(m, v); |
747 | 0 | BLAKE2B_ROUND<5>(m, v); |
748 | 0 | BLAKE2B_ROUND<6>(m, v); |
749 | 0 | BLAKE2B_ROUND<7>(m, v); |
750 | 0 | BLAKE2B_ROUND<8>(m, v); |
751 | 0 | BLAKE2B_ROUND<9>(m, v); |
752 | 0 | BLAKE2B_ROUND<10>(m, v); |
753 | 0 | BLAKE2B_ROUND<11>(m, v); |
754 | |
|
755 | 0 | word64* h = state.h(); |
756 | 0 | for (unsigned int i = 0; i < 8; ++i) |
757 | 0 | h[i] = h[i] ^ ConditionalByteReverse(LITTLE_ENDIAN_ORDER, v[i] ^ v[i + 8]); |
758 | 0 | } |
759 | | |
760 | | void BLAKE2_Compress32_CXX(const byte* input, BLAKE2s_State& state) |
761 | 0 | { |
762 | 0 | word32 m[16], v[16]; |
763 | |
|
764 | 0 | GetBlock<word32, LittleEndian, true> get1(input); |
765 | 0 | get1(m[0])(m[1])(m[2])(m[3])(m[4])(m[5])(m[6])(m[7])(m[8])(m[9])(m[10])(m[11])(m[12])(m[13])(m[14])(m[15]); |
766 | |
|
767 | 0 | GetBlock<word32, LittleEndian, true> get2(state.h()); |
768 | 0 | get2(v[0])(v[1])(v[2])(v[3])(v[4])(v[5])(v[6])(v[7]); |
769 | |
|
770 | 0 | const word32* iv = BLAKE2S_IV; |
771 | 0 | const word32* tf = state.t(); |
772 | 0 | v[ 8] = iv[0]; |
773 | 0 | v[ 9] = iv[1]; |
774 | 0 | v[10] = iv[2]; |
775 | 0 | v[11] = iv[3]; |
776 | 0 | v[12] = tf[0] ^ iv[4]; |
777 | 0 | v[13] = tf[1] ^ iv[5]; |
778 | 0 | v[14] = tf[2] ^ iv[6]; |
779 | 0 | v[15] = tf[3] ^ iv[7]; |
780 | |
|
781 | 0 | BLAKE2S_ROUND<0>(m, v); |
782 | 0 | BLAKE2S_ROUND<1>(m, v); |
783 | 0 | BLAKE2S_ROUND<2>(m, v); |
784 | 0 | BLAKE2S_ROUND<3>(m, v); |
785 | 0 | BLAKE2S_ROUND<4>(m, v); |
786 | 0 | BLAKE2S_ROUND<5>(m, v); |
787 | 0 | BLAKE2S_ROUND<6>(m, v); |
788 | 0 | BLAKE2S_ROUND<7>(m, v); |
789 | 0 | BLAKE2S_ROUND<8>(m, v); |
790 | 0 | BLAKE2S_ROUND<9>(m, v); |
791 | |
|
792 | 0 | word32* h = state.h(); |
793 | 0 | for (unsigned int i = 0; i < 8; ++i) |
794 | 0 | h[i] = h[i] ^ ConditionalByteReverse(LITTLE_ENDIAN_ORDER, v[i] ^ v[i + 8]); |
795 | 0 | } |
796 | | |
797 | | NAMESPACE_END |