[Libreoffice-commits] core.git: oox/source

Eike Rathke erack at redhat.com
Tue Feb 27 10:42:12 UTC 2018


 oox/source/crypto/AgileEngine.cxx |   32 +++-----------------------------
 1 file changed, 3 insertions(+), 29 deletions(-)

New commits:
commit 87dbef3224e98081491ddbd8a2d405d8baf23e89
Author: Eike Rathke <erack at redhat.com>
Date:   Mon Feb 26 23:21:04 2018 +0100

    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 at redhat.com>
    Tested-by: Eike Rathke <erack at redhat.com>

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)


More information about the Libreoffice-commits mailing list