1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
29 namespace oox::crypto
{
31 /** Rounds up the input to the nearest multiple
34 * input 1, multiple 16 = 16
35 * input 16, multiple 16 = 16
36 * input 17, multiple 16 = 32
37 * input 31, multiple 16 = 32
40 T
roundUp(T input
, T multiple
)
42 if (input
% multiple
== 0)
44 return ((input
/ multiple
) * multiple
) + multiple
;
47 enum class CryptoHashType
57 class OOX_DLLPUBLIC Crypto
69 std::unique_ptr
<CryptoImpl
> mpImpl
;
78 class Decrypt final
: public Crypto
81 Decrypt(std::vector
<sal_uInt8
>& key
, std::vector
<sal_uInt8
>& iv
, CryptoType type
);
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
99 Encrypt(std::vector
<sal_uInt8
>& key
, std::vector
<sal_uInt8
>& iv
, CryptoType type
);
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
;
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
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */