ADLER32(3) BSD Programmer's Manual ADLER32(3)NAME
ADLER32Init, ADLER32Update, ADLER32Final, ADLER32End, ADLER32File,
ADLER32FileChunk, ADLER32Data - calculate the ADLER32 checksum
SYNOPSIS
#include <sys/types.h>
#include <adler32.h>
void
ADLER32Init(ADLER32_CTX *ctx);
void
ADLER32Update(ADLER32_CTX *ctx, const uint8_t *data, size_t noctets);
void
ADLER32Final(uint8_t digest[ADLER32_DIGEST_LENGTH], ADLER32_CTX *ctx);
char *
ADLER32End(ADLER32_CTX *ctx, char *digest);
char *
ADLER32File(const char *filename, char *digest);
char *
ADLER32FileChunk(const char *filename, char *digest, off_t offset,
off_t length);
char *
ADLER32Data(const uint8_t *data, size_t len, char *digest);
DESCRIPTION
The ADLER32 functions implement the 32-bit ADLER32 cyclic redundancy
checksum. They share a similar API to the md5(3) interface.
The ADLER32Init() function initialises a ADLER32_CTX context for use with
ADLER32Update() and ADLER32Final(). The ADLER32Update() function adds
(condenses) data of length noctets to the context. ADLER32Final() is
called after processing and stores a message digest in the digest parame-
ter.
For a description of the other functions, please refer e.g. the rmd160(3)
manual page.
EXAMPLES
The follow code fragment will calculate the checksum for the string
"abc", which is "024D0127".
ADLER32_CTX context;
uint8_t result[ADLER32_DIGEST_LENGTH];
const char buf[] = "abc";
size_t n = strlen(buf);
ADLER32Init(&context);
ADLER32Update(&context, buf, n);
ADLER32Final(result, &context);
/* print the digest as one long sedecimal value */
printf("0x");
for (n = 0; n < ADLER32_DIGEST_LENGTH; n++)
printf("%02X", result[n]);
putchar('\n');
Alternately, the helper functions could be used in the following way:
ADLER32_CTX context;
uint8_t output[ADLER32_DIGEST_STRING_LENGTH];
const char buf[] = "abc";
printf("0x%s\n", ADLER32Data(buf, strlen(buf), output));
SEE ALSOcksum(1), compress(3), md4(3), md5(3), rmd160(3), sfv(3), sha1(3),
sha2(3), suma(3), tiger(3), whirlpool(3)HISTORY
The ADLER32 functions appeared in MirOS #10.
AUTHORS
This implementation of ADLER32 was written by Thorsten Glaser
<tg@mirbsd.de> as a size-optimised version of the zlib Adler-32 checksum.
The ADLER32End(), ADLER32File(), ADLER32FileChunk(), and ADLER32Data()
helper functions are derived from code written by Poul-Henning Kamp.
MirOS BSD #10-current November 22, 2009 1