1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Copyright (C) 2013 Richard J. Moore <rich@kde.org>.
5** Contact: https://www.qt.io/licensing/
6**
7** This file is part of the QtCore module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial License Usage
11** Licensees holding valid commercial Qt licenses may use this file in
12** accordance with the commercial license agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and The Qt Company. For licensing terms
15** and conditions see https://www.qt.io/terms-conditions. For further
16** information use the contact form at https://www.qt.io/contact-us.
17**
18** GNU Lesser General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU Lesser
20** General Public License version 3 as published by the Free Software
21** Foundation and appearing in the file LICENSE.LGPL3 included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU Lesser General Public License version 3 requirements
24** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25**
26** GNU General Public License Usage
27** Alternatively, this file may be used under the terms of the GNU
28** General Public License version 2.0 or (at your option) the GNU General
29** Public license version 3 or any later version approved by the KDE Free
30** Qt Foundation. The licenses are as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32** included in the packaging of this file. Please review the following
33** information to ensure the GNU General Public License requirements will
34** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35** https://www.gnu.org/licenses/gpl-3.0.html.
36**
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41#ifndef QCRYPTOGRAPHICHASH_H
42#define QCRYPTOGRAPHICHASH_H
43
44#include <QtCore/qbytearray.h>
45#include <QtCore/qobjectdefs.h>
46
47QT_BEGIN_NAMESPACE
48
49
50class QCryptographicHashPrivate;
51class QIODevice;
52
53class Q_CORE_EXPORT QCryptographicHash
54{
55 Q_GADGET
56public:
57 enum Algorithm {
58#ifndef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
59 Md4,
60 Md5,
61#endif
62 Sha1 = 2,
63#ifndef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
64 Sha224,
65 Sha256,
66 Sha384,
67 Sha512,
68
69 Keccak_224 = 7,
70 Keccak_256,
71 Keccak_384,
72 Keccak_512,
73 RealSha3_224 = 11,
74 RealSha3_256,
75 RealSha3_384,
76 RealSha3_512,
77# ifndef QT_SHA3_KECCAK_COMPAT
78 Sha3_224 = RealSha3_224,
79 Sha3_256 = RealSha3_256,
80 Sha3_384 = RealSha3_384,
81 Sha3_512 = RealSha3_512,
82# else
83 Sha3_224 = Keccak_224,
84 Sha3_256 = Keccak_256,
85 Sha3_384 = Keccak_384,
86 Sha3_512 = Keccak_512,
87# endif
88
89 Blake2b_160 = 15,
90 Blake2b_256,
91 Blake2b_384,
92 Blake2b_512,
93 Blake2s_128,
94 Blake2s_160,
95 Blake2s_224,
96 Blake2s_256,
97#endif
98 };
99 Q_ENUM(Algorithm)
100
101 explicit QCryptographicHash(Algorithm method);
102 ~QCryptographicHash();
103
104 void reset();
105
106 void addData(const char *data, qsizetype length);
107 void addData(const QByteArray &data);
108 bool addData(QIODevice *device);
109
110 QByteArray result() const;
111
112 static QByteArray hash(const QByteArray &data, Algorithm method);
113 static int hashLength(Algorithm method);
114private:
115 Q_DISABLE_COPY(QCryptographicHash)
116 QCryptographicHashPrivate *d;
117};
118
119QT_END_NAMESPACE
120
121#endif
122