aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/hash
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-09-16 14:45:17 -0400
committerJack Lloyd <[email protected]>2017-09-16 14:45:17 -0400
commitf39aa7bb4e43e27b10d3f890da7ba1acba9f14ca (patch)
tree44eb974c45b4c644c2932502962a6c403b00f8b4 /src/lib/hash
parent4c8b0316defbe9e6bfb3b3ce68c506b437760af0 (diff)
De-inline xor_buf, add SIMD and unrolling
Improves CBC and OCB performance with AES-NI quite noticably
Diffstat (limited to 'src/lib/hash')
-rw-r--r--src/lib/hash/streebog/streebog.cpp35
1 files changed, 24 insertions, 11 deletions
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<const uint64_t*>(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<const uint8_t*>(&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<uint8_t*>(&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<const uint64_t*>(m), 8);
+ const uint64_t* m64 = reinterpret_cast<const uint64_t*>(m);
+
+ e(hN, m64);
+
+ for(size_t i = 0; i != 8; ++i)
+ {
+ h[i] ^= hN[i] ^ m64[i];
+ }
}
} //namespace