UtilsLite
Utilities for C++ programming
Loading...
Searching...
No Matches
Utils_SHA3.hh
Go to the documentation of this file.
1#pragma once
2
3#ifndef UTILS_SHA3_HH
4#define UTILS_SHA3_HH
5
6#include "Utils.hh"
7
8#include <string>
9#include <iostream>
10#include <cstdint>
11
12namespace Utils {
13
27 class SHA3 {
28
29 using uint8_t = std::uint8_t;
30 using uint64_t = std::uint64_t;
31
32 // Round state
33 uint8_t *m_buffer_location{nullptr}; // used for writing and to know when to flush the buffer
34 uint64_t m_state[5][5];
35 uint64_t m_message_buffer_64[1600/8]; // rate bits wide, defined during construction
36
37 int m_digest_size{0}; // bytes
38
39 // Digest-length specific Values
40 int m_sponge_capacity{0};
41 int m_sponge_rate{0};
42
43 void m_reset();
44 void m_perform_rounds( int rounds );
45 void m_absorb_buffer();
46
47 // Debugging
48 void m_print_message_buffer( ostream_type & stream ) const;
49 void m_print_sponge( ostream_type & stream ) const;
50
51 public:
52
60 explicit SHA3( int digest_size );
61
63 ~SHA3() { }
64
73 void hash_string( string_view str );
74
83 void hash_hex_string( string_view str );
84
94 string digest_in_hex();
95
96
104 int digest_size() const { return m_digest_size; }
105
113 void hash( const int b );
114
123 void digest( uint8_t * d );
124 };
125}
126
127#endif
SHA3(int digest_size)
Constructor for the SHA3 class.
Definition Utils_SHA3.cc:43
void hash_hex_string(string_view str)
Adds an entire hexadecimal string to the message.
Definition Utils_SHA3.cc:72
void hash_string(string_view str)
Adds an entire string to the message.
Definition Utils_SHA3.cc:63
int digest_size() const
Returns the size of the hash digest.
Definition Utils_SHA3.hh:104
void hash(const int b)
Hash a specified number of bytes.
Definition Utils_SHA3.cc:53
~SHA3()
Destructor for the SHA3 class.
Definition Utils_SHA3.hh:63
void digest(uint8_t *d)
Retrieve the digest and store it in the provided byte array.
Definition Utils_SHA3.cc:93
string digest_in_hex()
Returns a representation of the digest as a hexadecimal string.
Definition Utils_SHA3.cc:111
Definition SystemUtils.cc:39
std::basic_ostream< char > ostream_type
Type for output stream.
Definition Console.hxx:28