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