diff options
-rw-r--r-- | comphelper/source/misc/hash.cxx | 8 | ||||
-rw-r--r-- | filter/source/msfilter/mscodec.cxx | 4 | ||||
-rw-r--r-- | include/comphelper/hash.hxx | 6 | ||||
-rw-r--r-- | include/filter/msfilter/mscodec.hxx | 8 | ||||
-rw-r--r-- | oox/source/crypto/AgileEngine.cxx | 4 | ||||
-rw-r--r-- | oox/source/crypto/Standard2007Engine.cxx | 14 | ||||
-rw-r--r-- | svl/source/crypto/cryptosign.cxx | 6 |
7 files changed, 27 insertions, 23 deletions
diff --git a/comphelper/source/misc/hash.cxx b/comphelper/source/misc/hash.cxx index 119044985bc5..6b54ed0a2452 100644 --- a/comphelper/source/misc/hash.cxx +++ b/comphelper/source/misc/hash.cxx @@ -139,13 +139,13 @@ size_t Hash::getLength() const switch (mpImpl->meType) { case HashType::MD5: - return 16; + return MD5_HASH_LENGTH; case HashType::SHA1: - return 20; + return SHA1_HASH_LENGTH; case HashType::SHA256: - return 32; + return SHA256_HASH_LENGTH; case HashType::SHA512: - return 64; + return SHA512_HASH_LENGTH; } return 0; diff --git a/filter/source/msfilter/mscodec.cxx b/filter/source/msfilter/mscodec.cxx index 0a03b50de454..50b282f8434b 100644 --- a/filter/source/msfilter/mscodec.cxx +++ b/filter/source/msfilter/mscodec.cxx @@ -625,13 +625,13 @@ EncryptionStandardHeader::EncryptionStandardHeader() EncryptionVerifierAES::EncryptionVerifierAES() : saltSize(SALT_LENGTH) - , encryptedVerifierHashSize(SHA1_HASH_LENGTH) + , encryptedVerifierHashSize(comphelper::SHA1_HASH_LENGTH) { } EncryptionVerifierRC4::EncryptionVerifierRC4() : saltSize(SALT_LENGTH) - , encryptedVerifierHashSize(SHA1_HASH_LENGTH) + , encryptedVerifierHashSize(comphelper::SHA1_HASH_LENGTH) { } diff --git a/include/comphelper/hash.hxx b/include/comphelper/hash.hxx index 52ad5e5cdf1e..54ab3a25105c 100644 --- a/include/comphelper/hash.hxx +++ b/include/comphelper/hash.hxx @@ -11,6 +11,7 @@ #define INCLUDED_COMPHELPER_HASH_HXX #include <comphelper/comphelperdllapi.h> +#include <rtl/digest.h> #include <memory> #include <vector> @@ -29,6 +30,11 @@ enum class HashType SHA512 }; +const sal_uInt32 MD5_HASH_LENGTH = RTL_DIGEST_LENGTH_MD5; +const sal_uInt32 SHA1_HASH_LENGTH = RTL_DIGEST_LENGTH_SHA1; +const sal_uInt32 SHA256_HASH_LENGTH = 32; +const sal_uInt32 SHA512_HASH_LENGTH = 64; + struct HashImpl; class COMPHELPER_DLLPUBLIC Hash diff --git a/include/filter/msfilter/mscodec.hxx b/include/filter/msfilter/mscodec.hxx index a7917ec1aa09..f40003efe0d6 100644 --- a/include/filter/msfilter/mscodec.hxx +++ b/include/filter/msfilter/mscodec.hxx @@ -25,6 +25,7 @@ #include <rtl/cipher.h> #include <rtl/digest.h> #include <sal/types.h> +#include <comphelper/hash.hxx> #include <vector> namespace com::sun::star { @@ -442,9 +443,6 @@ const sal_uInt32 AGILE_ENCRYPTION_RESERVED = 0x00000040; const sal_uInt32 SALT_LENGTH = 16; const sal_uInt32 ENCRYPTED_VERIFIER_LENGTH = 16; -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 MSFILTER_DLLPUBLIC EncryptionStandardHeader { @@ -466,7 +464,7 @@ struct MSFILTER_DLLPUBLIC 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[SHA256_HASH_LENGTH] = {}; // verifier value hash - itself also encrypted + sal_uInt8 encryptedVerifierHash[comphelper::SHA256_HASH_LENGTH] = {}; // verifier value hash - itself also encrypted EncryptionVerifierAES(); }; @@ -477,7 +475,7 @@ struct MSFILTER_DLLPUBLIC EncryptionVerifierRC4 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[SHA1_HASH_LENGTH] = {}; // verifier value hash - itself also encrypted + sal_uInt8 encryptedVerifierHash[comphelper::SHA1_HASH_LENGTH] = {}; // verifier value hash - itself also encrypted EncryptionVerifierRC4(); }; diff --git a/oox/source/crypto/AgileEngine.cxx b/oox/source/crypto/AgileEngine.cxx index df3bf4bb19d8..008b29462c0d 100644 --- a/oox/source/crypto/AgileEngine.cxx +++ b/oox/source/crypto/AgileEngine.cxx @@ -531,7 +531,7 @@ bool AgileEngine::readEncryptionInfo(uno::Reference<io::XInputStream> & rxInputS mInfo.cipherAlgorithm == "AES" && mInfo.cipherChaining == "ChainingModeCBC" && mInfo.hashAlgorithm == "SHA1" && - mInfo.hashSize == msfilter::SHA1_HASH_LENGTH) + mInfo.hashSize == comphelper::SHA1_HASH_LENGTH) { return true; } @@ -541,7 +541,7 @@ bool AgileEngine::readEncryptionInfo(uno::Reference<io::XInputStream> & rxInputS mInfo.cipherAlgorithm == "AES" && mInfo.cipherChaining == "ChainingModeCBC" && mInfo.hashAlgorithm == "SHA512" && - mInfo.hashSize == msfilter::SHA512_HASH_LENGTH) + mInfo.hashSize == comphelper::SHA512_HASH_LENGTH) { return true; } diff --git a/oox/source/crypto/Standard2007Engine.cxx b/oox/source/crypto/Standard2007Engine.cxx index 2799ec5286f9..0a367874d2c4 100644 --- a/oox/source/crypto/Standard2007Engine.cxx +++ b/oox/source/crypto/Standard2007Engine.cxx @@ -54,11 +54,11 @@ bool Standard2007Engine::generateVerifier() return false; std::copy(encryptedVerifier.begin(), encryptedVerifier.end(), mInfo.verifier.encryptedVerifier); - mInfo.verifier.encryptedVerifierHashSize = msfilter::SHA1_HASH_LENGTH; + mInfo.verifier.encryptedVerifierHashSize = comphelper::SHA1_HASH_LENGTH; std::vector<sal_uInt8> hash = comphelper::Hash::calculateHash(verifier.data(), verifier.size(), comphelper::HashType::SHA1); - hash.resize(msfilter::SHA256_HASH_LENGTH, 0); + hash.resize(comphelper::SHA256_HASH_LENGTH, 0); - std::vector<sal_uInt8> encryptedHash(msfilter::SHA256_HASH_LENGTH, 0); + std::vector<sal_uInt8> encryptedHash(comphelper::SHA256_HASH_LENGTH, 0); Encrypt aEncryptorHash(mKey, iv, Crypto::AES_128_ECB); aEncryptorHash.update(encryptedHash, hash, hash.size()); @@ -89,7 +89,7 @@ bool Standard2007Engine::calculateEncryptionKey(const OUString& rPassword) std::vector<sal_uInt8> hash = comphelper::Hash::calculateHash(initialData.data(), initialData.size(), comphelper::HashType::SHA1); // data = iterator (4bytes) + hash - std::vector<sal_uInt8> data(msfilter::SHA1_HASH_LENGTH + 4, 0); + std::vector<sal_uInt8> data(comphelper::SHA1_HASH_LENGTH + 4, 0); for (sal_Int32 i = 0; i < 50000; ++i) { @@ -98,7 +98,7 @@ bool Standard2007Engine::calculateEncryptionKey(const OUString& rPassword) hash = comphelper::Hash::calculateHash(data.data(), data.size(), comphelper::HashType::SHA1); } std::copy(hash.begin(), hash.end(), data.begin() ); - std::fill(data.begin() + msfilter::SHA1_HASH_LENGTH, data.end(), 0 ); + std::fill(data.begin() + comphelper::SHA1_HASH_LENGTH, data.end(), 0 ); hash = comphelper::Hash::calculateHash(data.data(), data.size(), comphelper::HashType::SHA1); @@ -140,10 +140,10 @@ bool Standard2007Engine::generateEncryptionKey(const OUString& password) mInfo.verifier.encryptedVerifier + msfilter::ENCRYPTED_VERIFIER_LENGTH, encryptedVerifier.begin()); - std::vector<sal_uInt8> encryptedHash(msfilter::SHA256_HASH_LENGTH); + std::vector<sal_uInt8> encryptedHash(comphelper::SHA256_HASH_LENGTH); std::copy( mInfo.verifier.encryptedVerifierHash, - mInfo.verifier.encryptedVerifierHash + msfilter::SHA256_HASH_LENGTH, + mInfo.verifier.encryptedVerifierHash + comphelper::SHA256_HASH_LENGTH, encryptedHash.begin()); std::vector<sal_uInt8> verifier(encryptedVerifier.size(), 0); diff --git a/svl/source/crypto/cryptosign.cxx b/svl/source/crypto/cryptosign.cxx index 573c06ba5826..25120d7cd6e5 100644 --- a/svl/source/crypto/cryptosign.cxx +++ b/svl/source/crypto/cryptosign.cxx @@ -2061,15 +2061,15 @@ bool Signing::Verify(const std::vector<unsigned char>& aData, switch (eOidTag) { case SEC_OID_SHA1: - nMaxResultLen = msfilter::SHA1_HASH_LENGTH; + nMaxResultLen = comphelper::SHA1_HASH_LENGTH; rInformation.nDigestID = xml::crypto::DigestID::SHA1; break; case SEC_OID_SHA256: - nMaxResultLen = msfilter::SHA256_HASH_LENGTH; + nMaxResultLen = comphelper::SHA256_HASH_LENGTH; rInformation.nDigestID = xml::crypto::DigestID::SHA256; break; case SEC_OID_SHA512: - nMaxResultLen = msfilter::SHA512_HASH_LENGTH; + nMaxResultLen = comphelper::SHA512_HASH_LENGTH; rInformation.nDigestID = xml::crypto::DigestID::SHA512; break; default: |