24 #ifndef INC_KECCAK_HPP_6A4377C8_9736_4336_BCAB_C8D49C398CA7
25 #define INC_KECCAK_HPP_6A4377C8_9736_4336_BCAB_C8D49C398CA7
75 void reset() override final;
83 void update(const uint8_t* buf,
size_t len) override final;
105 static inline constexpr uint64_t rol(uint64_t x,
int n)
107 return ((x << n) | (x >> (64 - n)));
150 uint8_t*
getValue(uint8_t* buffer)
const override;
159 size_t getSize() const override final {
return 28; }
223 return ChecksumAlgoId::SHA3_224;
279 uint8_t*
getValue(uint8_t* buffer)
const override;
288 size_t getSize() const override final {
return 32; }
352 return ChecksumAlgoId::SHA3_256;
408 uint8_t*
getValue(uint8_t* buffer)
const override final;
417 size_t getSize() const override final {
return 48; }
481 return ChecksumAlgoId::SHA3_384;
537 uint8_t*
getValue(uint8_t* buffer)
const override final;
546 size_t getSize() const override final {
return 64; }
610 return ChecksumAlgoId::SHA3_512;
651 class Keccak224 final :
public AbstractKeccakImpl
657 Keccak224() : AbstractKeccakImpl(Keccak224::getSize(), false) {}
667 uint8_t* getValue(uint8_t* buffer)
const override final;
676 size_t getSize() const override final {
return 28; }
683 std::string getName() const override final
685 return getHashName();
695 return getAlternativeNames();
709 return getIdentifier();
717 static std::string getHashName()
740 return ChecksumAlgoId::Keccak224;
751 static Checksum* getNewInstance()
753 return new Keccak224();
780 class Keccak256 final :
public AbstractKeccakImpl
786 Keccak256() : AbstractKeccakImpl(Keccak256::getSize(), false) {}
796 uint8_t* getValue(uint8_t* buffer)
const override;
805 size_t getSize() const override final {
return 32; }
812 std::string getName() const override final
814 return getHashName();
824 return getAlternativeNames();
838 return getIdentifier();
846 static std::string getHashName()
869 return ChecksumAlgoId::Keccak256;
880 static Checksum* getNewInstance()
882 return new Keccak256();
909 class Keccak384 final :
public AbstractKeccakImpl
915 Keccak384() : AbstractKeccakImpl(Keccak384::getSize(), false) {}
925 uint8_t* getValue(uint8_t* buffer)
const override;
934 size_t getSize() const override final {
return 48; }
941 std::string getName() const override final
943 return getHashName();
953 return getAlternativeNames();
967 return getIdentifier();
975 static std::string getHashName()
998 return ChecksumAlgoId::Keccak384;
1009 static Checksum* getNewInstance()
1011 return new Keccak384();
1038 class Keccak512 final :
public AbstractKeccakImpl
1044 Keccak512() : AbstractKeccakImpl(Keccak512::getSize(), false) {}
1054 uint8_t* getValue(uint8_t* buffer)
const override final;
1063 size_t getSize() const override final {
return 64; }
1070 std::string getName() const override final
1072 return getHashName();
1082 return getAlternativeNames();
1096 return getIdentifier();
1104 static std::string getHashName()
1127 return ChecksumAlgoId::Keccak512;
1138 static Checksum* getNewInstance()
1140 return new Keccak512();
Add some utilities to Checksum class.
Computes the Keccak hash from a byte stream.
void update(const uint8_t *buf, size_t len) override final
Updates the Keccak hash with specified array of bytes.
const bool useSHA3Hash
true if result is SHA3 hash, false if "original" Keccak hash.
unsigned byteIndex
0..7–the next byte after the set one (starts from 0; 0–none are buffered).
AbstractKeccakImpl()=delete
Disable default constructor.
unsigned wordIndex
0..24–the next word to integrate input (starts from 0).
void reset() override final
Resets the Keccak hash to initial value.
uint64_t state[SHA3_KECCAK_SPONGE_WORDS]
Keccak's state in 'words'.
void finish()
Process the remaining bytes in the internal buffer and the usual prolog according to the standard.
static constexpr unsigned SHA3_KECCAK_SPONGE_WORDS
'Words' here refers to uint64_t
uint64_t saved
The portion of the input message that we didn't consume yet.
const unsigned capacityWords
The double size of the hash output in words (e.g. 16 for Keccak 512).
Computes a hash from a byte stream.
Computes a checksum from a byte stream.
Computes the SHA3-224 hash from a byte stream.
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the hash algorithm.
ChecksumAlgoId getID() const override final
Returns an unique identifier for the checksum or the hash algorithm.
SHA3_224()
Default constructor.
size_t getSize() const override final
Returns the minimal size to allocate in memory to store the hash with the getValue(buffer) method.
uint8_t * getValue(uint8_t *buffer) const override
Returns the SHA3-224 hash value in the first 28 bytes of the given address.
static ArrayString getAlternativeNames()
Returns the alternative names of the SHA3-224 hash algorithm.
static std::string getHashName()
Returns the name of the hash algorithm.
ArrayString getAltNames() const override final
Returns the alternative names of the SHA3-224 hash algorithm.
static Checksum * getNewInstance()
Gets a new instance of this class.
std::string getName() const override final
Returns the name of the checksum or the hash algorithm.
Computes the SHA3-256 hash from a byte stream.
static std::string getHashName()
Returns the name of the hash algorithm.
static ArrayString getAlternativeNames()
Returns the alternative names of the SHA3-256 hash algorithm.
SHA3_256()
Default constructor.
std::string getName() const override final
Returns the name of the checksum or the hash algorithm.
static Checksum * getNewInstance()
Gets a new instance of this class.
ChecksumAlgoId getID() const override final
Returns an unique identifier for the checksum or the hash algorithm.
size_t getSize() const override final
Returns the minimal size to allocate in memory to store the hash with the getValue(buffer) method.
ArrayString getAltNames() const override final
Returns the alternative names of the SHA3-256 hash algorithm.
uint8_t * getValue(uint8_t *buffer) const override
Returns the SHA3-256 hash value in the first 32 bytes of the given address.
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the hash algorithm.
Computes the SHA3-384 hash from a byte stream.
ChecksumAlgoId getID() const override final
Returns an unique identifier for the checksum or the hash algorithm.
ArrayString getAltNames() const override final
Returns the alternative names of the SHA3-384 hash algorithm.
size_t getSize() const override final
Returns the minimal size to allocate in memory to store the hash with the getValue(buffer) method.
SHA3_384()
Default constructor.
static Checksum * getNewInstance()
Gets a new instance of this class.
uint8_t * getValue(uint8_t *buffer) const override final
Returns the SHA3-384 hash value in the first 48 bytes of the given address.
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the hash algorithm.
static ArrayString getAlternativeNames()
Returns the alternative names of the SHA3-384 hash algorithm.
std::string getName() const override final
Returns the name of the checksum or the hash algorithm.
static std::string getHashName()
Returns the name of the hash algorithm.
Computes the SHA3-512 hash from a byte stream.
std::string getName() const override final
Returns the name of the checksum or the hash algorithm.
ChecksumAlgoId getID() const override final
Returns an unique identifier for the checksum or the hash algorithm.
ArrayString getAltNames() const override final
Returns the alternative names of the SHA3-512 hash algorithm.
static Checksum * getNewInstance()
Gets a new instance of this class.
static std::string getHashName()
Returns the name of the hash algorithm.
static ArrayString getAlternativeNames()
Returns the alternative names of the SHA3-512 hash algorithm.
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the hash algorithm.
uint8_t * getValue(uint8_t *buffer) const override final
Returns the SHA3-512 hash value in the first 64 bytes of the given address.
SHA3_512()
Default constructor.
size_t getSize() const override final
Returns the minimal size to allocate in memory to store the hash with the getValue(buffer) method.
ChecksumAlgoId
Ids of algorithms of checksums.
std::vector< std::string > ArrayString
Array of strings.