From fcc846e8f29839eaace7e1d28746abea8f4b598a Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Thu, 20 Oct 2016 14:13:19 +0100 Subject: hash len isn't going to change depending on who implements it Change-Id: Iee585cba4acad74c11d083085153e2af96c8894f --- oox/source/crypto/CryptTools.cxx | 14 +++----------- oox/source/crypto/DocumentDecryption.cxx | 4 ++-- oox/source/crypto/Standard2007Engine.cxx | 26 +++++++++++++------------- 3 files changed, 18 insertions(+), 26 deletions(-) (limited to 'oox') diff --git a/oox/source/crypto/CryptTools.cxx b/oox/source/crypto/CryptTools.cxx index 120487789d89..d6dbc96dc989 100644 --- a/oox/source/crypto/CryptTools.cxx +++ b/oox/source/crypto/CryptTools.cxx @@ -10,6 +10,7 @@ #include "oox/crypto/CryptTools.hxx" #include +#include "oox/crypto/Standard2007Engine.hxx" namespace oox { namespace core { @@ -196,15 +197,6 @@ sal_uInt32 Encrypt::update(vector& output, vector& input, // Digest -#if USE_TLS_OPENSSL -const sal_uInt32 Digest::DIGEST_LENGTH_SHA1 = SHA_DIGEST_LENGTH; -const sal_uInt32 Digest::DIGEST_LENGTH_SHA512 = SHA512_DIGEST_LENGTH; -#endif -#if USE_TLS_NSS -const sal_uInt32 Digest::DIGEST_LENGTH_SHA1 = SHA1_LENGTH; -const sal_uInt32 Digest::DIGEST_LENGTH_SHA512 = SHA512_LENGTH; -#endif - namespace { @@ -275,9 +267,9 @@ sal_uInt32 Digest::getLength() switch(meType) { case SHA1: - return DIGEST_LENGTH_SHA1; + return oox::core::SHA1_HASH_LENGTH; case SHA512: - return DIGEST_LENGTH_SHA512; + return oox::core::SHA512_HASH_LENGTH; default: break; } diff --git a/oox/source/crypto/DocumentDecryption.cxx b/oox/source/crypto/DocumentDecryption.cxx index d60c6b3d45e3..c843ad116d13 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 == ENCRYPTED_SHA1_VERIFIER_HASH_LENGTH) + info.hashSize == SHA1_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 == ENCRYPTED_SHA512_VERIFIER_HASH_LENGTH ) + info.hashSize == SHA512_HASH_LENGTH) { return true; } diff --git a/oox/source/crypto/Standard2007Engine.cxx b/oox/source/crypto/Standard2007Engine.cxx index 2266e44f49d4..87ef81b56e9b 100644 --- a/oox/source/crypto/Standard2007Engine.cxx +++ b/oox/source/crypto/Standard2007Engine.cxx @@ -54,9 +54,9 @@ EncryptionStandardHeader::EncryptionStandardHeader() reserved2 = 0; } -EncryptionVerifierAES::EncryptionVerifierAES() : - saltSize(SALT_LENGTH), - encryptedVerifierHashSize(Digest::DIGEST_LENGTH_SHA1) +EncryptionVerifierAES::EncryptionVerifierAES() + : saltSize(SALT_LENGTH) + , encryptedVerifierHashSize(SHA1_HASH_LENGTH) { memset(salt, 0, sizeof(salt)); memset(encryptedVerifier, 0, sizeof(encryptedVerifier)); @@ -87,12 +87,12 @@ bool Standard2007Engine::generateVerifier() return false; std::copy(encryptedVerifier.begin(), encryptedVerifier.end(), mInfo.verifier.encryptedVerifier); - vector hash(RTL_DIGEST_LENGTH_SHA1, 0); - mInfo.verifier.encryptedVerifierHashSize = RTL_DIGEST_LENGTH_SHA1; + vector hash(SHA1_HASH_LENGTH, 0); + mInfo.verifier.encryptedVerifierHashSize = SHA1_HASH_LENGTH; Digest::sha1(hash, verifier); - hash.resize(ENCRYPTED_SHA256_VERIFIER_HASH_LENGTH, 0); + hash.resize(SHA256_HASH_LENGTH, 0); - vector encryptedHash(ENCRYPTED_SHA256_VERIFIER_HASH_LENGTH, 0); + vector encryptedHash(SHA256_HASH_LENGTH, 0); Encrypt aEncryptorHash(mKey, iv, Crypto::AES_128_ECB); aEncryptorHash.update(encryptedHash, hash, hash.size()); @@ -119,13 +119,13 @@ bool Standard2007Engine::calculateEncryptionKey(const OUString& rPassword) initialData.begin() + saltSize); // use "hash" vector for result of sha1 hashing - vector hash(Digest::DIGEST_LENGTH_SHA1, 0); + vector hash(SHA1_HASH_LENGTH, 0); // calculate SHA1 hash of initialData Digest::sha1(hash, initialData); // data = iterator (4bytes) + hash - vector data(Digest::DIGEST_LENGTH_SHA1 + 4, 0); + vector data(SHA1_HASH_LENGTH + 4, 0); for (sal_Int32 i = 0; i < 50000; ++i) { @@ -134,7 +134,7 @@ bool Standard2007Engine::calculateEncryptionKey(const OUString& rPassword) Digest::sha1(hash, data); } std::copy(hash.begin(), hash.end(), data.begin() ); - std::fill(data.begin() + Digest::DIGEST_LENGTH_SHA1, data.end(), 0 ); + std::fill(data.begin() + SHA1_HASH_LENGTH, data.end(), 0 ); Digest::sha1(hash, data); @@ -162,10 +162,10 @@ bool Standard2007Engine::generateEncryptionKey(const OUString& password) mInfo.verifier.encryptedVerifier + ENCRYPTED_VERIFIER_LENGTH, encryptedVerifier.begin()); - vector encryptedHash(ENCRYPTED_SHA256_VERIFIER_HASH_LENGTH); + vector encryptedHash(SHA256_HASH_LENGTH); std::copy( mInfo.verifier.encryptedVerifierHash, - mInfo.verifier.encryptedVerifierHash + ENCRYPTED_SHA256_VERIFIER_HASH_LENGTH, + mInfo.verifier.encryptedVerifierHash + SHA256_HASH_LENGTH, encryptedHash.begin()); vector verifier(encryptedVerifier.size(), 0); @@ -174,7 +174,7 @@ bool Standard2007Engine::generateEncryptionKey(const OUString& password) vector verifierHash(encryptedHash.size(), 0); Decrypt::aes128ecb(verifierHash, encryptedHash, mKey); - vector hash(RTL_DIGEST_LENGTH_SHA1, 0); + vector hash(SHA1_HASH_LENGTH, 0); Digest::sha1(hash, verifier); return std::equal( hash.begin(), hash.end(), verifierHash.begin() ); -- cgit