Skip to content

Latest commit

 

History

History
140 lines (93 loc) · 3.3 KB

blkhash.3.adoc

File metadata and controls

140 lines (93 loc) · 3.3 KB

blkhash(3) Manual Page

NAME

blkhash_new, blkhash_update, blkhash_zero, blkhash_final, blkhash_free - block based hash optimized for disk images.

SYNOPSIS

#include <blkhash.h>

struct blkhash *blkhash_new();

struct blkhash *blkhash_new_opts(const struct blkhash_opts *opts);

int blkhash_update(struct blkhash *h, const void *buf, size_t len);

int blkhash_zero(struct blkhash *h, size_t len);

int blkhash_final(struct blkhash *h, unsigned char *md_value,
                  unsigned int *md_len);

void blkhash_free(struct blkhash *h);

DESCRIPTION

blkhash is block based hash optimized for hashing sparse files and disk images.

blkhash_new()

Allocate and initialize a block hash for creating one message digest using the default options. To create a hash with non-default options see blkhash_new_opts().

Return NULL and set errno on error.

blkhash_new_opts()

Allocate and initialize a block hash using the specified options. Note that using non-default options can change the hash value and reduce interoperability.

Return NULL and set errno on error.

blkhash_update()

Hash len bytes of data at buf into the hash h. This function can be called several times on the same hash to hash additional data. For best performance, len should be aligned to the block size specified in blkhash_new().

This function detects zero blocks in buf to optimize hashing, so you don’t need to do this yourself. However if you know that a byte range contains only zeros, call blkhash_zero() instead, which is much faster.

Return 0 on success and errno value on error. All future calls will fail after the first error.

blkhash_zero()

Hash len bytes of zeros efficiently into the hash h. This function can be called several times on the same hash to hash additional zeros. For best performance, len should be aligned to the block size specified in blkhash_new().

Should be used when you know that a range of bytes is read as zeros. Example use cases are a hole in a sparse file, or area in qcow2 image that is a hole or reads as zeros. If you don’t know the contents of the data, use blkhash_update().

Return 0 on success and errno value on error. All future calls will fail after the first error.

blkhash_final()

Finalize a hash and store the message digest in md_value. At most BLKHASH_MAX_MD_SIZE bytes will be written.

If md_len is not NULL, store the length of the digest in md_len.

Return 0 on success and errno value on error. The contents of md_value and md_len are undefined on error.

blkhash_free()

Free resources allocated in blkhash_new().

EXAMPLE

The program below demonstrates how to compute a message digest from data or from a run of zeros.

To compile use:

cc example.c -o example -lblkhash

Program source:

link:example.c[role=include]

AUTHORS

Nir Soffer <nirsof@gmail.com>

Copyright Red Hat Inc.

LICENSE

LGPL-2.1-or-later.

SEE ALSO

blkhash-aio(3), blkhash-opts(3)