From f39aa7bb4e43e27b10d3f890da7ba1acba9f14ca Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Sat, 16 Sep 2017 14:45:17 -0400 Subject: De-inline xor_buf, add SIMD and unrolling Improves CBC and OCB performance with AES-NI quite noticably --- src/lib/hash/streebog/streebog.cpp | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'src/lib/hash') diff --git a/src/lib/hash/streebog/streebog.cpp b/src/lib/hash/streebog/streebog.cpp index ae2fe1fef..c0e60f10a 100644 --- a/src/lib/hash/streebog/streebog.cpp +++ b/src/lib/hash/streebog/streebog.cpp @@ -53,20 +53,28 @@ inline void lps(uint64_t* block) } } -inline void e(uint64_t* K, const uint8_t* m) +inline void e(uint64_t* K, const uint64_t* m) { - uint64_t tmp[8]; + uint64_t A[8]; uint64_t C[8]; - std::memcpy(tmp, K, 64); - xor_buf(K, reinterpret_cast(m), 8); + copy_mem(A, K, 8); + + for(size_t i = 0; i != 8; ++i) + { + K[i] ^= m[i]; + } + for(int i = 0; i < 12; ++i) { lps(K); load_le(C, reinterpret_cast(&STREEBOG_C[i][0]), 8); - xor_buf(tmp, C, 8); - lps(tmp); - xor_buf(K, tmp, 8); + + for(size_t i = 0; i != 8; ++i) + A[i] ^= C[i]; + lps(A); + for(size_t i = 0; i != 8; ++i) + K[i] ^= A[i]; } } @@ -77,12 +85,17 @@ inline void g(uint64_t* h, const uint8_t* m, uint64_t N) // force N to little-endian store_le(N, reinterpret_cast(&N)); - std::memcpy(hN, h, 64); + copy_mem(hN, h, 8); hN[0] ^= N; lps(hN); - e(hN, m); - xor_buf(h, hN, 8); - xor_buf(h, reinterpret_cast(m), 8); + const uint64_t* m64 = reinterpret_cast(m); + + e(hN, m64); + + for(size_t i = 0; i != 8; ++i) + { + h[i] ^= hN[i] ^ m64[i]; + } } } //namespace -- cgit v1.2.3