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

Caolán McNamara caolanm at redhat.com
Thu Oct 20 13:00:49 UTC 2016


 include/oox/crypto/Standard2007Engine.hxx |    7 ++++---
 oox/source/crypto/DocumentDecryption.cxx  |    4 ++--
 oox/source/crypto/Standard2007Engine.cxx  |    8 ++++----
 3 files changed, 10 insertions(+), 9 deletions(-)

New commits:
commit 8db1b13e721683d0263925c8e0300dd86a022814
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Thu Oct 20 14:00:01 2016 +0100

    clarify hash lengths a bit more
    
    Change-Id: I66cea4b9efb82d29e6c052ac11a6f2eaca823ce0

diff --git a/include/oox/crypto/Standard2007Engine.hxx b/include/oox/crypto/Standard2007Engine.hxx
index b413053..2ee4a55 100644
--- a/include/oox/crypto/Standard2007Engine.hxx
+++ b/include/oox/crypto/Standard2007Engine.hxx
@@ -52,8 +52,9 @@ const sal_uInt32 VERSION_INFO_AGILE         = 0x00040004;
 
 const sal_uInt32 SALT_LENGTH                    = 16;
 const sal_uInt32 ENCRYPTED_VERIFIER_LENGTH      = 16;
-const sal_uInt32 ENCRYPTED_RC4_VERIFIER_HASH_LENGTH = 20;
-const sal_uInt32 ENCRYPTED_AES_VERIFIER_HASH_LENGTH = 32;
+const sal_uInt32 ENCRYPTED_SHA1_VERIFIER_HASH_LENGTH = 20;
+const sal_uInt32 ENCRYPTED_SHA256_VERIFIER_HASH_LENGTH = 32;
+const sal_uInt32 ENCRYPTED_SHA512_VERIFIER_HASH_LENGTH = 64;
 
 struct EncryptionStandardHeader
 {
@@ -75,7 +76,7 @@ struct EncryptionVerifierAES
     sal_uInt8  salt[SALT_LENGTH];                                       // random generated salt value
     sal_uInt8  encryptedVerifier[ENCRYPTED_VERIFIER_LENGTH];            // randomly generated verifier value
     sal_uInt32 encryptedVerifierHashSize;                               // actually written hash size - depends on algorithm
-    sal_uInt8  encryptedVerifierHash[ENCRYPTED_AES_VERIFIER_HASH_LENGTH];   // verifier value hash - itself also encrypted
+    sal_uInt8  encryptedVerifierHash[ENCRYPTED_SHA256_VERIFIER_HASH_LENGTH];   // verifier value hash - itself also encrypted
 
     EncryptionVerifierAES();
 };
diff --git a/oox/source/crypto/DocumentDecryption.cxx b/oox/source/crypto/DocumentDecryption.cxx
index b07c74f..d60c6b3 100644
--- a/oox/source/crypto/DocumentDecryption.cxx
+++ b/oox/source/crypto/DocumentDecryption.cxx
@@ -241,7 +241,7 @@ bool DocumentDecryption::readAgileEncryptionInfo(Reference< XInputStream >& xInp
         info.cipherAlgorithm == "AES" &&
         info.cipherChaining  == "ChainingModeCBC" &&
         info.hashAlgorithm   == "SHA1" &&
-        info.hashSize        == 20)
+        info.hashSize        == ENCRYPTED_SHA1_VERIFIER_HASH_LENGTH)
     {
         return true;
     }
@@ -251,7 +251,7 @@ bool DocumentDecryption::readAgileEncryptionInfo(Reference< XInputStream >& xInp
         info.cipherAlgorithm == "AES" &&
         info.cipherChaining  == "ChainingModeCBC" &&
         info.hashAlgorithm   == "SHA512" &&
-        info.hashSize        == 64 )
+        info.hashSize        == ENCRYPTED_SHA512_VERIFIER_HASH_LENGTH )
     {
         return true;
     }
diff --git a/oox/source/crypto/Standard2007Engine.cxx b/oox/source/crypto/Standard2007Engine.cxx
index 98b94a1..2266e44 100644
--- a/oox/source/crypto/Standard2007Engine.cxx
+++ b/oox/source/crypto/Standard2007Engine.cxx
@@ -90,9 +90,9 @@ bool Standard2007Engine::generateVerifier()
     vector<sal_uInt8> hash(RTL_DIGEST_LENGTH_SHA1, 0);
     mInfo.verifier.encryptedVerifierHashSize = RTL_DIGEST_LENGTH_SHA1;
     Digest::sha1(hash, verifier);
-    hash.resize(ENCRYPTED_AES_VERIFIER_HASH_LENGTH, 0);
+    hash.resize(ENCRYPTED_SHA256_VERIFIER_HASH_LENGTH, 0);
 
-    vector<sal_uInt8> encryptedHash(ENCRYPTED_AES_VERIFIER_HASH_LENGTH, 0);
+    vector<sal_uInt8> encryptedHash(ENCRYPTED_SHA256_VERIFIER_HASH_LENGTH, 0);
 
     Encrypt aEncryptorHash(mKey, iv, Crypto::AES_128_ECB);
     aEncryptorHash.update(encryptedHash, hash, hash.size());
@@ -162,10 +162,10 @@ bool Standard2007Engine::generateEncryptionKey(const OUString& password)
         mInfo.verifier.encryptedVerifier + ENCRYPTED_VERIFIER_LENGTH,
         encryptedVerifier.begin());
 
-    vector<sal_uInt8> encryptedHash(ENCRYPTED_AES_VERIFIER_HASH_LENGTH);
+    vector<sal_uInt8> encryptedHash(ENCRYPTED_SHA256_VERIFIER_HASH_LENGTH);
     std::copy(
         mInfo.verifier.encryptedVerifierHash,
-        mInfo.verifier.encryptedVerifierHash + ENCRYPTED_AES_VERIFIER_HASH_LENGTH,
+        mInfo.verifier.encryptedVerifierHash + ENCRYPTED_SHA256_VERIFIER_HASH_LENGTH,
         encryptedHash.begin());
 
     vector<sal_uInt8> verifier(encryptedVerifier.size(), 0);


More information about the Libreoffice-commits mailing list