From 267c6f2ac71f92999e969232431ba04678e7437e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 07:54:39 +0200 Subject: Adding upstream version 4:24.2.0. Signed-off-by: Daniel Baumann --- include/oox/crypto/AgileEngine.hxx | 148 +++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 include/oox/crypto/AgileEngine.hxx (limited to 'include/oox/crypto/AgileEngine.hxx') diff --git a/include/oox/crypto/AgileEngine.hxx b/include/oox/crypto/AgileEngine.hxx new file mode 100644 index 0000000000..07ce3cb5ee --- /dev/null +++ b/include/oox/crypto/AgileEngine.hxx @@ -0,0 +1,148 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#ifndef INCLUDED_OOX_CRYPTO_AGILEENGINE_HXX +#define INCLUDED_OOX_CRYPTO_AGILEENGINE_HXX + +#include + +#include +#include +#include +#include +#include + +namespace oox { + class BinaryXInputStream; + class BinaryXOutputStream; +} + +namespace oox::crypto { + +struct OOX_DLLPUBLIC AgileEncryptionInfo +{ + sal_Int32 spinCount; + sal_Int32 saltSize; + sal_Int32 keyBits; + sal_Int32 hashSize; + sal_Int32 blockSize; + + OUString cipherAlgorithm; + OUString cipherChaining; + OUString hashAlgorithm; + + std::vector keyDataSalt; + + // Key Encryptor + std::vector saltValue; + std::vector encryptedVerifierHashInput; + std::vector encryptedVerifierHashValue; + std::vector encryptedKeyValue; + + // HMAC + std::vector hmacKey; + std::vector hmacHash; + std::vector hmacCalculatedHash; + std::vector hmacEncryptedKey; // encrypted Key + std::vector hmacEncryptedValue; // encrypted Hash +}; + +struct OOX_DLLPUBLIC AgileEncryptionParameters +{ + sal_Int32 spinCount; + sal_Int32 saltSize; + sal_Int32 keyBits; + sal_Int32 hashSize; + sal_Int32 blockSize; + + OUString cipherAlgorithm; + OUString cipherChaining; + OUString hashAlgorithm; +}; + +enum class AgileEncryptionPreset +{ + AES_128_SHA1, + AES_128_SHA384, + AES_256_SHA512, +}; + +class OOX_DLLPUBLIC AgileEngine final : public CryptoEngine +{ +private: + AgileEncryptionInfo mInfo; + AgileEncryptionPreset meEncryptionPreset; + + void calculateHashFinal(const OUString& rPassword, std::vector& aHashFinal); + + void calculateBlock( + std::vector const & rBlock, + std::vector& rHashFinal, + std::vector& rInput, + std::vector& rOutput); + + void encryptBlock( + std::vector const & rBlock, + std::vector& rHashFinal, + std::vector& rInput, + std::vector& rOutput); + + static Crypto::CryptoType cryptoType(const AgileEncryptionInfo& rInfo); + +public: + AgileEngine(); + + AgileEncryptionInfo& getInfo() { return mInfo;} + + void setPreset(AgileEncryptionPreset ePreset) + { + meEncryptionPreset = ePreset; + } + + // Decryption + + void decryptEncryptionKey(OUString const & rPassword); + bool decryptAndCheckVerifierHash(OUString const & rPassword); + + bool generateEncryptionKey(OUString const & rPassword) override; + bool readEncryptionInfo(css::uno::Reference & rxInputStream) override; + bool decrypt(BinaryXInputStream& aInputStream, + BinaryXOutputStream& aOutputStream) override; + + bool checkDataIntegrity() override; + + bool decryptHmacKey(); + bool decryptHmacValue(); + + // Encryption + + void writeEncryptionInfo(BinaryXOutputStream& rStream) override; + + void encrypt(const css::uno::Reference& rxInputStream, + css::uno::Reference& rxOutputStream, + sal_uInt32 nSize) override; + + bool setupEncryption(OUString const & rPassword) override; + + bool generateAndEncryptVerifierHash(OUString const & rPassword); + + bool encryptHmacKey(); + bool encryptHmacValue(); + + bool encryptEncryptionKey(OUString const & rPassword); + void setupEncryptionParameters(AgileEncryptionParameters const & rAgileEncryptionParameters); + bool setupEncryptionKey(OUString const & rPassword); +}; + +} // namespace oox::crypto + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3