lhashes  1.0.0
C++ hashes library
lhashes_sha512.h
Go to the documentation of this file.
1 /*
2  * ======================================================================================
3  * __ ____ __ __ ____ ___
4  * ( ) (_ _)( \/ )( ___)/ __)
5  * )(__ _)(_ ) ( )__) \__ \
6  * (____)(____)(_/\/\_)(____)(___/
7  *
8  * This file is part of the Limes open source library and is licensed under the terms of the GNU Public License.
9  *
10  * Commercial licenses are available; contact the maintainers at ben.the.vining@gmail.com to inquire for details.
11  *
12  * ======================================================================================
13  */
14 
15 #pragma once
16 
17 #include <cstdint>
18 #include <string>
19 #include <string_view>
20 #include "lhashes/lhashes_Export.h"
21 #include "lhashes/lhashes_hash.h"
22 
29 namespace limes::hash
30 {
31 
36 class LHASH_EXPORT SHA512 final : public Hasher
37 {
38 public:
40  void update (const unsigned char* data, std::size_t length) final;
41 
43  [[nodiscard]] std::string getHash() final;
44 
46  [[nodiscard]] std::size_t getLengthOfHash() const final;
47 
48 private:
49  void transform (const unsigned char* message, unsigned block_nb) noexcept;
50 
51  static constinit const unsigned SHA384_512_BLOCK_SIZE = (1024 / 8);
52 
53  unsigned m_tot_len { 0 };
54  unsigned m_len { 0 };
55 
56  unsigned char m_block[2 * SHA384_512_BLOCK_SIZE] = {};
57 
58  std::uint64_t m_h[8] = { 0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL, 0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL, 0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL, 0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL };
59 };
60 
66 [[nodiscard]] LHASH_EXPORT std::string sha512 (const char* input, std::size_t length);
67 
73 [[nodiscard]] LHASH_EXPORT std::string sha512 (std::string_view input);
74 
75 } // namespace limes::hash
A base class representing an object that calculates a hash function.
Definition: lhashes_hash.h:69
A Hasher object that calculates a SHA512 hash.
void update(const unsigned char *data, std::size_t length) final
Updates the internal state of the hasher with new data.
std::string getHash() final
Retrieves the calculated SHA512 hash value as a string.
LHASH_EXPORT std::string sha512(std::string_view input)
Calculates a SHA512 hash for the given string.
LHASH_EXPORT std::string sha512(const char *input, std::size_t length)
Calculates a SHA512 hash for the given data.
This file defines the hash::Hasher class and the hash::hash() free functions.
Cryptographic hash functions.