Fabcoin Core
0.16.2
P2P Digital Currency
|
Interface for hash functions and data processing part of MACs. More...
#include <cryptlib.h>
Public Member Functions | |
virtual | ~HashTransformation () |
HashTransformation & | Ref () |
Provides a reference to this object. More... | |
virtual void | Update (const byte *input, size_t length)=0 |
Updates a hash with additional input. More... | |
virtual byte * | CreateUpdateSpace (size_t &size) |
Request space which can be written into by the caller. More... | |
virtual void | Final (byte *digest) |
Computes the hash of the current message. More... | |
virtual void | Restart () |
Restart the hash. More... | |
virtual unsigned int | DigestSize () const =0 |
Provides the digest size of the hash. More... | |
unsigned int | TagSize () const |
Provides the tag size of the hash. More... | |
virtual unsigned int | BlockSize () const |
Provides the block size of the compression function. More... | |
virtual unsigned int | OptimalBlockSize () const |
Provides the input block size most efficient for this hash. More... | |
virtual unsigned int | OptimalDataAlignment () const |
Provides input and output data alignment for optimal performance. More... | |
virtual void | CalculateDigest (byte *digest, const byte *input, size_t length) |
Updates the hash with additional input and computes the hash of the current message. More... | |
virtual bool | Verify (const byte *digest) |
Verifies the hash of the current message. More... | |
virtual bool | VerifyDigest (const byte *digest, const byte *input, size_t length) |
Updates the hash with additional input and verifies the hash of the current message. More... | |
virtual void | TruncatedFinal (byte *digest, size_t digestSize)=0 |
Computes the hash of the current message. More... | |
virtual void | CalculateTruncatedDigest (byte *digest, size_t digestSize, const byte *input, size_t length) |
Updates the hash with additional input and computes the hash of the current message. More... | |
virtual bool | TruncatedVerify (const byte *digest, size_t digestLength) |
Verifies the hash of the current message. More... | |
virtual bool | VerifyTruncatedDigest (const byte *digest, size_t digestLength, const byte *input, size_t length) |
Updates the hash with additional input and verifies the hash of the current message. More... | |
Public Member Functions inherited from Algorithm | |
virtual | ~Algorithm () |
Algorithm (bool checkSelfTestStatus=true) | |
Interface for all crypto algorithms. More... | |
virtual std::string | AlgorithmName () const |
Provides the name of this algorithm. More... | |
Public Member Functions inherited from Clonable | |
virtual | ~Clonable () |
virtual Clonable * | Clone () const |
Copies this object. More... | |
Protected Member Functions | |
void | ThrowIfInvalidTruncatedSize (size_t size) const |
Validates a truncated digest size. More... | |
Interface for hash functions and data processing part of MACs.
HashTransformation objects are stateful. They are created in an initial state, change state as Update() is called, and return to the initial state when Final() is called. This interface allows a large message to be hashed in pieces by calling Update() on each piece followed by calling Final().
Definition at line 930 of file cryptlib.h.
|
inlinevirtual |
Definition at line 933 of file cryptlib.h.
|
inlinevirtual |
Provides the block size of the compression function.
BlockSize() will return 0 if the hash is not block based. For example, SHA3 is a recursive hash (not an iterative hash), and it does not have a block size.
Reimplemented in IteratedHash< word64, LittleEndian, T_BlockSize >, IteratedHash< T_HashWordType, T_Endianness, T_BlockSize >, IteratedHash< word32, LittleEndian, T_BlockSize >, IteratedHash< word32, LittleEndian, 64, MessageAuthenticationCode >, IteratedHash< word32, BigEndian, T_BlockSize >, IteratedHash< word32, NativeByteOrder, 32 >, IteratedHash< word64, BigEndian, T_BlockSize >, HermeticHashFunctionMAC< T_Hash, T_Info >, HermeticHashFunctionMAC< PanamaHash< B > >, Keccak_Final< T_DigestSize >, Poly1305_Base< T >, SHA3_Final< T_DigestSize >, VMAC_Base, and Weak1::MD2.
Definition at line 981 of file cryptlib.h.
|
inlinevirtual |
Updates the hash with additional input and computes the hash of the current message.
digest | a pointer to the buffer to receive the hash |
input | the additional input as a buffer |
length | the size of the buffer, in bytes |
Use this if your input is in one piece and you don't want to call Update() and Final() separately
CalculateDigest() restarts the hash for the next message.
COUNTOF(digest) == DigestSize()
or COUNTOF(digest) == HASH::DIGESTSIZE
ensures the output byte buffer is large enough for the digest. Definition at line 1003 of file cryptlib.h.
|
inlinevirtual |
Updates the hash with additional input and computes the hash of the current message.
digest | a pointer to the buffer to receive the hash |
digestSize | the length of the truncated hash, in bytes |
input | the additional input as a buffer |
length | the size of the buffer, in bytes |
Use this if your input is in one piece and you don't want to call Update() and CalculateDigest() separately.
CalculateTruncatedDigest() restarts the hash for the next message.
COUNTOF(digest) == DigestSize()
or COUNTOF(digest) == HASH::DIGESTSIZE
ensures the output byte buffer is large enough for the digest. Definition at line 1051 of file cryptlib.h.
|
inlinevirtual |
Request space which can be written into by the caller.
size | the requested size of the buffer |
The purpose of this method is to help avoid extra memory allocations.
size is an IN and OUT parameter and used as a hint. When the call is made, size is the requested size of the buffer. When the call returns, size is the size of the array returned to the caller.
The base class implementation sets size to 0 and returns NULL.
Reimplemented in IteratedHashBase< word32, HashTransformation >, IteratedHashBase< T_HashWordType, HashTransformation >, IteratedHashBase< word32, MessageAuthenticationCode >, IteratedHashBase< word64, HashTransformation >, and IteratedHashBase< word64, MessageAuthenticationCode >.
Definition at line 953 of file cryptlib.h.
|
pure virtual |
Provides the digest size of the hash.
Implemented in PK_MessageAccumulator, BLAKE2_Base< W, T_64bit >, BLAKE2_Base< word32, false >, BLAKE2_Base< word64, true >, IteratedHashWithStaticTransform< T_HashWordType, T_Endianness, T_BlockSize, T_StateSize, T_Transform, T_DigestSize, T_StateAligned >, IteratedHashWithStaticTransform< word32, LittleEndian, 64, 32, RIPEMD256 >, IteratedHashWithStaticTransform< word64, BigEndian, 128, 64, SHA512, 64,(CRYPTOPP_BOOL_X86|CRYPTOPP_BOOL_X32)>, IteratedHashWithStaticTransform< word32, LittleEndian, 64, 16, MD5 >, IteratedHashWithStaticTransform< word32, LittleEndian, 64, 16, MD4 >, IteratedHashWithStaticTransform< word32, LittleEndian, 64, 40, RIPEMD320 >, IteratedHashWithStaticTransform< word32, BigEndian, 64, 20, SHA1 >, IteratedHashWithStaticTransform< word64, BigEndian, 128, 64, SHA384, 48,(CRYPTOPP_BOOL_X86|CRYPTOPP_BOOL_X32)>, IteratedHashWithStaticTransform< word32, LittleEndian, 64, 16, RIPEMD128 >, IteratedHashWithStaticTransform< word32, BigEndian, 64, 32, SHA224, 28, true >, IteratedHashWithStaticTransform< word32, BigEndian, 64, 32, SHA256, 32, true >, IteratedHashWithStaticTransform< word32, LittleEndian, 64, 20, RIPEMD160 >, IteratedHashWithStaticTransform< word64, LittleEndian, 64, 24, Tiger >, IteratedHashWithStaticTransform< word64, BigEndian, 64, 64, Whirlpool >, HermeticHashFunctionMAC< T_Hash, T_Info >, HermeticHashFunctionMAC< PanamaHash< B > >, Poly1305_Base< T >, SipHash_Base< C, D, T_128bit >, CRC32C, GCM_Base, Keccak, CCM_Base, EAX_Base, Weak::PanamaHash< B >, SHA3, TruncatedHashTemplate< T >, CRC32, VMAC_Base, DMAC_Base< T >, HMAC_Base, CMAC_Base, CBC_MAC_Base, TTMAC_Base, Adler32, Weak1::MD2, and NullHash.
|
inlinevirtual |
Computes the hash of the current message.
digest | a pointer to the buffer to receive the hash |
Final() restarts the hash for a new message.
COUNTOF(digest) == DigestSize()
or COUNTOF(digest) == HASH::DIGESTSIZE
ensures the output byte buffer is large enough for the digest. Definition at line 960 of file cryptlib.h.
|
inlinevirtual |
Provides the input block size most efficient for this hash.
The base class implementation returns MandatoryBlockSize().
Optimal input length is n * OptimalBlockSize() - GetOptimalBlockSizeUsed()
for any n > 0
.
Reimplemented in HermeticHashFunctionMAC< T_Hash, T_Info >, HermeticHashFunctionMAC< PanamaHash< B > >, SipHash_Base< C, D, T_128bit >, IteratedHashBase< word32, HashTransformation >, IteratedHashBase< T_HashWordType, HashTransformation >, IteratedHashBase< word32, MessageAuthenticationCode >, IteratedHashBase< word64, HashTransformation >, IteratedHashBase< word64, MessageAuthenticationCode >, CMAC_Base, and HMAC_Base.
Definition at line 988 of file cryptlib.h.
|
virtual |
Provides input and output data alignment for optimal performance.
Reimplemented in BLAKE2_Base< W, T_64bit >, BLAKE2_Base< word32, false >, BLAKE2_Base< word64, true >, HermeticHashFunctionMAC< T_Hash, T_Info >, HermeticHashFunctionMAC< PanamaHash< B > >, SipHash_Base< C, D, T_128bit >, Keccak, IteratedHashBase< word32, HashTransformation >, IteratedHashBase< T_HashWordType, HashTransformation >, IteratedHashBase< word32, MessageAuthenticationCode >, IteratedHashBase< word64, HashTransformation >, IteratedHashBase< word64, MessageAuthenticationCode >, GCM_Base, SHA3, CCM_Base, VMAC_Base, EAX_Base, and CMAC_Base.
Definition at line 239 of file cryptlib.cpp.
|
inline |
Provides a reference to this object.
Useful for passing a temporary object to a function that takes a non-const reference
Definition at line 938 of file cryptlib.h.
|
inlinevirtual |
Restart the hash.
Discards the current state, and restart for a new message
Reimplemented in BLAKE2_Base< W, T_64bit >, BLAKE2_Base< word32, false >, BLAKE2_Base< word64, true >, SipHash_Base< C, D, T_128bit >, Poly1305_Base< T >, HermeticHashFunctionMAC< T_Hash, T_Info >, HermeticHashFunctionMAC< PanamaHash< B > >, IteratedHashBase< word32, HashTransformation >, IteratedHashBase< T_HashWordType, HashTransformation >, IteratedHashBase< word32, MessageAuthenticationCode >, IteratedHashBase< word64, HashTransformation >, IteratedHashBase< word64, MessageAuthenticationCode >, Keccak, SHA3, AuthenticatedSymmetricCipherBase, TruncatedHashTemplate< T >, and HMAC_Base.
Definition at line 965 of file cryptlib.h.
|
inline |
Provides the tag size of the hash.
Same as DigestSize().
Definition at line 975 of file cryptlib.h.
|
protected |
Validates a truncated digest size.
size | the requested digest size |
InvalidArgument | if the algorithm's digest size cannot be truncated to the requested size |
Throws an exception when the truncated digest size is greater than DigestSize()
Definition at line 416 of file cryptlib.cpp.
|
pure virtual |
Computes the hash of the current message.
digest | a pointer to the buffer to receive the hash |
digestSize | the size of the truncated digest, in bytes |
TruncatedFinal() call Final() and then copies digestSize bytes to digest. The hash is restarted the hash for the next message.
Implemented in PK_MessageAccumulator, BLAKE2_Base< W, T_64bit >, BLAKE2_Base< word32, false >, BLAKE2_Base< word64, true >, HermeticHashFunctionMAC< T_Hash, T_Info >, HermeticHashFunctionMAC< PanamaHash< B > >, SipHash_Base< C, D, T_128bit >, Poly1305_Base< T >, IteratedHashBase< word32, HashTransformation >, IteratedHashBase< T_HashWordType, HashTransformation >, IteratedHashBase< word32, MessageAuthenticationCode >, IteratedHashBase< word64, HashTransformation >, IteratedHashBase< word64, MessageAuthenticationCode >, Keccak, CRC32C, Weak::PanamaHash< B >, SHA3, AuthenticatedSymmetricCipherBase, TruncatedHashTemplate< T >, VMAC_Base, CRC32, DMAC_Base< T >, HMAC_Base, CMAC_Base, TTMAC_Base, CBC_MAC_Base, Adler32, Tiger, Weak1::MD2, NullHash, and Whirlpool.
|
virtual |
Verifies the hash of the current message.
digest | a pointer to the buffer of an existing hash |
digestLength | the size of the truncated hash, in bytes |
true
if the existing hash matches the computed hash, false
otherwise ThrowIfInvalidTruncatedSize() | if digestLength exceeds DigestSize() |
TruncatedVerify() is a truncated version of Verify(). It can operate on a buffer smaller than DigestSize(). However, digestLength cannot exceed DigestSize().
Verify() performs a bitwise compare on the buffers using VerifyBufsEqual(), which is a constant time comparison function. digestLength cannot exceed DigestSize().
TruncatedVerify() restarts the hash for the next message.
Reimplemented in TruncatedHashTemplate< T >, and NullHash.
Definition at line 408 of file cryptlib.cpp.
|
pure virtual |
Updates a hash with additional input.
input | the additional input as a buffer |
length | the size of the buffer, in bytes |
Implemented in PK_MessageAccumulatorBase, BLAKE2_Base< W, T_64bit >, BLAKE2_Base< word32, false >, BLAKE2_Base< word64, true >, SipHash_Base< C, D, T_128bit >, Poly1305_Base< T >, HermeticHashFunctionMAC< T_Hash, T_Info >, HermeticHashFunctionMAC< PanamaHash< B > >, CRC32C, Keccak, IteratedHashBase< word32, HashTransformation >, IteratedHashBase< T_HashWordType, HashTransformation >, IteratedHashBase< word32, MessageAuthenticationCode >, IteratedHashBase< word64, HashTransformation >, IteratedHashBase< word64, MessageAuthenticationCode >, SHA3, AuthenticatedSymmetricCipherBase, TruncatedHashTemplate< T >, CRC32, DMAC_Base< T >, HMAC_Base, CMAC_Base, CBC_MAC_Base, Adler32, Weak1::MD2, and NullHash.
|
inlinevirtual |
Verifies the hash of the current message.
digest | a pointer to the buffer of an existing hash |
true
if the existing hash matches the computed hash, false
otherwise ThrowIfInvalidTruncatedSize() | if the existing hash's size exceeds DigestSize() |
Verify() performs a bitwise compare on the buffers using VerifyBufsEqual(), which is a constant time comparison function. digestLength cannot exceed DigestSize().
Verify() restarts the hash for the next message.
COUNTOF(digest) == DigestSize()
or COUNTOF(digest) == HASH::DIGESTSIZE
ensures the output byte buffer is large enough for the digest. Definition at line 1015 of file cryptlib.h.
|
inlinevirtual |
Updates the hash with additional input and verifies the hash of the current message.
digest | a pointer to the buffer of an existing hash |
input | the additional input as a buffer |
length | the size of the buffer, in bytes |
true
if the existing hash matches the computed hash, false
otherwise ThrowIfInvalidTruncatedSize() | if the existing hash's size exceeds DigestSize() |
Use this if your input is in one piece and you don't want to call Update() and Verify() separately
VerifyDigest() performs a bitwise compare on the buffers using VerifyBufsEqual(), which is a constant time comparison function. digestLength cannot exceed DigestSize().
VerifyDigest() restarts the hash for the next message.
COUNTOF(digest) == DigestSize()
or COUNTOF(digest) == HASH::DIGESTSIZE
ensures the output byte buffer is large enough for the digest. Definition at line 1031 of file cryptlib.h.
|
inlinevirtual |
Updates the hash with additional input and verifies the hash of the current message.
digest | a pointer to the buffer of an existing hash |
digestLength | the size of the truncated hash, in bytes |
input | the additional input as a buffer |
length | the size of the buffer, in bytes |
true
if the existing hash matches the computed hash, false
otherwise ThrowIfInvalidTruncatedSize() | if digestLength exceeds DigestSize() |
Use this if your input is in one piece and you don't want to call Update() and TruncatedVerify() separately.
VerifyTruncatedDigest() is a truncated version of VerifyDigest(). It can operate on a buffer smaller than DigestSize(). However, digestLength cannot exceed DigestSize().
VerifyTruncatedDigest() restarts the hash for the next message.
COUNTOF(digest) == DigestSize()
or COUNTOF(digest) == HASH::DIGESTSIZE
ensures the output byte buffer is large enough for the digest. Definition at line 1080 of file cryptlib.h.