lhashes  1.0.0
C++ hashes library
lhashes_sha384.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 <string>
18 #include <string_view>
19 #include <cstdint>
20 #include "lhashes/lhashes_Export.h"
21 #include "lhashes/lhashes_hash.h"
22 
29 namespace limes::hash
30 {
31 
36 class LHASH_EXPORT SHA384 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] = {}; // NOLINT
57 
58  std::uint64_t m_h[8] = { 0xcbbb9d5dc1059ed8ULL, 0x629a292a367cd507ULL, 0x9159015a3070dd17ULL, 0x152fecd8f70e5939ULL, 0x67332667ffc00b31ULL, 0x8eb44a8768581511ULL, 0xdb0c2e0d64f98fa7ULL, 0x47b5481dbefa4fa4ULL }; // NOLINT
59 };
60 
66 [[nodiscard]] LHASH_EXPORT std::string sha384 (const char* input, std::size_t length);
67 
73 [[nodiscard]] LHASH_EXPORT std::string sha384 (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 SHA384 hash.
std::string getHash() final
Retrieves the calculated SHA384 hash value as a string.
void update(const unsigned char *data, std::size_t length) final
Updates the internal state of the hasher with new data.
LHASH_EXPORT std::string sha384(std::string_view input)
Calculates a SHA384 hash for the given string.
LHASH_EXPORT std::string sha384(const char *input, std::size_t length)
Calculates a SHA384 hash for the given data.
This file defines the hash::Hasher class and the hash::hash() free functions.
Cryptographic hash functions.