diff options
author | 2022-09-25 22:28:50 -0400 | |
---|---|---|
committer | 2022-09-25 22:37:29 -0400 | |
commit | 5dc22ca8fd325315c5d24b6ed6a037cc38e86527 (patch) | |
tree | 3b0810f803ef2e9dff52c203510825f7c0b79a9b /src/lib/util/hashing.cpp | |
parent | a61cb4cb61c544241712dfb039817e7c7b72e3c0 (diff) |
eminline.h: Additions
- Add mul_16x16 inline function to perform a signed 16x16-bit multiplication with 32-bit result. This was moved from cpu/e132xs to unite it with the analogous 32x32 operations.
- Add rotl_32, rotr_32, rotl_64 and rotr_64 inline functions to perform 32-bit and 64-bit circular shifts in either direction by the specified number of places, modulo 32 or 64. It is anticipated that these will eventually be replaced by standard functions in C++20's <bit> header, and so they have been given similar signatures and semantics (which are also validity-checked).
- Remove LSL, LSR, ROL and ROR macros from cpu/arm and cpu/arm7 to ameliorate unnecessary obfuscation.
Diffstat (limited to 'src/lib/util/hashing.cpp')
-rw-r--r-- | src/lib/util/hashing.cpp | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/src/lib/util/hashing.cpp b/src/lib/util/hashing.cpp index e90c128a8a2..62447c7b6c0 100644 --- a/src/lib/util/hashing.cpp +++ b/src/lib/util/hashing.cpp @@ -11,6 +11,8 @@ #include "hashing.h" #include "strformat.h" +#include "eminline.h" + #include <zlib.h> #include <iomanip> @@ -40,50 +42,45 @@ constexpr int char_to_hex(char c) } -constexpr uint32_t sha1_rol(uint32_t x, unsigned n) -{ - return (x << n) | (x >> (32 - n)); -} - inline uint32_t sha1_b(uint32_t *data, unsigned i) { uint32_t r = data[(i + 13) & 15U]; r ^= data[(i + 8) & 15U]; r ^= data[(i + 2) & 15U]; r ^= data[i & 15U]; - r = sha1_rol(r, 1); + r = rotl_32(r, 1); data[i & 15U] = r; return r; } inline void sha1_r0(const uint32_t *data, std::array<uint32_t, 5> &d, unsigned i) { - d[i % 5] = d[i % 5] + ((d[(i + 3) % 5] & (d[(i + 2) % 5] ^ d[(i + 1) % 5])) ^ d[(i + 1) % 5]) + data[i] + 0x5a827999U + sha1_rol(d[(i + 4) % 5], 5); - d[(i + 3) % 5] = sha1_rol(d[(i + 3) % 5], 30); + d[i % 5] = d[i % 5] + ((d[(i + 3) % 5] & (d[(i + 2) % 5] ^ d[(i + 1) % 5])) ^ d[(i + 1) % 5]) + data[i] + 0x5a827999U + rotl_32(d[(i + 4) % 5], 5); + d[(i + 3) % 5] = rotl_32(d[(i + 3) % 5], 30); } inline void sha1_r1(uint32_t *data, std::array<uint32_t, 5> &d, unsigned i) { - d[i % 5] = d[i % 5] + ((d[(i + 3) % 5] & (d[(i + 2) % 5] ^ d[(i + 1) % 5])) ^ d[(i + 1) % 5])+ sha1_b(data, i) + 0x5a827999U + sha1_rol(d[(i + 4) % 5], 5); - d[(i + 3) % 5] = sha1_rol(d[(i + 3) % 5], 30); + d[i % 5] = d[i % 5] + ((d[(i + 3) % 5] & (d[(i + 2) % 5] ^ d[(i + 1) % 5])) ^ d[(i + 1) % 5])+ sha1_b(data, i) + 0x5a827999U + rotl_32(d[(i + 4) % 5], 5); + d[(i + 3) % 5] = rotl_32(d[(i + 3) % 5], 30); } inline void sha1_r2(uint32_t *data, std::array<uint32_t, 5> &d, unsigned i) { - d[i % 5] = d[i % 5] + (d[(i + 3) % 5] ^ d[(i + 2) % 5] ^ d[(i + 1) % 5]) + sha1_b(data, i) + 0x6ed9eba1U + sha1_rol(d[(i + 4) % 5], 5); - d[(i + 3) % 5] = sha1_rol(d[(i + 3) % 5], 30); + d[i % 5] = d[i % 5] + (d[(i + 3) % 5] ^ d[(i + 2) % 5] ^ d[(i + 1) % 5]) + sha1_b(data, i) + 0x6ed9eba1U + rotl_32(d[(i + 4) % 5], 5); + d[(i + 3) % 5] = rotl_32(d[(i + 3) % 5], 30); } inline void sha1_r3(uint32_t *data, std::array<uint32_t, 5> &d, unsigned i) { - d[i % 5] = d[i % 5] + (((d[(i + 3) % 5] | d[(i + 2) % 5]) & d[(i + 1) % 5]) | (d[(i + 3) % 5] & d[(i + 2) % 5])) + sha1_b(data, i) + 0x8f1bbcdcU + sha1_rol(d[(i + 4) % 5], 5); - d[(i + 3) % 5] = sha1_rol(d[(i + 3) % 5], 30); + d[i % 5] = d[i % 5] + (((d[(i + 3) % 5] | d[(i + 2) % 5]) & d[(i + 1) % 5]) | (d[(i + 3) % 5] & d[(i + 2) % 5])) + sha1_b(data, i) + 0x8f1bbcdcU + rotl_32(d[(i + 4) % 5], 5); + d[(i + 3) % 5] = rotl_32(d[(i + 3) % 5], 30); } inline void sha1_r4(uint32_t *data, std::array<uint32_t, 5> &d, unsigned i) { - d[i % 5] = d[i % 5] + (d[(i + 3) % 5] ^ d[(i + 2) % 5] ^ d[(i + 1) % 5]) + sha1_b(data, i) + 0xca62c1d6U + sha1_rol(d[(i + 4) % 5], 5); - d[(i + 3) % 5] = sha1_rol(d[(i + 3) % 5], 30); + d[i % 5] = d[i % 5] + (d[(i + 3) % 5] ^ d[(i + 2) % 5] ^ d[(i + 1) % 5]) + sha1_b(data, i) + 0xca62c1d6U + rotl_32(d[(i + 4) % 5], 5); + d[(i + 3) % 5] = rotl_32(d[(i + 3) % 5], 30); } inline void sha1_process(std::array<uint32_t, 5> &st, uint32_t *data) |