diff options
Diffstat (limited to 'src/lib/hash')
-rw-r--r-- | src/lib/hash/sha1/sha1_x86/sha1_x86.cpp | 4 | ||||
-rw-r--r-- | src/lib/hash/sha2_32/sha2_32.cpp | 25 | ||||
-rw-r--r-- | src/lib/hash/sha2_32/sha2_32_x86/sha2_32_x86.cpp | 20 |
3 files changed, 13 insertions, 36 deletions
diff --git a/src/lib/hash/sha1/sha1_x86/sha1_x86.cpp b/src/lib/hash/sha1/sha1_x86/sha1_x86.cpp index 2249c3427..1da3eda63 100644 --- a/src/lib/hash/sha1/sha1_x86/sha1_x86.cpp +++ b/src/lib/hash/sha1/sha1_x86/sha1_x86.cpp @@ -29,7 +29,7 @@ void SHA_160::sha1_compress_x86(secure_vector<uint32_t>& digest, uint32_t* state = digest.data(); // Load initial values - __m128i ABCD = _mm_loadu_si128((__m128i*) state); + __m128i ABCD = _mm_loadu_si128(reinterpret_cast<__m128i*>(state)); __m128i E0 = _mm_set_epi32(state[4], 0, 0, 0); ABCD = _mm_shuffle_epi32(ABCD, 0x1B); @@ -208,7 +208,7 @@ void SHA_160::sha1_compress_x86(secure_vector<uint32_t>& digest, // Save state ABCD = _mm_shuffle_epi32(ABCD, 0x1B); - _mm_storeu_si128((__m128i*) state, ABCD); + _mm_storeu_si128(reinterpret_cast<__m128i*>(state), ABCD); state[4] = _mm_extract_epi32(E0, 3); } #endif diff --git a/src/lib/hash/sha2_32/sha2_32.cpp b/src/lib/hash/sha2_32/sha2_32.cpp index 58977b617..281e6ed2b 100644 --- a/src/lib/hash/sha2_32/sha2_32.cpp +++ b/src/lib/hash/sha2_32/sha2_32.cpp @@ -21,31 +21,6 @@ std::unique_ptr<HashFunction> SHA_256::copy_state() const return std::unique_ptr<HashFunction>(new SHA_256(*this)); } -namespace { - -namespace SHA2_32 { - -/* -* SHA-256 Rho Function -*/ -inline uint32_t rho(uint32_t X, uint32_t rot1, uint32_t rot2, uint32_t rot3) - { - return (rotate_right(X, rot1) ^ rotate_right(X, rot2) ^ - rotate_right(X, rot3)); - } - -/* -* SHA-256 Sigma Function -*/ -inline uint32_t sigma(uint32_t X, uint32_t rot1, uint32_t rot2, uint32_t shift) - { - return (rotate_right(X, rot1) ^ rotate_right(X, rot2) ^ (X >> shift)); - } - -} - -} - /* * SHA-256 F1 Function * diff --git a/src/lib/hash/sha2_32/sha2_32_x86/sha2_32_x86.cpp b/src/lib/hash/sha2_32/sha2_32_x86/sha2_32_x86.cpp index 99c0e374f..ee8af1e22 100644 --- a/src/lib/hash/sha2_32/sha2_32_x86/sha2_32_x86.cpp +++ b/src/lib/hash/sha2_32/sha2_32_x86/sha2_32_x86.cpp @@ -22,9 +22,11 @@ void SHA_256::compress_digest_x86(secure_vector<uint32_t>& digest, const uint8_t uint32_t* state = &digest[0]; + const __m128i* input_mm = reinterpret_cast<const __m128i*>(input); + // Load initial values - TMP = _mm_loadu_si128((__m128i*) &state[0]); - STATE1 = _mm_loadu_si128((__m128i*) &state[4]); + TMP = _mm_loadu_si128(reinterpret_cast<__m128i*>(&state[0])); + STATE1 = _mm_loadu_si128(reinterpret_cast<__m128i*>(&state[4])); MASK = _mm_set_epi64x(0x0c0d0e0f08090a0bULL, 0x0405060700010203ULL); TMP = _mm_shuffle_epi32(TMP, 0xB1); // CDAB @@ -39,7 +41,7 @@ void SHA_256::compress_digest_x86(secure_vector<uint32_t>& digest, const uint8_t CDGH_SAVE = STATE1; // Rounds 0-3 - MSG = _mm_loadu_si128((const __m128i*) (input+0)); + MSG = _mm_loadu_si128(input_mm); TMSG0 = _mm_shuffle_epi8(MSG, MASK); MSG = _mm_add_epi32(TMSG0, _mm_set_epi64x(0xE9B5DBA5B5C0FBCFULL, 0x71374491428A2F98ULL)); STATE1 = _mm_sha256rnds2_epu32(STATE1, STATE0, MSG); @@ -47,7 +49,7 @@ void SHA_256::compress_digest_x86(secure_vector<uint32_t>& digest, const uint8_t STATE0 = _mm_sha256rnds2_epu32(STATE0, STATE1, MSG); // Rounds 4-7 - TMSG1 = _mm_loadu_si128((const __m128i*) (input+16)); + TMSG1 = _mm_loadu_si128(input_mm + 1); TMSG1 = _mm_shuffle_epi8(TMSG1, MASK); MSG = _mm_add_epi32(TMSG1, _mm_set_epi64x(0xAB1C5ED5923F82A4ULL, 0x59F111F13956C25BULL)); STATE1 = _mm_sha256rnds2_epu32(STATE1, STATE0, MSG); @@ -56,7 +58,7 @@ void SHA_256::compress_digest_x86(secure_vector<uint32_t>& digest, const uint8_t TMSG0 = _mm_sha256msg1_epu32(TMSG0, TMSG1); // Rounds 8-11 - TMSG2 = _mm_loadu_si128((const __m128i*) (input+32)); + TMSG2 = _mm_loadu_si128(input_mm + 2); TMSG2 = _mm_shuffle_epi8(TMSG2, MASK); MSG = _mm_add_epi32(TMSG2, _mm_set_epi64x(0x550C7DC3243185BEULL, 0x12835B01D807AA98ULL)); STATE1 = _mm_sha256rnds2_epu32(STATE1, STATE0, MSG); @@ -65,7 +67,7 @@ void SHA_256::compress_digest_x86(secure_vector<uint32_t>& digest, const uint8_t TMSG1 = _mm_sha256msg1_epu32(TMSG1, TMSG2); // Rounds 12-15 - TMSG3 = _mm_loadu_si128((const __m128i*) (input+48)); + TMSG3 = _mm_loadu_si128(input_mm + 3); TMSG3 = _mm_shuffle_epi8(TMSG3, MASK); MSG = _mm_add_epi32(TMSG3, _mm_set_epi64x(0xC19BF1749BDC06A7ULL, 0x80DEB1FE72BE5D74ULL)); STATE1 = _mm_sha256rnds2_epu32(STATE1, STATE0, MSG); @@ -194,7 +196,7 @@ void SHA_256::compress_digest_x86(secure_vector<uint32_t>& digest, const uint8_t STATE0 = _mm_add_epi32(STATE0, ABEF_SAVE); STATE1 = _mm_add_epi32(STATE1, CDGH_SAVE); - input += 64; + input_mm += 4; blocks--; } @@ -204,8 +206,8 @@ void SHA_256::compress_digest_x86(secure_vector<uint32_t>& digest, const uint8_t STATE1 = _mm_alignr_epi8(STATE1, TMP, 8); // ABEF // Save state - _mm_storeu_si128((__m128i*) &state[0], STATE0); - _mm_storeu_si128((__m128i*) &state[4], STATE1); + _mm_storeu_si128(reinterpret_cast<__m128i*>(&state[0]), STATE0); + _mm_storeu_si128(reinterpret_cast<__m128i*>(&state[4]), STATE1); } #endif |