1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
11 #ifndef INCLUDED_OOX_CRYPTO_AGILEENGINE_HXX
12 #define INCLUDED_OOX_CRYPTO_AGILEENGINE_HXX
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>
23 class BinaryXInputStream
;
24 class BinaryXOutputStream
;
27 namespace oox::crypto
{
29 struct OOX_DLLPUBLIC AgileEncryptionInfo
37 OUString cipherAlgorithm
;
38 OUString cipherChaining
;
39 OUString hashAlgorithm
;
41 std::vector
<sal_uInt8
> keyDataSalt
;
44 std::vector
<sal_uInt8
> saltValue
;
45 std::vector
<sal_uInt8
> encryptedVerifierHashInput
;
46 std::vector
<sal_uInt8
> encryptedVerifierHashValue
;
47 std::vector
<sal_uInt8
> encryptedKeyValue
;
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
65 OUString cipherAlgorithm
;
66 OUString cipherChaining
;
67 OUString hashAlgorithm
;
70 enum class AgileEncryptionPreset
77 class OOX_DLLPUBLIC AgileEngine final
: public CryptoEngine
80 AgileEncryptionInfo mInfo
;
81 AgileEncryptionPreset meEncryptionPreset
;
83 void calculateHashFinal(const OUString
& rPassword
, std::vector
<sal_uInt8
>& aHashFinal
);
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
);
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
);
102 AgileEncryptionInfo
& getInfo() { return mInfo
;}
104 void setPreset(AgileEncryptionPreset ePreset
)
106 meEncryptionPreset
= ePreset
;
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();
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
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */