hashfile.c(3)

NAME
hashfile.c - Hashing functions.

SYNOPSIS

#include <config.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <wget.h>
#include 'private.h'
#include <gnutls/gnutls.h>
#include <gnutls/crypto.h>

  Data Structures
struct wget_hash_hd_st
wget_digest_algorithm wget_hash_get_algorithm (const char *hashname)
int wget_hash_fast (wget_digest_algorithm algorithm, const void *text, size_t textlen, void *digest)
int wget_hash_get_len (wget_digest_algorithm algorithm)
int wget_hash_init (wget_hash_hd **handle, wget_digest_algorithm algorithm)
int wget_hash (wget_hash_hd *handle, const void *text, size_t textlen)
int wget_hash_deinit (wget_hash_hd **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

Hashing functions.

Function Documentation

  wget_digest_algorithm wget_hash_get_algorithm (const char * hashname)

Parameters
    hashname Name 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 enum.

Algorithm name Constant sha1 or sha-1 WGET_DIGTYPE_SHA1 sha256 or sha-256 WGET_DIGTYPE_SHA256 sha512 or sha-512 WGET_DIGTYPE_SHA512 sha224 or sha-224 WGET_DIGTYPE_SHA224 sha384 or sha-384 WGET_DIGTYPE_SHA384 md5 WGET_DIGTYPE_MD5 md2 WGET_DIGTYPE_MD2 rmd160 WGET_DIGTYPE_RMD160

  int wget_hash_fast (wget_digest_algorithm algorithm, const void * text, size_t textlen, void * digest)

Parameters
    algorithm One of the hashing algorithms returned by wget_hash_get_algorithm()
    text Input data to hash
    textlen Length of the input data
    digest Caller-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.

  int wget_hash_get_len (wget_digest_algorithm algorithm)

Parameters
    algorithm One 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.

  int wget_hash_init (wget_hash_hd ** handle, wget_digest_algorithm algorithm)

Parameters
    handle Caller-provided pointer to a wget_hash_hd structure where the handle to this hashing primitive will be stored, needed in subsequent calls to wget_hash()
    algorithm One 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.

  int wget_hash (wget_hash_hd * handle, const void * text, size_t textlen)

Parameters
    handle Handle to the hashing primitive returned by a subsequent call to wget_hash_init()
    text Input data
    textlen Length 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.

  int wget_hash_deinit (wget_hash_hd ** handle, void * digest)

Parameters
    handle Handle to the hashing primitive returned by a subsequent call to wget_hash_init()
    digest Caller-supplied buffer where the output hash will be placed.

Returns
    0 on success, < 0 on failure

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().

  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
    hashname Name of the hashing algorithm. See wget_hash_get_algorithm()
    fd File descriptor for the target file
    digest_hex caller-supplied buffer that will contain the resulting hex string
    digest_hex_size Length of digest_hex
    offset File offset to start hashing at
    length Number 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.

  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
    hashname Name of the hashing algorithm. See wget_hash_get_algorithm()
    fname Target file name
    digest_hex Caller-supplied buffer that will contain the resulting hex string
    digest_hex_size Length of digest_hex
    offset File offset to start hashing at
    length Number 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.

  int wget_hash_file (const char * hashname, const char * fname, char * digest_hex, size_t digest_hex_size)

Parameters
    hashname Name of the hashing algorithm. See wget_hash_get_algorithm()
    fname Target file name
    digest_hex Caller-supplied buffer that will contain the resulting hex string
    digest_hex_size Length 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.

Author

Generated automatically by Doxygen for wget2 from the source code.