From e95618d754ee4e75632ed5f2bc29b8a021f45731 Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Mon, 26 Feb 2018 15:33:57 +0100 Subject: Swap UTF16-BE to UTF16-LE in Hash::calculateHash() Change-Id: I3727eefe795efcc3cc0a199ed3c3efc358145c87 --- comphelper/source/misc/hash.cxx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/comphelper/source/misc/hash.cxx b/comphelper/source/misc/hash.cxx index ad0a247ae7f6..2101bee64629 100644 --- a/comphelper/source/misc/hash.cxx +++ b/comphelper/source/misc/hash.cxx @@ -223,6 +223,22 @@ std::vector Hash::calculateHash( { const unsigned char* pPassBytes = reinterpret_cast(rPassword.getStr()); const size_t nPassBytesLen = rPassword.getLength() * 2; +#ifdef OSL_BIGENDIAN + // Swap UTF16-BE to UTF16-LE + std::vector vPass; + if (nPassBytesLen) + { + vPass.resize( nPassBytesLen); + std::copy( pPassBytes, pPassBytes + nPassBytesLen, vPass.begin()); + sal_uInt8* p = reinterpret_cast(vPass.data()); + sal_uInt8 const * const pEnd = p + nPassBytesLen; + for ( ; p < pEnd; p += 2 ) + { + std::swap( p[0], p[1] ); + } + pPassBytes = vPass.data(); + } +#endif return calculateHash( pPassBytes, nPassBytesLen, rSaltValue.data(), rSaltValue.size(), nSpinCount, bPrependNotAppend, eType); } -- cgit