wget2  2.0.0
hashfile.c File Reference

(2021-09-05 15:34:56 -0600, (build 0f85ef3))

Hashing functions. More...

#include <config.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <wget.h>
#include "private.h"
#include "md2.h"
#include "md5.h"
#include "sha1.h"
#include "sha256.h"
#include "sha512.h"
Include dependency graph for hashfile.c:

Data Structures

struct  wget_hash_hd_st
 

Functions

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

wget_digest_algorithm 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 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

◆ 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.