update credits
[LibreOffice.git] / include / oox / crypto / CryptTools.hxx
blob86bfb79fa2d389a3db8fedf394b9d98c7bc2be26
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 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_OOX_CRYPTO_CRYPTTOOLS_HXX
21 #define INCLUDED_OOX_CRYPTO_CRYPTTOOLS_HXX
23 #include <config_oox.h>
25 #include <rtl/ustring.hxx>
27 #if USE_TLS_OPENSSL
28 #include <openssl/evp.h>
29 #include <openssl/sha.h>
30 #endif // USE_TLS_OPENSSL
32 #if USE_TLS_NSS
33 #include <nss.h>
34 #include <pk11pub.h>
35 #include <sechash.h>
36 #endif // USE_TLS_NSS
38 #include <rtl/digest.h>
39 #include <vector>
41 namespace oox {
42 namespace core {
44 class Crypto
46 public:
47 enum CryptoType
49 UNKNOWN,
50 AES_128_ECB,
51 AES_128_CBC,
52 AES_256_CBC,
55 protected:
56 CryptoType mType;
57 #if USE_TLS_OPENSSL
58 EVP_CIPHER_CTX mContext;
59 #endif
60 #if USE_TLS_NSS
61 PK11Context* mContext;
62 SECItem* mSecParam;
63 PK11SymKey* mSymKey;
64 #endif
66 #if USE_TLS_OPENSSL
67 const EVP_CIPHER* getCipher(CryptoType type);
68 #endif
69 #if USE_TLS_NSS
70 void setupContext(
71 std::vector<sal_uInt8>& key,
72 std::vector<sal_uInt8>& iv,
73 CryptoType type,
74 CK_ATTRIBUTE_TYPE operation);
75 #endif
77 protected:
78 Crypto(CryptoType type);
80 public:
81 virtual ~Crypto();
83 virtual sal_uInt32 update(
84 std::vector<sal_uInt8>& output,
85 std::vector<sal_uInt8>& input,
86 sal_uInt32 inputLength = 0) = 0;
89 class Decrypt : public Crypto
91 public:
92 Decrypt(std::vector<sal_uInt8>& key, CryptoType type);
93 Decrypt(std::vector<sal_uInt8>& key, std::vector<sal_uInt8>& iv, CryptoType type);
95 virtual sal_uInt32 update(
96 std::vector<sal_uInt8>& output,
97 std::vector<sal_uInt8>& input,
98 sal_uInt32 inputLength = 0) SAL_OVERRIDE;
101 static sal_uInt32 aes128ecb(
102 std::vector<sal_uInt8>& output,
103 std::vector<sal_uInt8>& input,
104 std::vector<sal_uInt8>& key );
108 class Encrypt : public Crypto
110 public:
111 Encrypt(std::vector<sal_uInt8>& key, CryptoType type);
112 Encrypt(std::vector<sal_uInt8>& key, std::vector<sal_uInt8>& iv, CryptoType type);
114 virtual sal_uInt32 update(
115 std::vector<sal_uInt8>& output,
116 std::vector<sal_uInt8>& input,
117 sal_uInt32 inputLength = 0) SAL_OVERRIDE;
120 class Digest
122 public:
123 enum DigestType
125 UNKNOWN,
126 SHA1,
127 SHA512
130 static const sal_uInt32 DIGEST_LENGTH_SHA1;
131 static const sal_uInt32 DIGEST_LENGTH_SHA512;
133 private:
134 DigestType meType;
136 #if USE_TLS_OPENSSL
137 EVP_MD_CTX* mpContext;
138 #endif
140 #if USE_TLS_NSS
141 HASHContext* mpContext;
142 #endif
144 public:
145 Digest(DigestType eType);
146 virtual ~Digest();
148 bool update(std::vector<sal_uInt8>& input);
149 bool finalize(std::vector<sal_uInt8>& digest);
151 sal_uInt32 getLength();
153 static bool sha1( std::vector<sal_uInt8>& digest, std::vector<sal_uInt8>& input);
154 static bool sha512(std::vector<sal_uInt8>& digest, std::vector<sal_uInt8>& input);
157 bool sha1( std::vector<sal_uInt8>& digest, std::vector<sal_uInt8>& input);
158 bool sha512(std::vector<sal_uInt8>& digest, std::vector<sal_uInt8>& input);
160 } // namespace core
161 } // namespace oox
163 #endif
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */