Home
Crypto module

Hash

Incremental cryptographic hash engine wrapping OpenSSL EVP digest functions.

Hash

#include <icy/crypto/hash.h>
class Hash

Defined in src/crypto/include/icy/crypto/hash.h:38

Incremental cryptographic hash engine wrapping OpenSSL EVP digest functions.

Construct with an algorithm name recognized by OpenSSL (e.g. "sha256", "md5"). Feed data with one or more calls to update(), then call digest() or digestStr() to finalize and retrieve the result. Call reset() to reuse the engine for a new computation without reallocating the context.

List of all members

NameKindOwner
HashfunctionDeclared here
~HashfunctionDeclared here
updatefunctionDeclared here
updatefunctionDeclared here
updatefunctionDeclared here
digestfunctionDeclared here
digestStrfunctionDeclared here
resetfunctionDeclared here
algorithmfunctionDeclared here
_ctxvariableDeclared here
_mdvariableDeclared here
_digestvariableDeclared here
_algorithmvariableDeclared here
operator=functionDeclared here

Public Methods

ReturnNameDescription
HashConstructs a Hash engine for the given algorithm.
~HashDestroys the Hash engine and releases OpenSSL resources.
voidupdateFeeds a single character into the digest computation.
voidupdateFeeds a string view into the digest computation.
voidupdateFeeds a raw memory buffer into the digest computation.
const ByteVec &digestFinalizes the digest computation and returns the raw binary result.
std::stringdigestStrFinalizes the digest computation and returns the result as a raw binary string (not hex-encoded). Use icy::hex::encode() on digest() if you need a printable representation.
voidresetResets the digest context and clears the cached result, allowing the engine to be reused for a new computation with the same algorithm.
const std::string &algorithm constReturns the algorithm name this engine was constructed with.

Hash

Hash(const std::string & algorithm)

Defined in src/crypto/include/icy/crypto/hash.h:45

Constructs a Hash engine for the given algorithm.

Parameters

  • algorithm OpenSSL digest name (e.g. "sha256", "sha1", "md5").

Exceptions

  • std::runtime_error if the algorithm is not recognized by OpenSSL.

~Hash

~Hash()

Defined in src/crypto/include/icy/crypto/hash.h:48

Destroys the Hash engine and releases OpenSSL resources.


update

void update(char data)

Defined in src/crypto/include/icy/crypto/hash.h:53

Feeds a single character into the digest computation.

Parameters

  • data The byte to hash.

update

void update(std::string_view data)

Defined in src/crypto/include/icy/crypto/hash.h:58

Feeds a string view into the digest computation.

Parameters

  • data The data to hash.

update

void update(const void * data, size_t length)

Defined in src/crypto/include/icy/crypto/hash.h:66

Feeds a raw memory buffer into the digest computation.

This method may be called multiple times for streaming large inputs.

Parameters

  • data Pointer to the input buffer.

  • length Number of bytes to hash from data.


digest

const ByteVec & digest()

Defined in src/crypto/include/icy/crypto/hash.h:75

Finalizes the digest computation and returns the raw binary result.

The result is computed on the first call and cached; subsequent calls return the same value without recomputing. Call reset() before reusing the engine for a new computation.

Returns

Reference to the internal byte vector containing the digest.


digestStr

std::string digestStr()

Defined in src/crypto/include/icy/crypto/hash.h:82

Finalizes the digest computation and returns the result as a raw binary string (not hex-encoded). Use icy::hex::encode() on digest() if you need a printable representation.

Returns

Binary digest as a std::string.


reset

void reset()

Defined in src/crypto/include/icy/crypto/hash.h:86

Resets the digest context and clears the cached result, allowing the engine to be reused for a new computation with the same algorithm.


algorithm

const

const std::string & algorithm() const

Defined in src/crypto/include/icy/crypto/hash.h:91

Returns the algorithm name this engine was constructed with.

Returns

OpenSSL digest name string (e.g. "sha256").

Protected Attributes

ReturnNameDescription
EvpMdCtxPtr_ctx
const EVP_MD *_md
crypto::ByteVec_digest
std::string_algorithm

_ctx

EvpMdCtxPtr _ctx

Defined in src/crypto/include/icy/crypto/hash.h:96


_md

const EVP_MD * _md

Defined in src/crypto/include/icy/crypto/hash.h:97


_digest

crypto::ByteVec _digest

Defined in src/crypto/include/icy/crypto/hash.h:98


_algorithm

std::string _algorithm

Defined in src/crypto/include/icy/crypto/hash.h:99