aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/block/aria
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-10-11 17:02:20 -0400
committerJack Lloyd <[email protected]>2017-10-12 11:13:11 -0400
commit175f09ffd806f2f19cd509017a67ae1384f29ae1 (patch)
tree6194884467e4720dd79797cd106a45d60211f35f /src/lib/block/aria
parent40b3f979723b2b3dfb5c44047d7f786a73fd7f6f (diff)
Add compile-time rotation functions
The problem with asm rol/ror is the compiler can't schedule effectively. But we only need asm in the case when the rotation is variable, so distinguish the two cases. If a compile time constant, then static_assert that the rotation is in the correct range and do the straightforward expression knowing the compiler will probably do the right thing. Otherwise do a tricky expression that both GCC and Clang happen to have recognize. Avoid the reduction case; instead require that the rotation be in range (this reverts 2b37c13dcf). Remove the asm rotations (making this branch illnamed), because now both Clang and GCC will create a roll without any extra help. Remove the reduction/mask by the word size for the variable case. The compiler can't optimize that it out well, but it's easy to ensure it is valid in the callers, especially now that the variable input cases are easy to grep for.
Diffstat (limited to 'src/lib/block/aria')
-rw-r--r--src/lib/block/aria/aria.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/lib/block/aria/aria.cpp b/src/lib/block/aria/aria.cpp
index 5b449722a..1583dd7d3 100644
--- a/src/lib/block/aria/aria.cpp
+++ b/src/lib/block/aria/aria.cpp
@@ -183,7 +183,7 @@ inline void ARIA_FO(uint32_t& T0, uint32_t& T1, uint32_t& T2, uint32_t& T3)
T1 ^= T2;
T1 = ((T1 << 8) & 0xFF00FF00) | ((T1 >> 8) & 0x00FF00FF);
- T2 = rotate_right(T2, 16);
+ T2 = rotr<16>(T2);
T3 = reverse_bytes(T3);
T1 ^= T2;
@@ -205,7 +205,7 @@ inline void ARIA_FE(uint32_t& T0, uint32_t& T1, uint32_t& T2, uint32_t& T3)
T1 ^= T2;
T3 = ((T3 << 8) & 0xFF00FF00) | ((T3 >> 8) & 0x00FF00FF);
- T0 = rotate_right(T0, 16);
+ T0 = rotr<16>(T0);
T1 = reverse_bytes(T1);
T1 ^= T2;
@@ -411,9 +411,9 @@ void key_schedule(secure_vector<uint32_t>& ERK,
{
for(size_t j = 0; j != 4; ++j)
{
- DRK[i+j] = rotate_right(DRK[i+j], 8) ^
- rotate_right(DRK[i+j], 16) ^
- rotate_right(DRK[i+j], 24);
+ DRK[i+j] = rotr<8>(DRK[i+j]) ^
+ rotr<16>(DRK[i+j]) ^
+ rotr<24>(DRK[i+j]);
}
DRK[i+1] ^= DRK[i+2]; DRK[i+2] ^= DRK[i+3];
@@ -421,7 +421,7 @@ void key_schedule(secure_vector<uint32_t>& ERK,
DRK[i+2] ^= DRK[i+0]; DRK[i+1] ^= DRK[i+2];
DRK[i+1] = ((DRK[i+1] << 8) & 0xFF00FF00) | ((DRK[i+1] >> 8) & 0x00FF00FF);
- DRK[i+2] = rotate_right(DRK[i+2], 16);
+ DRK[i+2] = rotr<16>(DRK[i+2]);
DRK[i+3] = reverse_bytes(DRK[i+3]);
DRK[i+1] ^= DRK[i+2]; DRK[i+2] ^= DRK[i+3];