From 309fbc2e7802fde80e5c1d3cc2562a6215b9a584 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Sat, 21 May 2016 12:19:57 -0400 Subject: [PATCH] Fix hash calculation for big endian machines. Remove unused functions --- blake2.cpp | 36 +++++------------------------------- 1 file changed, 5 insertions(+), 31 deletions(-) diff --git a/blake2.cpp b/blake2.cpp index e8d39fea..6409f6a8 100644 --- a/blake2.cpp +++ b/blake2.cpp @@ -141,20 +141,6 @@ const byte BLAKE2_Sigma::sigma[12][16] = { { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 } }; -template -inline void ThrowIfInvalidSalt(size_t size) -{ - if (size > BLAKE2_Info::SALTSIZE) - throw InvalidSaltLength(T_64bit ? "Blake2b" : "Blake2s", size); -} - -template -inline void ThrowIfInvalidPersonalization(size_t size) -{ - if (size > BLAKE2_Info::PERSONALIZATIONSIZE) - throw InvalidPersonalizationLength(T_64bit ? "Blake2b" : "Blake2s", size); -} - typedef void (*pfnCompress32)(const byte*, BLAKE2_State&); typedef void (*pfnCompress64)(const byte*, BLAKE2_State&); @@ -451,20 +437,8 @@ void BLAKE2_Base::TruncatedFinal(byte *hash, size_t size) memset(state.buffer + state.length, 0x00, BLOCKSIZE - state.length); Compress(state.buffer); - if (size >= DIGESTSIZE) - { - // Write directly to the caller buffer - PutBlock put(NULL, hash); - put(state.h[0])(state.h[1])(state.h[2])(state.h[3])(state.h[4])(state.h[5])(state.h[6])(state.h[7]); - } - else - { - FixedSizeAlignedSecBlock buffer; - PutBlock put(NULL, buffer); - put(state.h[0])(state.h[1])(state.h[2])(state.h[3])(state.h[4])(state.h[5])(state.h[6])(state.h[7]); - - memcpy_s(hash, DIGESTSIZE, buffer, size); - } + // Copy to caller buffer + memcpy_s(hash, size, &state.h[0], DIGESTSIZE); Restart(); } @@ -553,8 +527,8 @@ void BLAKE2_CXX_Compress64(const byte* input, BLAKE2_State& state) BLAKE2_ROUND( 10 ); BLAKE2_ROUND( 11 ); - for(i = 0; i < 8; ++i) - state.h[i] = state.h[i] ^ v[i] ^ v[i + 8]; + for(unsigned int i = 0; i < 8; ++i) + state.h[i] = state.h[i] ^ ConditionalByteReverse(LittleEndian::ToEnum(), v[i] ^ v[i + 8]); } void BLAKE2_CXX_Compress32(const byte* input, BLAKE2_State& state) @@ -615,7 +589,7 @@ void BLAKE2_CXX_Compress32(const byte* input, BLAKE2_State& state BLAKE2_ROUND( 9 ); for(unsigned int i = 0; i < 8; ++i) - state.h[i] = state.h[i] ^ v[i] ^ v[i + 8]; + state.h[i] = state.h[i] ^ ConditionalByteReverse(LittleEndian::ToEnum(), v[i] ^ v[i + 8]); } #if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE