Audacity 3.2.0
SHA256.h
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-or-later
3 * SPDX-FileName: SHA256.h
4 * SPDX-FileContributor: Dmitry Vedenko
5 */
6
7#pragma once
8
9#include <cstdint>
10#include <cstddef>
11
12#include <string>
13
14namespace crypto
15{
16class CRYPTO_API SHA256 final
17{
18public:
19 static constexpr std::size_t HASH_SIZE = 32;
20 static constexpr std::size_t BLOCK_SIZE = 64;
21
22 SHA256();
23
24 SHA256(const SHA256&) = delete;
25 SHA256(SHA256&&) = delete;
26 SHA256& operator=(const SHA256&) = delete;
27 SHA256& operator=(SHA256&&) = delete;
28
29 void Update(const void* data, std::size_t size);
30 void Update(const char* zString);
31
32 template<typename T>
33 void Update(const T& data)
34 {
35 Update(data.data(), data.size());
36 }
37
38 std::string Finalize();
39
40 void Reset();
41
42private:
43 uint64_t mBitLength;
44 uint32_t mState[8];
45 uint8_t mBuffer[BLOCK_SIZE];
46 uint32_t mBufferLength;
47}; // class SHA256
48
49template<typename T>
50std::string sha256(const T& data)
51{
52 SHA256 hasher;
53 hasher.Update(data);
54 return hasher.Finalize();
55}
56} // namespace crypto
struct State mState
SHA256(SHA256 &&)=delete
SHA256 & operator=(SHA256 &&)=delete
void Update(const void *data, std::size_t size)
Definition: SHA256.cpp:98
SHA256 & operator=(const SHA256 &)=delete
std::string Finalize()
Definition: SHA256.cpp:127
void Update(const T &data)
Definition: SHA256.h:33
SHA256(const SHA256 &)=delete
uint64_t mBitLength
Definition: SHA256.h:43
uint32_t mBufferLength
Definition: SHA256.h:46
std::string sha256(const T &data)
Definition: SHA256.h:50