summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2018-02-26 23:21:04 +0100
committerEike Rathke <erack@redhat.com>2018-02-27 11:41:49 +0100
commit87dbef3224e98081491ddbd8a2d405d8baf23e89 (patch)
tree08f0172b58ac71427cafc0ff689038d1f08a034e /oox
parentc98d3303027bd8bf8e0881b61918710ac479864c (diff)
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 <erack@redhat.com> Tested-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'oox')
-rw-r--r--oox/source/crypto/AgileEngine.cxx32
1 files 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 <oox/helper/binaryoutputstream.hxx>
#include <comphelper/hash.hxx>
+#include <comphelper/docpasswordhelper.hxx>
namespace oox {
namespace core {
@@ -76,35 +77,8 @@ void AgileEngine::calculateBlock(
void AgileEngine::calculateHashFinal(const OUString& rPassword, std::vector<sal_uInt8>& aHashFinal)
{
- sal_Int32 saltSize = mInfo.saltSize;
- std::vector<sal_uInt8>& salt = mInfo.saltValue;
-
- sal_uInt32 passwordByteLength = rPassword.getLength() * 2;
-
- std::vector<sal_uInt8> initialData(saltSize + passwordByteLength);
- std::copy(salt.begin(), salt.end(), initialData.begin());
-
- const sal_uInt8* passwordByteArray = reinterpret_cast<const sal_uInt8*>(rPassword.getStr());
-
- std::copy(
- passwordByteArray,
- passwordByteArray + passwordByteLength,
- initialData.begin() + saltSize);
-
- std::vector<sal_uInt8> hash(mInfo.hashSize, 0);
-
- hashCalc(hash, initialData, mInfo.hashAlgorithm);
-
- std::vector<sal_uInt8> 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)