wget2  1.0.0
Hashing functions

Functions

wget_digest_algorithm_t wget_hash_get_algorithm (const char *hashname)
 
int wget_hash_fast (wget_digest_algorithm_t algorithm, const void *text, size_t textlen, void *digest)
 
int wget_hash_get_len (wget_digest_algorithm_t algorithm)
 
int wget_hash_init (wget_hash_hd_t *handle, wget_digest_algorithm_t algorithm)
 
int wget_hash (wget_hash_hd_t *handle, const void *text, size_t textlen)
 
void wget_hash_deinit (wget_hash_hd_t *handle, void *digest)
 
int wget_hash_file_fd (const char *hashname, int fd, char *digest_hex, size_t digest_hex_size, off_t offset, off_t length)
 
int wget_hash_file_offset (const char *hashname, const char *fname, char *digest_hex, size_t digest_hex_size, off_t offset, off_t length)
 
int wget_hash_file (const char *hashname, const char *fname, char *digest_hex, size_t digest_hex_size)
 

Detailed Description

Function Documentation

◆ wget_hash_get_algorithm()

wget_digest_algorithm_t wget_hash_get_algorithm ( const char *  hashname)
Parameters
[in]hashnameName of the hashing algorithm (see table below)
Returns
A constant to be used by libwget hashing functions

Get the hashing algorithms list item that corresponds to the named hashing algorithm.

This function returns a constant that uniquely identifies a known supported hashing algorithm within libwget. All the supported algorithms are listed in the ::wget_digest_algorithm_t enum.

Algorithm name Constant
sha1 or sha-1WGET_DIGTYPE_SHA1
sha256 or sha-256WGET_DIGTYPE_SHA256
sha512 or sha-512WGET_DIGTYPE_SHA512
sha224 or sha-224WGET_DIGTYPE_SHA224
sha384 or sha-384WGET_DIGTYPE_SHA384
md5WGET_DIGTYPE_MD5
md2WGET_DIGTYPE_MD2
rmd160WGET_DIGTYPE_RMD160

◆ wget_hash_fast()

int wget_hash_fast ( wget_digest_algorithm_t  algorithm,
const void *  text,
size_t  textlen,
void *  digest 
)
Parameters
[in]algorithmOne of the hashing algorithms returned by wget_hash_get_algorithm()
[in]textInput data to hash
[in]textlenLength of the input data
[in]digestCaller-supplied buffer where the output hash will be placed
Returns
Zero on success or a negative value on error

Convenience function to hash the given data in a single call.

The caller must ensure that the provided output buffer digest is large enough to store the hash. A particular hash algorithm is guaranteed to always generate the same amount of data (e.g. 512 bits) but different hash algorithms will output different lengths of data. To get the output length of the chosen algorithm algorithm, call wget_hash_get_len().

Note
This function's behavior depends on the underlying cryptographic engine libwget was compiled with.

◆ wget_hash_get_len()

int wget_hash_get_len ( wget_digest_algorithm_t  algorithm)
Parameters
[in]algorithmOne of the hashing algorithms returned by wget_hash_get_algorithm()
Returns
The length of the output data generated by the algorithm

Determines the output length of the given hashing algorithm.

A particular hash algorithm is guaranteed to always generate the same amount of data (e.g. 512 bits) but different hash algorithms will output different lengths of data.

◆ wget_hash_init()

int wget_hash_init ( wget_hash_hd_t *  handle,
wget_digest_algorithm_t  algorithm 
)
Parameters
[out]handleCaller-provided pointer to a ::wget_hash_hd_t structure where the handle to this hashing primitive will be stored, needed in subsequent calls to wget_hash()
[in]algorithmOne of the hashing algorithms returned by wget_hash_get_algorithm()
Returns
Zero on success or a negative value on error

Initialize the cryptographic engine to compute hashes with the given hashing algorithm, as well as the hashing algorithm itself.

After this function returns, wget_hash() might be called as many times as desired.

◆ wget_hash()

int wget_hash ( wget_hash_hd_t *  handle,
const void *  text,
size_t  textlen 
)
Parameters
[in]handleHandle to the hashing primitive returned by a subsequent call to wget_hash_init()
[in]textInput data
[in]textlenLength of the input data
Returns
Zero on success or a negative value on error

Update the digest by adding additional input data to it. This method can be called as many times as desired. Once finished, call wget_hash_deinit() to complete the computation and get the resulting hash.

◆ wget_hash_deinit()

void wget_hash_deinit ( wget_hash_hd_t *  handle,
void *  digest 
)
Parameters
[in]handleHandle to the hashing primitive returned by a subsequent call to wget_hash_init()
[out]digestCaller-supplied buffer where the output hash will be placed.

Complete the hash computation by performing final operations, such as padding, and obtain the final result. The result will be placed in the caller-supplied buffer digest. The caller must ensure that the provided output buffer digest is large enough to store the hash. To get the output length of the chosen algorithm algorithm, call wget_hash_get_len().

◆ wget_hash_file_fd()

int wget_hash_file_fd ( const char *  hashname,
int  fd,
char *  digest_hex,
size_t  digest_hex_size,
off_t  offset,
off_t  length 
)
Parameters
[in]hashnameName of the hashing algorithm. See wget_hash_get_algorithm()
[in]fdFile descriptor for the target file
[out]digest_hexcaller-supplied buffer that will contain the resulting hex string
[in]digest_hex_sizeLength of digest_hex
[in]offsetFile offset to start hashing at
[in]lengthNumber of bytes to hash, starting from offset. Zero will hash up to the end of the file
Returns
0 on success or -1 in case of failure

Compute the hash of the contents of the target file and return its hex representation.

This function will encode the resulting hash in a string of hex digits, and place that string in the user-supplied buffer digest_hex.

◆ wget_hash_file_offset()

int wget_hash_file_offset ( const char *  hashname,
const char *  fname,
char *  digest_hex,
size_t  digest_hex_size,
off_t  offset,
off_t  length 
)
Parameters
[in]hashnameName of the hashing algorithm. See wget_hash_get_algorithm()
[in]fnameTarget file name
[out]digest_hexCaller-supplied buffer that will contain the resulting hex string
[in]digest_hex_sizeLength of digest_hex
[in]offsetFile offset to start hashing at
[in]lengthNumber of bytes to hash, starting from offset. Zero will hash up to the end of the file
Returns
0 on success or -1 in case of failure

Compute the hash of the contents of the target file starting from offset and up to length bytes and return its hex representation.

This function will encode the resulting hash in a string of hex digits, and place that string in the user-supplied buffer digest_hex.

◆ wget_hash_file()

int wget_hash_file ( const char *  hashname,
const char *  fname,
char *  digest_hex,
size_t  digest_hex_size 
)
Parameters
[in]hashnameName of the hashing algorithm. See wget_hash_get_algorithm()
[in]fnameTarget file name
[out]digest_hexCaller-supplied buffer that will contain the resulting hex string
[in]digest_hex_sizeLength of digest_hex
Returns
0 on success or -1 in case of failure

Compute the hash of the contents of the target file and return its hex representation.

This function will encode the resulting hash in a string of hex digits, and place that string in the user-supplied buffer digest_hex.