LibreOffice Module comphelper (master) 1
hash.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
10#ifndef INCLUDED_COMPHELPER_HASH_HXX
11#define INCLUDED_COMPHELPER_HASH_HXX
12
14#include <rtl/digest.h>
15
16#include <memory>
17#include <vector>
18
19namespace rtl {
20 class OUString;
21}
22
23namespace comphelper {
24
25enum class HashType
26{
27 MD5,
28 SHA1,
29 SHA256,
30 SHA512
31};
32
33const sal_uInt32 MD5_HASH_LENGTH = RTL_DIGEST_LENGTH_MD5;
34const sal_uInt32 SHA1_HASH_LENGTH = RTL_DIGEST_LENGTH_SHA1;
35const sal_uInt32 SHA256_HASH_LENGTH = 32;
36const sal_uInt32 SHA512_HASH_LENGTH = 64;
37
38struct HashImpl;
39
41{
42private:
43 std::unique_ptr<HashImpl> mpImpl;
44
45public:
46
47 enum class IterCount
48 {
49 NONE,
50 PREPEND,
51 APPEND
52 };
53
54 Hash(HashType eType);
55 ~Hash();
56
57 void update(const unsigned char* pInput, size_t length);
58
59 std::vector<unsigned char> finalize();
60
61 static std::vector<unsigned char> calculateHash(const unsigned char* pInput, size_t length, HashType eType);
62
92 static std::vector<unsigned char> calculateHash(
93 const unsigned char* pInput, size_t nLength,
94 const unsigned char* pSalt, size_t nSaltLen,
95 sal_uInt32 nSpinCount,
96 IterCount eIterCount,
97 HashType eType);
98
107 static std::vector<unsigned char> calculateHash(
108 const rtl::OUString& rPassword,
109 const std::vector<unsigned char>& rSaltValue,
110 sal_uInt32 nSpinCount,
111 IterCount eIterCount,
112 HashType eType);
113
114 size_t getLength() const;
115};
116
117}
118
119#endif // INCLUDED_COMPHELPER_HASH_HXX
120
121/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< HashImpl > mpImpl
Definition: hash.hxx:43
static std::vector< unsigned char > calculateHash(const rtl::OUString &rPassword, const std::vector< unsigned char > &rSaltValue, sal_uInt32 nSpinCount, IterCount eIterCount, HashType eType)
Convenience function to calculate a salted hash with iterations.
#define COMPHELPER_DLLPUBLIC
NONE
double getLength(const B2DPolygon &rCandidate)
const sal_uInt32 SHA256_HASH_LENGTH
Definition: hash.hxx:35
const sal_uInt32 SHA512_HASH_LENGTH
Definition: hash.hxx:36
const sal_uInt32 SHA1_HASH_LENGTH
Definition: hash.hxx:34
const sal_uInt32 MD5_HASH_LENGTH
Definition: hash.hxx:33
Status finalize()
APPEND
bool update()