From 87dbef3224e98081491ddbd8a2d405d8baf23e89 Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Mon, 26 Feb 2018 23:21:04 +0100 Subject: Switch AgileEngine::calculateHashFinal() to GetOoxHashAsVector() ... to de-duplicate implementation and cut some overhead. Also, it seems UTF-16BE password was never handled. Change-Id: I46cae8516c6f2d1568aabc8d993c883f424c7d12 Reviewed-on: https://gerrit.libreoffice.org/50401 Reviewed-by: Eike Rathke Tested-by: Eike Rathke --- oox/source/crypto/AgileEngine.cxx | 32 +++----------------------------- 1 file changed, 3 insertions(+), 29 deletions(-) diff --git a/oox/source/crypto/AgileEngine.cxx b/oox/source/crypto/AgileEngine.cxx index b8a791848a49..49b428053061 100644 --- a/oox/source/crypto/AgileEngine.cxx +++ b/oox/source/crypto/AgileEngine.cxx @@ -14,6 +14,7 @@ #include #include +#include namespace oox { namespace core { @@ -76,35 +77,8 @@ void AgileEngine::calculateBlock( void AgileEngine::calculateHashFinal(const OUString& rPassword, std::vector& aHashFinal) { - sal_Int32 saltSize = mInfo.saltSize; - std::vector& salt = mInfo.saltValue; - - sal_uInt32 passwordByteLength = rPassword.getLength() * 2; - - std::vector initialData(saltSize + passwordByteLength); - std::copy(salt.begin(), salt.end(), initialData.begin()); - - const sal_uInt8* passwordByteArray = reinterpret_cast(rPassword.getStr()); - - std::copy( - passwordByteArray, - passwordByteArray + passwordByteLength, - initialData.begin() + saltSize); - - std::vector hash(mInfo.hashSize, 0); - - hashCalc(hash, initialData, mInfo.hashAlgorithm); - - std::vector data(mInfo.hashSize + 4, 0); - - for (sal_Int32 i = 0; i < mInfo.spinCount; i++) - { - ByteOrderConverter::writeLittleEndian(data.data(), i); - std::copy(hash.begin(), hash.end(), data.begin() + 4); - hashCalc(hash, data, mInfo.hashAlgorithm); - } - - std::copy(hash.begin(), hash.end(), aHashFinal.begin()); + aHashFinal = comphelper::DocPasswordHelper::GetOoxHashAsVector( rPassword, mInfo.saltValue, + mInfo.spinCount, comphelper::Hash::IterCount::PREPEND, mInfo.hashAlgorithm); } bool AgileEngine::generateEncryptionKey(const OUString& rPassword) -- cgit