Security Scol plugin
keccak.h
Go to the documentation of this file.
1// keccak.h - originally written and placed in the public domain by Wei Dai
2
11
12#ifndef CRYPTOPP_KECCAK_H
13#define CRYPTOPP_KECCAK_H
14
15#include "cryptlib.h"
16#include "secblock.h"
17
18NAMESPACE_BEGIN(CryptoPP)
19
20
41{
42protected:
51 Keccak(unsigned int digestSize) : m_digestSize(digestSize) {Restart();}
52
53public:
54 unsigned int DigestSize() const {return m_digestSize;}
55 unsigned int OptimalDataAlignment() const {return GetAlignmentOf<word64>();}
56
57 void Update(const byte *input, size_t length);
58 void Restart();
59 void TruncatedFinal(byte *hash, size_t size);
60
61protected:
62 inline unsigned int r() const {return BlockSize();}
63
65 unsigned int m_digestSize, m_counter;
66};
67
71template<unsigned int T_DigestSize>
72class Keccak_Final : public Keccak
73{
74public:
75 CRYPTOPP_CONSTANT(DIGESTSIZE = T_DigestSize);
76 CRYPTOPP_CONSTANT(BLOCKSIZE = 200 - 2 * DIGESTSIZE);
77 static std::string StaticAlgorithmName()
78 { return "Keccak-" + IntToString(DIGESTSIZE * 8); }
79
81 Keccak_Final() : Keccak(DIGESTSIZE) {}
82
89 unsigned int BlockSize() const { return BLOCKSIZE; }
90
91 std::string AlgorithmName() const { return StaticAlgorithmName(); }
92
93private:
94#if !defined(__BORLANDC__)
95 // ensure there was no underflow in the math
96 CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200);
97#endif
98};
99
102DOCUMENTED_TYPEDEF(Keccak_Final<28>, Keccak_224);
103
106DOCUMENTED_TYPEDEF(Keccak_Final<32>, Keccak_256);
107
110DOCUMENTED_TYPEDEF(Keccak_Final<48>, Keccak_384);
111
114DOCUMENTED_TYPEDEF(Keccak_Final<64>, Keccak_512);
115
116NAMESPACE_END
117
118#endif
Fixed size stack-based SecBlock.
Definition secblock.h:1246
Interface for hash functions and data processing part of MACs.
Definition cryptlib.h:1113
Keccak message digest template.
Definition keccak.h:73
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition keccak.h:91
unsigned int BlockSize() const
Provides the block size of the compression function.
Definition keccak.h:89
Keccak_Final()
Construct a Keccak-X message digest.
Definition keccak.h:81
Keccak message digest base class.
Definition keccak.h:41
unsigned int DigestSize() const
Definition keccak.h:54
Keccak(unsigned int digestSize)
Construct a Keccak.
Definition keccak.h:51
unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Definition keccak.h:55
Abstract base classes that provide a uniform interface to this 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.