diff options
-rw-r--r-- | include/oox/crypto/CryptTools.hxx | 3 | ||||
-rw-r--r-- | include/oox/crypto/Standard2007Engine.hxx | 9 | ||||
-rw-r--r-- | oox/source/crypto/CryptTools.cxx | 14 | ||||
-rw-r--r-- | oox/source/crypto/DocumentDecryption.cxx | 4 | ||||
-rw-r--r-- | oox/source/crypto/Standard2007Engine.cxx | 26 |
5 files changed, 23 insertions, 33 deletions
diff --git a/include/oox/crypto/CryptTools.hxx b/include/oox/crypto/CryptTools.hxx index d963be2719c4..d4fdda2c1cfb 100644 --- a/include/oox/crypto/CryptTools.hxx +++ b/include/oox/crypto/CryptTools.hxx @@ -123,9 +123,6 @@ public: SHA512 }; - static const sal_uInt32 DIGEST_LENGTH_SHA1; - static const sal_uInt32 DIGEST_LENGTH_SHA512; - private: DigestType meType; diff --git a/include/oox/crypto/Standard2007Engine.hxx b/include/oox/crypto/Standard2007Engine.hxx index 2ee4a553a918..1650b622e9f5 100644 --- a/include/oox/crypto/Standard2007Engine.hxx +++ b/include/oox/crypto/Standard2007Engine.hxx @@ -12,6 +12,7 @@ #define INCLUDED_OOX_CRYPTO_STANDARD2007ENGINE_HXX #include <oox/crypto/CryptoEngine.hxx> +#include <rtl/digest.h> #include <rtl/ustring.hxx> #include <sal/types.h> @@ -52,9 +53,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_SHA1_VERIFIER_HASH_LENGTH = 20; -const sal_uInt32 ENCRYPTED_SHA256_VERIFIER_HASH_LENGTH = 32; -const sal_uInt32 ENCRYPTED_SHA512_VERIFIER_HASH_LENGTH = 64; +const sal_uInt32 SHA1_HASH_LENGTH = RTL_DIGEST_LENGTH_SHA1; // 20 +const sal_uInt32 SHA256_HASH_LENGTH = 32; +const sal_uInt32 SHA512_HASH_LENGTH = 64; struct EncryptionStandardHeader { @@ -76,7 +77,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_SHA256_VERIFIER_HASH_LENGTH]; // verifier value hash - itself also encrypted + sal_uInt8 encryptedVerifierHash[SHA256_HASH_LENGTH]; // verifier value hash - itself also encrypted EncryptionVerifierAES(); }; 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 <com/sun/star/uno/RuntimeException.hpp> +#include "oox/crypto/Standard2007Engine.hxx" namespace oox { namespace core { @@ -196,15 +197,6 @@ sal_uInt32 Encrypt::update(vector<sal_uInt8>& output, vector<sal_uInt8>& 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<sal_uInt8> hash(RTL_DIGEST_LENGTH_SHA1, 0); - mInfo.verifier.encryptedVerifierHashSize = RTL_DIGEST_LENGTH_SHA1; + vector<sal_uInt8> 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<sal_uInt8> encryptedHash(ENCRYPTED_SHA256_VERIFIER_HASH_LENGTH, 0); + vector<sal_uInt8> 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<sal_uInt8> hash(Digest::DIGEST_LENGTH_SHA1, 0); + vector<sal_uInt8> hash(SHA1_HASH_LENGTH, 0); // calculate SHA1 hash of initialData Digest::sha1(hash, initialData); // data = iterator (4bytes) + hash - vector<sal_uInt8> data(Digest::DIGEST_LENGTH_SHA1 + 4, 0); + vector<sal_uInt8> 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<sal_uInt8> encryptedHash(ENCRYPTED_SHA256_VERIFIER_HASH_LENGTH); + vector<sal_uInt8> 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<sal_uInt8> verifier(encryptedVerifier.size(), 0); @@ -174,7 +174,7 @@ bool Standard2007Engine::generateEncryptionKey(const OUString& password) vector<sal_uInt8> verifierHash(encryptedHash.size(), 0); Decrypt::aes128ecb(verifierHash, encryptedHash, mKey); - vector<sal_uInt8> hash(RTL_DIGEST_LENGTH_SHA1, 0); + vector<sal_uInt8> hash(SHA1_HASH_LENGTH, 0); Digest::sha1(hash, verifier); return std::equal( hash.begin(), hash.end(), verifierHash.begin() ); |