lhashes  1.0.0
C++ hashes library
lhashes_sha224.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 <array>
21 #include "lhashes/lhashes_Export.h"
22 #include "lhashes/lhashes_hash.h"
23 
30 namespace limes::hash
31 {
32 
37 class LHASH_EXPORT SHA224 final : public Hasher // cppcheck-suppress noConstructor
38 {
39 public:
41  void update (const unsigned char* message, std::size_t len) final;
42 
44  [[nodiscard]] std::string getHash() final;
45 
47  [[nodiscard]] std::size_t getLengthOfHash() const final;
48 
49 private:
50  void transform (const unsigned char* message, unsigned block_nb) noexcept;
51 
52  static constexpr auto blocksize = 512 / 8;
53 
54  unsigned m_len { 0u };
55  unsigned m_tot_len { 0u };
56 
57  unsigned char m_block[2 * blocksize] = {};
58 
59  std::uint32_t m_h[8] { 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 };
60 };
61 
67 [[nodiscard]] LHASH_EXPORT std::string sha224 (const char* input, std::size_t length);
68 
74 [[nodiscard]] LHASH_EXPORT std::string sha224 (std::string_view input);
75 
76 } // 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 SHA224 hash.
void update(const unsigned char *message, std::size_t len) final
Updates the internal state of the hasher with new data.
std::string getHash() final
Retrieves the calculated SHA224 hash value as a string.
LHASH_EXPORT std::string sha224(const char *input, std::size_t length)
Calculates a SHA224 hash for the given data.
LHASH_EXPORT std::string sha224(std::string_view input)
Calculates a SHA224 hash for the given data.
This file defines the hash::Hasher class and the hash::hash() free functions.
Cryptographic hash functions.