update credits
[LibreOffice.git] / include / oox / crypto / Standard2007Engine.hxx
blob2d76bee8942cf64eda5dfa90bdb638589bad4479
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_STANDARD2007ENGINE_HXX
12 #define INCLUDED_OOX_CRYPTO_STANDARD2007ENGINE_HXX
14 #include <oox/crypto/CryptTools.hxx>
15 #include <oox/crypto/CryptoEngine.hxx>
17 namespace oox {
18 namespace core {
20 const sal_uInt32 ENCRYPTINFO_CRYPTOAPI = 0x00000004;
21 const sal_uInt32 ENCRYPTINFO_DOCPROPS = 0x00000008;
22 const sal_uInt32 ENCRYPTINFO_EXTERNAL = 0x00000010;
23 const sal_uInt32 ENCRYPTINFO_AES = 0x00000020;
25 const sal_uInt32 ENCRYPT_ALGO_AES128 = 0x0000660E;
26 const sal_uInt32 ENCRYPT_ALGO_AES192 = 0x0000660F;
27 const sal_uInt32 ENCRYPT_ALGO_AES256 = 0x00006610;
28 const sal_uInt32 ENCRYPT_ALGO_RC4 = 0x00006801;
30 const sal_uInt32 ENCRYPT_HASH_SHA1 = 0x00008004;
32 const sal_uInt32 ENCRYPT_KEY_SIZE_AES_128 = 0x00000080;
33 const sal_uInt32 ENCRYPT_KEY_SIZE_AES_192 = 0x000000C0;
34 const sal_uInt32 ENCRYPT_KEY_SIZE_AES_256 = 0x00000100;
36 const sal_uInt32 ENCRYPT_PROVIDER_TYPE_AES = 0x00000018;
37 const sal_uInt32 ENCRYPT_PROVIDER_TYPE_RC4 = 0x00000001;
39 // version of encryption info used in MS Office 2007 (major = 3, minor = 2)
40 const sal_uInt32 VERSION_INFO_2007_FORMAT = 0x00020003;
41 // version of encryption info used in MS Office 2007 SP2 and older (major = 4, minor = 2)
42 const sal_uInt32 VERSION_INFO_2007_FORMAT_SP2 = 0x00020004;
44 // version of encryption info - agile (major = 4, minor = 4)
45 const sal_uInt32 VERSION_INFO_AGILE = 0x00040004;
47 const sal_uInt32 SALT_LENGTH = 16;
48 const sal_uInt32 ENCRYPTED_VERIFIER_LENGTH = 16;
49 const sal_uInt32 ENCRYPTED_VERIFIER_HASH_LENGTH = 32;
51 struct EncryptionStandardHeader
53 sal_uInt32 flags;
54 sal_uInt32 sizeExtra; // 0
55 sal_uInt32 algId; // if flag AES && CRYPTOAPI this defaults to 128-bit AES
56 sal_uInt32 algIdHash; // 0: determine by flags - defaults to SHA-1 if not external
57 sal_uInt32 keyBits; // key size in bits: 0 (determine by flags), 128, 192, 256
58 sal_uInt32 providedType; // AES or RC4
59 sal_uInt32 reserved1; // 0
60 sal_uInt32 reserved2; // 0
62 EncryptionStandardHeader();
65 struct EncryptionVerifierAES
67 sal_uInt32 saltSize; // must be 0x00000010
68 sal_uInt8 salt[SALT_LENGTH]; // random generated salt value
69 sal_uInt8 encryptedVerifier[ENCRYPTED_VERIFIER_LENGTH]; // randomly generated verifier value
70 sal_uInt32 encryptedVerifierHashSize; // actually written hash size - depends on algorithm
71 sal_uInt8 encryptedVerifierHash[ENCRYPTED_VERIFIER_HASH_LENGTH]; // verifier value hash - itself also encrypted
73 EncryptionVerifierAES();
76 struct StandardEncryptionInfo
78 EncryptionStandardHeader header;
79 EncryptionVerifierAES verifier;
82 class Standard2007Engine : public CryptoEngine
84 StandardEncryptionInfo mInfo;
86 bool generateVerifier();
87 bool calculateEncryptionKey(const OUString& rPassword);
89 public:
90 Standard2007Engine();
91 virtual ~Standard2007Engine();
93 StandardEncryptionInfo& getInfo() { return mInfo;}
95 virtual bool generateEncryptionKey(const OUString& rPassword) SAL_OVERRIDE;
97 virtual bool writeEncryptionInfo(
98 const OUString& rPassword,
99 BinaryXOutputStream& rStream) SAL_OVERRIDE;
101 virtual bool decrypt(
102 BinaryXInputStream& aInputStream,
103 BinaryXOutputStream& aOutputStream) SAL_OVERRIDE;
105 virtual bool encrypt(
106 BinaryXInputStream& aInputStream,
107 BinaryXOutputStream& aOutputStream) SAL_OVERRIDE;
111 } // namespace core
112 } // namespace oox
114 #endif
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */