LibreOffice Module oox (master) 1
AgileEngine.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 */
10
11#ifndef INCLUDED_OOX_CRYPTO_AGILEENGINE_HXX
12#define INCLUDED_OOX_CRYPTO_AGILEENGINE_HXX
13
14#include <vector>
15
16#include <oox/dllapi.h>
19#include <rtl/ustring.hxx>
20#include <sal/types.h>
21
22namespace oox {
23 class BinaryXInputStream;
24 class BinaryXOutputStream;
25}
26
27namespace oox::crypto {
28
30{
31 sal_Int32 spinCount;
32 sal_Int32 saltSize;
33 sal_Int32 keyBits;
34 sal_Int32 hashSize;
35 sal_Int32 blockSize;
36
39 OUString hashAlgorithm;
40
41 std::vector<sal_uInt8> keyDataSalt;
42
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;
48
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
55};
56
58{
59 sal_Int32 spinCount;
60 sal_Int32 saltSize;
61 sal_Int32 keyBits;
62 sal_Int32 hashSize;
63 sal_Int32 blockSize;
64
67 OUString hashAlgorithm;
68};
69
71{
74};
75
77{
78private:
81
82 void calculateHashFinal(const OUString& rPassword, std::vector<sal_uInt8>& aHashFinal);
83
84 void calculateBlock(
85 std::vector<sal_uInt8> const & rBlock,
86 std::vector<sal_uInt8>& rHashFinal,
87 std::vector<sal_uInt8>& rInput,
88 std::vector<sal_uInt8>& rOutput);
89
90 void encryptBlock(
91 std::vector<sal_uInt8> const & rBlock,
92 std::vector<sal_uInt8>& rHashFinal,
93 std::vector<sal_uInt8>& rInput,
94 std::vector<sal_uInt8>& rOutput);
95
96 static Crypto::CryptoType cryptoType(const AgileEncryptionInfo& rInfo);
97
98public:
100
102
104 {
105 meEncryptionPreset = ePreset;
106 }
107
108 // Decryption
109
110 void decryptEncryptionKey(OUString const & rPassword);
111 bool decryptAndCheckVerifierHash(OUString const & rPassword);
112
113 bool generateEncryptionKey(OUString const & rPassword) override;
114 bool readEncryptionInfo(css::uno::Reference<css::io::XInputStream> & rxInputStream) override;
115 bool decrypt(BinaryXInputStream& aInputStream,
116 BinaryXOutputStream& aOutputStream) override;
117
118 bool checkDataIntegrity() override;
119
120 bool decryptHmacKey();
121 bool decryptHmacValue();
122
123 // Encryption
124
125 void writeEncryptionInfo(BinaryXOutputStream& rStream) override;
126
127 void encrypt(const css::uno::Reference<css::io::XInputStream>& rxInputStream,
128 css::uno::Reference<css::io::XOutputStream>& rxOutputStream,
129 sal_uInt32 nSize) override;
130
131 bool setupEncryption(OUString const & rPassword) override;
132
133 bool generateAndEncryptVerifierHash(OUString const & rPassword);
134
135 bool encryptHmacKey();
136 bool encryptHmacValue();
137
138 bool encryptEncryptionKey(OUString const & rPassword);
139 void setupEncryptionParameters(AgileEncryptionParameters const & rAgileEncryptionParameters);
140 bool setupEncryptionKey(OUString const & rPassword);
141};
142
143} // namespace oox::crypto
144
145#endif
146
147/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AgileEncryptionInfo & mInfo
Definition: AgileEngine.cxx:76
Wraps a UNO input stream and provides convenient access functions.
Wraps a UNO output stream and provides convenient access functions.
AgileEncryptionPreset meEncryptionPreset
Definition: AgileEngine.hxx:80
AgileEncryptionInfo & getInfo()
void setPreset(AgileEncryptionPreset ePreset)
AgileEncryptionInfo mInfo
Definition: AgileEngine.hxx:79
#define OOX_DLLPUBLIC
Definition: dllapi.h:28
std::vector< sal_uInt8 > hmacEncryptedKey
Definition: AgileEngine.hxx:53
std::vector< sal_uInt8 > hmacCalculatedHash
Definition: AgileEngine.hxx:52
std::vector< sal_uInt8 > hmacKey
Definition: AgileEngine.hxx:50
std::vector< sal_uInt8 > encryptedVerifierHashInput
Definition: AgileEngine.hxx:45
std::vector< sal_uInt8 > keyDataSalt
Definition: AgileEngine.hxx:41
std::vector< sal_uInt8 > encryptedKeyValue
Definition: AgileEngine.hxx:47
std::vector< sal_uInt8 > saltValue
Definition: AgileEngine.hxx:44
std::vector< sal_uInt8 > encryptedVerifierHashValue
Definition: AgileEngine.hxx:46
std::vector< sal_uInt8 > hmacEncryptedValue
Definition: AgileEngine.hxx:54
std::vector< sal_uInt8 > hmacHash
Definition: AgileEngine.hxx:51