LibreOffice Module oox (master) 1
CryptTools.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 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#ifndef INCLUDED_OOX_CRYPTO_CRYPTTOOLS_HXX
21#define INCLUDED_OOX_CRYPTO_CRYPTTOOLS_HXX
22
23#include <oox/dllapi.h>
24#include <sal/types.h>
25
26#include <vector>
27#include <memory>
28
29namespace oox::crypto {
30
39template<typename T>
40T roundUp(T input, T multiple)
41{
42 if (input % multiple == 0)
43 return input;
44 return ((input / multiple) * multiple) + multiple;
45}
46
48{
49 SHA1,
50 SHA256,
51 SHA512
52};
53
54struct CryptoImpl;
55
57{
58public:
60 {
65 };
66
67protected:
68 std::unique_ptr<CryptoImpl> mpImpl;
69
70protected:
71 Crypto();
72
73public:
74 virtual ~Crypto();
75};
76
77class Decrypt final : public Crypto
78{
79public:
80 Decrypt(std::vector<sal_uInt8>& key, std::vector<sal_uInt8>& iv, CryptoType type);
81
82 sal_uInt32 update(
83 std::vector<sal_uInt8>& output,
84 std::vector<sal_uInt8>& input,
85 sal_uInt32 inputLength = 0);
86
87
88 static sal_uInt32 aes128ecb(
89 std::vector<sal_uInt8>& output,
90 std::vector<sal_uInt8>& input,
91 std::vector<sal_uInt8>& key );
92
93};
94
95class Encrypt final : public Crypto
96{
97public:
98 Encrypt(std::vector<sal_uInt8>& key, std::vector<sal_uInt8>& iv, CryptoType type);
99
100 sal_uInt32 update(
101 std::vector<sal_uInt8>& output,
102 std::vector<sal_uInt8>& input,
103 sal_uInt32 inputLength = 0);
104};
105
106class OOX_DLLPUBLIC CryptoHash final : public Crypto
107{
108 sal_Int32 mnHashSize;
109public:
110 CryptoHash(std::vector<sal_uInt8>& rKey, CryptoHashType eType);
111 bool update(std::vector<sal_uInt8>& rInput, sal_uInt32 nInputLength = 0);
112 std::vector<sal_uInt8> finalize();
113};
114
115
116} // namespace oox::crypto
117
118#endif
119
120/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< CryptoImpl > mpImpl
Definition: CryptTools.hxx:68
Decrypt(std::vector< sal_uInt8 > &key, std::vector< sal_uInt8 > &iv, CryptoType type)
Definition: CryptTools.cxx:351
sal_uInt32 update(std::vector< sal_uInt8 > &output, std::vector< sal_uInt8 > &input, sal_uInt32 inputLength=0)
Definition: CryptTools.cxx:368
static sal_uInt32 aes128ecb(std::vector< sal_uInt8 > &output, std::vector< sal_uInt8 > &input, std::vector< sal_uInt8 > &key)
Definition: CryptTools.cxx:393
sal_uInt32 update(std::vector< sal_uInt8 > &output, std::vector< sal_uInt8 > &input, sal_uInt32 inputLength=0)
Definition: CryptTools.cxx:419
Encrypt(std::vector< sal_uInt8 > &key, std::vector< sal_uInt8 > &iv, CryptoType type)
Definition: CryptTools.cxx:404
#define OOX_DLLPUBLIC
Definition: dllapi.h:28
Status finalize()
T roundUp(T input, T multiple)
Rounds up the input to the nearest multiple.
Definition: CryptTools.hxx:40
ResultType type
bool update()