android: Update app-specific/MIME type icons
[LibreOffice.git] / include / oox / crypto / CryptTools.hxx
blob10382b9793800dc4a199b5046a5d86e8c471184e
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 <oox/dllapi.h>
24 #include <sal/types.h>
26 #include <vector>
27 #include <memory>
29 namespace oox::crypto {
31 /** Rounds up the input to the nearest multiple
33 * For example:
34 * input 1, multiple 16 = 16
35 * input 16, multiple 16 = 16
36 * input 17, multiple 16 = 32
37 * input 31, multiple 16 = 32
39 template<typename T>
40 T roundUp(T input, T multiple)
42 if (input % multiple == 0)
43 return input;
44 return ((input / multiple) * multiple) + multiple;
47 enum class CryptoHashType
49 SHA1,
50 SHA256,
51 SHA384,
52 SHA512
55 struct CryptoImpl;
57 class OOX_DLLPUBLIC Crypto
59 public:
60 enum CryptoType
62 UNKNOWN,
63 AES_128_ECB,
64 AES_128_CBC,
65 AES_256_CBC,
68 protected:
69 std::unique_ptr<CryptoImpl> mpImpl;
71 protected:
72 Crypto();
74 public:
75 virtual ~Crypto();
78 class Decrypt final : public Crypto
80 public:
81 Decrypt(std::vector<sal_uInt8>& key, std::vector<sal_uInt8>& iv, CryptoType type);
83 sal_uInt32 update(
84 std::vector<sal_uInt8>& output,
85 std::vector<sal_uInt8>& input,
86 sal_uInt32 inputLength = 0);
89 static sal_uInt32 aes128ecb(
90 std::vector<sal_uInt8>& output,
91 std::vector<sal_uInt8>& input,
92 std::vector<sal_uInt8>& key );
96 class Encrypt final : public Crypto
98 public:
99 Encrypt(std::vector<sal_uInt8>& key, std::vector<sal_uInt8>& iv, CryptoType type);
101 sal_uInt32 update(
102 std::vector<sal_uInt8>& output,
103 std::vector<sal_uInt8>& input,
104 sal_uInt32 inputLength = 0);
107 class OOX_DLLPUBLIC CryptoHash final : public Crypto
109 sal_Int32 mnHashSize;
110 public:
111 CryptoHash(std::vector<sal_uInt8>& rKey, CryptoHashType eType);
112 bool update(std::vector<sal_uInt8>& rInput, sal_uInt32 nInputLength = 0);
113 std::vector<sal_uInt8> finalize();
117 } // namespace oox::crypto
119 #endif
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */