Crypto++  5.6.4
Free C++ class library of cryptographic schemes
sha3.h
Go to the documentation of this file.
1 // sha3.h - written and placed in the public domain by Wei Dai
2 
3 //! \file sha3.h
4 //! \brief Classes for SHA3 message digests
5 //! \details The Crypto++ implementation conforms to the FIPS 202 version of SHA3 using F1600 with XOF d=0x06.
6 //! Previous behavior (XOF d=0x01) is available in Keccak classes.
7 //! \sa <a href="http://en.wikipedia.org/wiki/SHA-3">SHA-3</a>,
8 //! <A HREF="http://csrc.nist.gov/groups/ST/hash/sha-3/fips202_standard_2015.html">SHA-3 STANDARD (FIPS 202)</A>.
9 //! \since Crypto++ 5.6.2
10 
11 #ifndef CRYPTOPP_SHA3_H
12 #define CRYPTOPP_SHA3_H
13 
14 #include "cryptlib.h"
15 #include "secblock.h"
16 
17 NAMESPACE_BEGIN(CryptoPP)
18 
19 //! \class SHA3
20 //! \brief SHA3 message digest base class
21 //! \details The Crypto++ implementation conforms to FIPS 202 version of SHA3 using F1600 with XOF d=0x06.
22 //! Previous behavior (XOF d=0x01) is available in Keccak classes.
23 //! \details SHA3 is the base class for SHA3_224, SHA3_256, SHA3_384 and SHA3_512.
24 //! Library users should instantiate a derived class, and only use SHA3
25 //! as a base class reference or pointer.
26 //! \sa Keccak, SHA3_224, SHA3_256, SHA3_384 and SHA3_512.
27 //! \since Crypto++ 5.6.2
28 class SHA3 : public HashTransformation
29 {
30 public:
31  //! \brief Construct a SHA3
32  //! \param digestSize the digest size, in bytes
33  //! \details SHA3 is the base class for SHA3_224, SHA3_256, SHA3_384 and SHA3_512.
34  //! Library users should instantiate a derived class, and only use SHA3
35  //! as a base class reference or pointer.
36  SHA3(unsigned int digestSize) : m_digestSize(digestSize) {Restart();}
37  unsigned int DigestSize() const {return m_digestSize;}
38  std::string AlgorithmName() const {return "SHA3-" + IntToString(m_digestSize*8);}
39  unsigned int OptimalDataAlignment() const {return GetAlignmentOf<word64>();}
40 
41  void Update(const byte *input, size_t length);
42  void Restart();
43  void TruncatedFinal(byte *hash, size_t size);
44 
45 protected:
46  inline unsigned int r() const {return 200 - 2 * m_digestSize;}
47 
49  unsigned int m_digestSize, m_counter;
50 };
51 
52 //! \class SHA3_224
53 //! \brief SHA3-224 message digest
54 //! \since Crypto++ 5.6.2
55 class SHA3_224 : public SHA3
56 {
57 public:
58  CRYPTOPP_CONSTANT(DIGESTSIZE = 28)
59 
60  //! \brief Construct a SHA3-224 message digest
61  SHA3_224() : SHA3(DIGESTSIZE) {}
62  CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "SHA3-224";}
63 };
64 
65 //! \class SHA3_256
66 //! \brief SHA3-256 message digest
67 //! \since Crypto++ 5.6.2
68 class SHA3_256 : public SHA3
69 {
70 public:
71  CRYPTOPP_CONSTANT(DIGESTSIZE = 32)
72 
73  //! \brief Construct a SHA3-256 message digest
74  SHA3_256() : SHA3(DIGESTSIZE) {}
75  CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "SHA3-256";}
76 };
77 
78 //! \class SHA3_384
79 //! \brief SHA3-384 message digest
80 //! \since Crypto++ 5.6.2
81 class SHA3_384 : public SHA3
82 {
83 public:
84  CRYPTOPP_CONSTANT(DIGESTSIZE = 48)
85 
86  //! \brief Construct a SHA3-384 message digest
87  SHA3_384() : SHA3(DIGESTSIZE) {}
88  CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "SHA3-384";}
89 };
90 
91 //! \class SHA3_512
92 //! \brief SHA3-512 message digest
93 //! \since Crypto++ 5.6.2
94 class SHA3_512 : public SHA3
95 {
96 public:
97  CRYPTOPP_CONSTANT(DIGESTSIZE = 64)
98 
99  //! \brief Construct a SHA3-512 message digest
100  SHA3_512() : SHA3(DIGESTSIZE) {}
101  CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "SHA3-512";}
102 };
103 
104 NAMESPACE_END
105 
106 #endif
SHA3_384
SHA3-384 message digest.
Definition: sha3.h:81
SHA3_256
SHA3-256 message digest.
Definition: sha3.h:68
HashTransformation
Interface for hash functions and data processing part of MACs.
Definition: cryptlib.h:922
secblock.h
Classes and functions for secure memory allocations.
SHA3::SHA3
SHA3(unsigned int digestSize)
Construct a SHA3.
Definition: sha3.h:36
SHA3_224
SHA3-224 message digest.
Definition: sha3.h:55
IntToString
std::string IntToString(T value, unsigned int base=10)
Converts a value to a string.
Definition: misc.h:530
SHA3::AlgorithmName
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: sha3.h:38
SHA3::OptimalDataAlignment
unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Definition: sha3.h:39
FixedSizeSecBlock< word64, 25 >
SHA3::DigestSize
unsigned int DigestSize() const
Provides the digest size of the hash.
Definition: sha3.h:37
SHA3_512
SHA3-512 message digest.
Definition: sha3.h:94
CryptoPP
Crypto++ library namespace.
SHA3
SHA3 message digest base class.
Definition: sha3.h:28
cryptlib.h
Abstract base classes that provide a uniform interface to this library.