android: Update app-specific/MIME type icons
[LibreOffice.git] / include / oox / crypto / AgileEngine.hxx
blob07ce3cb5eeb1b2c44f4e51f3f60df1a28c66026f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 */
11 #ifndef INCLUDED_OOX_CRYPTO_AGILEENGINE_HXX
12 #define INCLUDED_OOX_CRYPTO_AGILEENGINE_HXX
14 #include <vector>
16 #include <oox/dllapi.h>
17 #include <oox/crypto/CryptTools.hxx>
18 #include <oox/crypto/CryptoEngine.hxx>
19 #include <rtl/ustring.hxx>
20 #include <sal/types.h>
22 namespace oox {
23 class BinaryXInputStream;
24 class BinaryXOutputStream;
27 namespace oox::crypto {
29 struct OOX_DLLPUBLIC AgileEncryptionInfo
31 sal_Int32 spinCount;
32 sal_Int32 saltSize;
33 sal_Int32 keyBits;
34 sal_Int32 hashSize;
35 sal_Int32 blockSize;
37 OUString cipherAlgorithm;
38 OUString cipherChaining;
39 OUString hashAlgorithm;
41 std::vector<sal_uInt8> keyDataSalt;
43 // Key Encryptor
44 std::vector<sal_uInt8> saltValue;
45 std::vector<sal_uInt8> encryptedVerifierHashInput;
46 std::vector<sal_uInt8> encryptedVerifierHashValue;
47 std::vector<sal_uInt8> encryptedKeyValue;
49 // HMAC
50 std::vector<sal_uInt8> hmacKey;
51 std::vector<sal_uInt8> hmacHash;
52 std::vector<sal_uInt8> hmacCalculatedHash;
53 std::vector<sal_uInt8> hmacEncryptedKey; // encrypted Key
54 std::vector<sal_uInt8> hmacEncryptedValue; // encrypted Hash
57 struct OOX_DLLPUBLIC AgileEncryptionParameters
59 sal_Int32 spinCount;
60 sal_Int32 saltSize;
61 sal_Int32 keyBits;
62 sal_Int32 hashSize;
63 sal_Int32 blockSize;
65 OUString cipherAlgorithm;
66 OUString cipherChaining;
67 OUString hashAlgorithm;
70 enum class AgileEncryptionPreset
72 AES_128_SHA1,
73 AES_128_SHA384,
74 AES_256_SHA512,
77 class OOX_DLLPUBLIC AgileEngine final : public CryptoEngine
79 private:
80 AgileEncryptionInfo mInfo;
81 AgileEncryptionPreset meEncryptionPreset;
83 void calculateHashFinal(const OUString& rPassword, std::vector<sal_uInt8>& aHashFinal);
85 void calculateBlock(
86 std::vector<sal_uInt8> const & rBlock,
87 std::vector<sal_uInt8>& rHashFinal,
88 std::vector<sal_uInt8>& rInput,
89 std::vector<sal_uInt8>& rOutput);
91 void encryptBlock(
92 std::vector<sal_uInt8> const & rBlock,
93 std::vector<sal_uInt8>& rHashFinal,
94 std::vector<sal_uInt8>& rInput,
95 std::vector<sal_uInt8>& rOutput);
97 static Crypto::CryptoType cryptoType(const AgileEncryptionInfo& rInfo);
99 public:
100 AgileEngine();
102 AgileEncryptionInfo& getInfo() { return mInfo;}
104 void setPreset(AgileEncryptionPreset ePreset)
106 meEncryptionPreset = ePreset;
109 // Decryption
111 void decryptEncryptionKey(OUString const & rPassword);
112 bool decryptAndCheckVerifierHash(OUString const & rPassword);
114 bool generateEncryptionKey(OUString const & rPassword) override;
115 bool readEncryptionInfo(css::uno::Reference<css::io::XInputStream> & rxInputStream) override;
116 bool decrypt(BinaryXInputStream& aInputStream,
117 BinaryXOutputStream& aOutputStream) override;
119 bool checkDataIntegrity() override;
121 bool decryptHmacKey();
122 bool decryptHmacValue();
124 // Encryption
126 void writeEncryptionInfo(BinaryXOutputStream& rStream) override;
128 void encrypt(const css::uno::Reference<css::io::XInputStream>& rxInputStream,
129 css::uno::Reference<css::io::XOutputStream>& rxOutputStream,
130 sal_uInt32 nSize) override;
132 bool setupEncryption(OUString const & rPassword) override;
134 bool generateAndEncryptVerifierHash(OUString const & rPassword);
136 bool encryptHmacKey();
137 bool encryptHmacValue();
139 bool encryptEncryptionKey(OUString const & rPassword);
140 void setupEncryptionParameters(AgileEncryptionParameters const & rAgileEncryptionParameters);
141 bool setupEncryptionKey(OUString const & rPassword);
144 } // namespace oox::crypto
146 #endif
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */