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/.
15 #include <oox/dllapi.h>
16 #include <oox/crypto/CryptoEngine.hxx>
17 #include <rtl/ustring.hxx>
18 #include <sal/types.h>
19 #include <comphelper/crypto/Crypto.hxx>
21 namespace oox::crypto
{
23 struct OOX_DLLPUBLIC AgileEncryptionInfo
31 OUString cipherAlgorithm
;
32 OUString cipherChaining
;
33 OUString hashAlgorithm
;
35 std::vector
<sal_uInt8
> keyDataSalt
;
38 std::vector
<sal_uInt8
> saltValue
;
39 std::vector
<sal_uInt8
> encryptedVerifierHashInput
;
40 std::vector
<sal_uInt8
> encryptedVerifierHashValue
;
41 std::vector
<sal_uInt8
> encryptedKeyValue
;
44 std::vector
<sal_uInt8
> hmacKey
;
45 std::vector
<sal_uInt8
> hmacHash
;
46 std::vector
<sal_uInt8
> hmacCalculatedHash
;
47 std::vector
<sal_uInt8
> hmacEncryptedKey
; // encrypted Key
48 std::vector
<sal_uInt8
> hmacEncryptedValue
; // encrypted Hash
51 struct OOX_DLLPUBLIC AgileEncryptionParameters
59 OUString cipherAlgorithm
;
60 OUString cipherChaining
;
61 OUString hashAlgorithm
;
64 enum class AgileEncryptionPreset
71 class OOX_DLLPUBLIC AgileEngine final
: public CryptoEngine
74 AgileEncryptionInfo mInfo
;
75 AgileEncryptionPreset meEncryptionPreset
;
77 void calculateHashFinal(const OUString
& rPassword
, std::vector
<sal_uInt8
>& aHashFinal
);
80 std::vector
<sal_uInt8
> const & rBlock
,
81 std::vector
<sal_uInt8
>& rHashFinal
,
82 std::vector
<sal_uInt8
>& rInput
,
83 std::vector
<sal_uInt8
>& rOutput
);
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 static comphelper::CryptoType
cryptoType(const AgileEncryptionInfo
& rInfo
);
96 AgileEncryptionInfo
& getInfo() { return mInfo
;}
98 void setPreset(AgileEncryptionPreset ePreset
)
100 meEncryptionPreset
= ePreset
;
105 void decryptEncryptionKey(OUString
const & rPassword
);
106 bool decryptAndCheckVerifierHash(OUString
const & rPassword
);
108 bool generateEncryptionKey(OUString
const & rPassword
) override
;
109 bool readEncryptionInfo(css::uno::Reference
<css::io::XInputStream
> & rxInputStream
) override
;
110 bool decrypt(BinaryXInputStream
& aInputStream
,
111 BinaryXOutputStream
& aOutputStream
) override
;
113 bool checkDataIntegrity() override
;
115 bool decryptHmacKey();
116 bool decryptHmacValue();
120 void writeEncryptionInfo(BinaryXOutputStream
& rStream
) override
;
122 void encrypt(const css::uno::Reference
<css::io::XInputStream
>& rxInputStream
,
123 css::uno::Reference
<css::io::XOutputStream
>& rxOutputStream
,
124 sal_uInt32 nSize
) override
;
126 bool setupEncryption(OUString
const & rPassword
) override
;
128 bool generateAndEncryptVerifierHash(OUString
const & rPassword
);
130 bool encryptHmacKey();
131 bool encryptHmacValue();
133 bool encryptEncryptionKey(OUString
const & rPassword
);
134 void setupEncryptionParameters(AgileEncryptionParameters
const & rAgileEncryptionParameters
);
135 bool setupEncryptionKey(OUString
const & rPassword
);
138 } // namespace comphelper::crypto
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */