diff options
author | Jack Lloyd <[email protected]> | 2017-12-23 06:20:51 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-12-23 06:20:51 -0500 |
commit | 4e101df712233ba6ef972b70d705bb29c7f1b7cf (patch) | |
tree | dfd776887264efab1b1354e57e7750f6cd985757 /src/lib/mac/siphash | |
parent | eb6c280b76b6f1d5909da016ee7f4c8fa52eb406 (diff) |
Avoid undefined behavior in SipHash
Diffstat (limited to 'src/lib/mac/siphash')
-rw-r--r-- | src/lib/mac/siphash/siphash.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/lib/mac/siphash/siphash.cpp b/src/lib/mac/siphash/siphash.cpp index 80acc4d60..7d8931c07 100644 --- a/src/lib/mac/siphash/siphash.cpp +++ b/src/lib/mac/siphash/siphash.cpp @@ -80,7 +80,15 @@ void SipHash::final_result(uint8_t mac[]) { verify_key_set(m_V.empty() == false); - m_mbuf = (m_mbuf >> (64-m_mbuf_pos*8)) | (static_cast<uint64_t>(m_words) << 56); + if(m_mbuf_pos == 0) + { + m_mbuf = (static_cast<uint64_t>(m_words) << 56); + } + else if(m_mbuf_pos < 8) + { + m_mbuf = (m_mbuf >> (64-m_mbuf_pos*8)) | (static_cast<uint64_t>(m_words) << 56); + } + SipRounds(m_mbuf, m_V, m_C); m_V[2] ^= 0xFF; |