Security Scol plugin
sha3.h
Go to the documentation of this file.
1// sha3.h - originally written and placed in the public domain by Wei Dai
2
10
11#ifndef CRYPTOPP_SHA3_H
12#define CRYPTOPP_SHA3_H
13
14#include "cryptlib.h"
15#include "secblock.h"
16#include "misc.h"
17
18NAMESPACE_BEGIN(CryptoPP)
19
20
29{
30protected:
39 SHA3(unsigned int digestSize) : m_digestSize(digestSize) {Restart();}
40
41public:
42 unsigned int DigestSize() const {return m_digestSize;}
43 unsigned int OptimalDataAlignment() const {return GetAlignmentOf<word64>();}
44
45 void Update(const byte *input, size_t length);
46 void Restart();
47 void TruncatedFinal(byte *hash, size_t size);
48
49protected:
50 inline unsigned int r() const {return BlockSize();}
51
53 unsigned int m_digestSize, m_counter;
54};
55
59template<unsigned int T_DigestSize>
60class SHA3_Final : public SHA3
61{
62public:
63 CRYPTOPP_CONSTANT(DIGESTSIZE = T_DigestSize);
64 CRYPTOPP_CONSTANT(BLOCKSIZE = 200 - 2 * DIGESTSIZE);
65 static std::string StaticAlgorithmName()
66 { return "SHA3-" + IntToString(DIGESTSIZE * 8); }
67
69 SHA3_Final() : SHA3(DIGESTSIZE) {}
70
77 unsigned int BlockSize() const { return BLOCKSIZE; }
78
79 std::string AlgorithmName() const { return StaticAlgorithmName(); }
80
81private:
82#if !defined(__BORLANDC__)
83 // ensure there was no underflow in the math
84 CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200);
85#endif
86};
87
90class SHA3_224 : public SHA3_Final<28> {};
91
94class SHA3_256 : public SHA3_Final<32> {};
95
98class SHA3_384 : public SHA3_Final<48> {};
99
102class SHA3_512 : public SHA3_Final<64> {};
103
104NAMESPACE_END
105
106#endif
Fixed size stack-based SecBlock.
Definition secblock.h:1246
Interface for hash functions and data processing part of MACs.
Definition cryptlib.h:1113
SHA3-224 message digest.
Definition sha3.h:90
SHA3-256 message digest.
Definition sha3.h:94
SHA3-384 message digest.
Definition sha3.h:98
SHA3-512 message digest.
Definition sha3.h:102
SHA3 message digest template.
Definition sha3.h:61
unsigned int BlockSize() const
Provides the block size of the compression function.
Definition sha3.h:77
SHA3_Final()
Construct a SHA3-X message digest.
Definition sha3.h:69
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition sha3.h:79
SHA3 message digest base class.
Definition sha3.h:29
unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Definition sha3.h:43
unsigned int DigestSize() const
Definition sha3.h:42
SHA3(unsigned int digestSize)
Construct a SHA3.
Definition sha3.h:39
Abstract base classes that provide a uniform interface to this library.
Utility functions for the Crypto++ library.
std::string IntToString(T value, unsigned int base=10)
Converts a value to a string.
Definition misc.h:724
Classes and functions for secure memory allocations.