|
template<typename H = HashProvider, typename std::enable_if< std::is_default_constructible< H >::value >::type * = nullptr> |
| hasher () |
| Default constructor. More...
|
|
template<typename H = HashProvider, typename std::enable_if<!detail::is_xof< H >::value >::type * = nullptr> |
| hasher (size_t hashsize) |
| Constructor with hash size parameter. More...
|
|
template<typename T , typename std::enable_if< detail::is_byte< T >::value >::type * = nullptr> |
hasher & | absorb (const T *data, size_t len) |
| Absorbs bytes from a C-style pointer to character buffer. More...
|
|
template<typename T , typename std::enable_if< detail::is_byte< T >::value &&!std::is_same< T, std::string::value_type >::value >::type * = nullptr> |
hasher & | absorb (const std::basic_string< T > &str) |
| Absorbs bytes from std::basic_string. More...
|
|
hasher & | absorb (const std::string &str) |
| Absorbs bytes from std::string. More...
|
|
template<typename T , typename std::enable_if< detail::is_byte< T >::value >::type * = nullptr> |
hasher & | absorb (std::basic_istream< T > &istr) |
| Absorbs bytes from std::istream. More...
|
|
template<typename IT > |
hasher & | absorb (IT begin, IT end) |
| Absorbs bytes from an iterator sequence. More...
|
|
template<typename T , typename H = HashProvider, typename std::enable_if< detail::is_byte< T >::value &&detail::is_xof< H >::value >::type * = nullptr> |
void | squeeze (T *buf, size_t len) |
| Squeeze bytes into user-provided preallocated buffer. More...
|
|
template<typename OI , typename H = HashProvider, typename std::enable_if< detail::is_xof< H >::value >::type * = nullptr> |
void | squeeze (size_t len, OI it) |
| Squeeze bytes into an output iterator. More...
|
|
template<typename H = HashProvider, typename std::enable_if< detail::is_xof< H >::value >::type * = nullptr> |
std::string | hexsqueeze (size_t len) |
| Squeeze bytes and return them as a hex string. More...
|
|
template<typename T , typename H = HashProvider, typename std::enable_if< detail::is_byte< T >::value &&!detail::is_xof< H >::value >::type * = nullptr> |
void | digest (T *buf, size_t len) const |
| Output binary digest into user-provided preallocated buffer. More...
|
|
template<typename OI , typename H = HashProvider, typename std::enable_if<!detail::is_xof< H >::value >::type * = nullptr> |
void | digest (OI it) const |
| Write binary digest into an output iterator. More...
|
|
template<typename H = HashProvider, typename std::enable_if<!detail::is_xof< H >::value >::type * = nullptr> |
std::string | hexdigest () const |
| Return hex digest of absorbed data. More...
|
|
void | reset (bool resetParameters=false) |
| Reset the hasher state to start new digest computation. More...
|
|
template<class HashProvider, template< class > class Mixin = mixin::null_mixin>
class digestpp::hasher< HashProvider, Mixin >
Main class template implementing the public API for hashing.
Individual hash functions are defined by typedefs. See digestpp namespace description for description of supported hash functions with usage examples.
- Parameters
-
HashProvider | A class implementing the algorithm via traditional init/update/final interface. |
Mixin | A class template which can be used to inject additional functions to the public API of the hasher. |
- See also
- digestpp
template<class HashProvider , template< class > class Mixin = mixin::null_mixin>
template<typename H = HashProvider, typename std::enable_if<!detail::is_xof< H >::value >::type * = nullptr>
Constructor with hash size parameter.
Supported output sizes for each algorithm are listed in the description of corresponding typedef.
- Available if
- HashProvider supports multiple output sizes, AND
- HashProvider is not an extendable output function (XOF)
- Parameters
-
[in] | hashsize | Desired output digest size (in bits). |
- Exceptions
-
std::runtime_error | if the requested output size is not supported by the algorithm. |
template<class HashProvider , template< class > class Mixin = mixin::null_mixin>
template<typename T , typename std::enable_if< detail::is_byte< T >::value &&!std::is_same< T, std::string::value_type >::value >::type * = nullptr>
Absorbs bytes from std::basic_string.
- Parameters
-
- Returns
- Reference to *this
template<class HashProvider , template< class > class Mixin = mixin::null_mixin>
template<typename T , typename H = HashProvider, typename std::enable_if< detail::is_byte< T >::value &&!detail::is_xof< H >::value >::type * = nullptr>
void digestpp::hasher< HashProvider, Mixin >::digest |
( |
T * |
buf, |
|
|
size_t |
len |
|
) |
| const |
|
inline |
Output binary digest into user-provided preallocated buffer.
This function does not change the state of the hasher and can be called multiple times, producing the same result. To reset the state and start new digest calculation, use reset function.
- Available if
- HashProvider is a hash function (not XOF)
- Parameters
-
[out] | buf | Buffer to squeeze data to; must be of byte type (char, unsigned char or signed char) |
[in] | len | Size of the buffer |
- Exceptions
-
std::runtime_error | if the buffer size is not enough to fit the calculated digest (fixed by the algorithm or specified in the hasher constructor). |
- Example:
unsigned char buf[32];
digestpp::sha3(256).absorb(
"The quick brown fox jumps over the lazy dog").digest(buf,
sizeof(buf));
template<class HashProvider , template< class > class Mixin = mixin::null_mixin>
template<typename OI , typename H = HashProvider, typename std::enable_if<!detail::is_xof< H >::value >::type * = nullptr>
Write binary digest into an output iterator.
This function does not change the state of the hasher and can be called multiple times, producing the same result. To reset the state and start new digest calculation, use reset function.
- Available if
- HashProvider is a hash function (not XOF)
- Parameters
-
[out] | it | Output iterator to a byte container. |
- Example:
vector<unsigned char> v;
digestpp::sha3(256).absorb(
"The quick brown fox jumps over the lazy dog").digest(back_inserter(v));
template<class HashProvider , template< class > class Mixin = mixin::null_mixin>
template<typename H = HashProvider, typename std::enable_if<!detail::is_xof< H >::value >::type * = nullptr>
Return hex digest of absorbed data.
This function does not change the state of the hasher and can be called multiple times, producing the same result. To reset the state and start new digest calculation, use reset function.
- Available if
- HashProvider is a hash function (not XOF)
- Returns
- Calculated digest as a hexademical string
- Example:
std::cout <<
digestpp::blake2b().absorb(
"The quick brown fox jumps over the lazy dog").hexdigest() << std::endl;
template<class HashProvider , template< class > class Mixin = mixin::null_mixin>
template<typename H = HashProvider, typename std::enable_if< detail::is_xof< H >::value >::type * = nullptr>
Squeeze bytes and return them as a hex string.
After each invocation of this function the internal state of the hasher changes so that the next call will generate different (additional) output bytes. To reset the state and start new digest calculation, use reset function.
- Available if
- HashProvider is an extendable output function (XOF)
- Parameters
-
[in] | len | Size of data to squeeze (in bytes) |
- Returns
- Calculated digest as a hexademical string
- Example:
xof.set_customization("My Customization");
std::cout << xof.
absorb(
"The quick brown fox jumps over the lazy dog").
hexsqueeze(64) << std::endl;
template<class HashProvider , template< class > class Mixin = mixin::null_mixin>
template<typename T , typename H = HashProvider, typename std::enable_if< detail::is_byte< T >::value &&detail::is_xof< H >::value >::type * = nullptr>
Squeeze bytes into user-provided preallocated buffer.
After each invocation of this function the internal state of the hasher changes so that the next call will generate different (additional) output bytes. To reset the state and start new digest calculation, use reset function.
- Available if
- HashProvider is an extendable output function (XOF)
- Parameters
-
[out] | buf | Buffer to squeeze data to; must be of byte type (char, unsigned char or signed char) |
[in] | len | Size of data to squeeze (in bytes) |
template<class HashProvider , template< class > class Mixin = mixin::null_mixin>
template<typename OI , typename H = HashProvider, typename std::enable_if< detail::is_xof< H >::value >::type * = nullptr>
Squeeze bytes into an output iterator.
After each invocation of this function the internal state of the hasher changes so that the next call will generate different (additional) output bytes. To reset the state and start new digest calculation, use reset function.
- Available if
- HashProvider is an extendable output function (XOF)
- Parameters
-
[in] | len | Size of data to squeeze (in bytes) |
[out] | it | output iterator to a byte container |
- Example:
std::vector<unsigned char> v;
xof.
absorb(
"The quick brown fox jumps over the lazy dog");
xof.
squeeze(1000, back_inserter(v));
xof.
squeeze(1000, back_inserter(v));
xof.
squeeze(1000, back_inserter(v));
std::cout << "Squeezed " << v.size() << " bytes." << std::endl;