summaryrefslogtreecommitdiff
path: root/comphelper/source/misc
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2018-02-26 15:33:57 +0100
committerEike Rathke <erack@redhat.com>2018-02-26 15:35:52 +0100
commite95618d754ee4e75632ed5f2bc29b8a021f45731 (patch)
treec7e69a51643372eb91b3962587ac5fa4a873a1ca /comphelper/source/misc
parentbf22cc9ac97e36aea974a5029303059717a318e6 (diff)
Swap UTF16-BE to UTF16-LE in Hash::calculateHash()
Change-Id: I3727eefe795efcc3cc0a199ed3c3efc358145c87
Diffstat (limited to 'comphelper/source/misc')
-rw-r--r--comphelper/source/misc/hash.cxx16
1 files changed, 16 insertions, 0 deletions
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<unsigned char> Hash::calculateHash(
{
const unsigned char* pPassBytes = reinterpret_cast<const unsigned char*>(rPassword.getStr());
const size_t nPassBytesLen = rPassword.getLength() * 2;
+#ifdef OSL_BIGENDIAN
+ // Swap UTF16-BE to UTF16-LE
+ std::vector<unsigned char> vPass;
+ if (nPassBytesLen)
+ {
+ vPass.resize( nPassBytesLen);
+ std::copy( pPassBytes, pPassBytes + nPassBytesLen, vPass.begin());
+ sal_uInt8* p = reinterpret_cast<sal_uInt8*>(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);
}