diff options
author | Caolán McNamara <caolanm@redhat.com> | 2016-10-20 14:13:19 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2016-10-21 11:16:11 +0100 |
commit | fcc846e8f29839eaace7e1d28746abea8f4b598a (patch) | |
tree | bb0f460a0ba682e0619f0e3d7f84cb63f28e9dca /oox | |
parent | 5a5731cd0587553f21b2cee2a99db9f527396406 (diff) |
hash len isn't going to change depending on who implements it
Change-Id: Iee585cba4acad74c11d083085153e2af96c8894f
Diffstat (limited to 'oox')
-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 |
3 files changed, 18 insertions, 26 deletions
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() ); |