ADLER32(3) BSD Programmer's Manual ADLER32(3)
ADLER32Init, ADLER32Update, ADLER32Final, ADLER32End, ADLER32File, ADLER32FileChunk, ADLER32Data - calculate the ADLER32 checksum
#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);
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.
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));
cksum(1), compress(3), md4(3), md5(3), rmd160(3), sfv(3), sha1(3), sha2(3), suma(3), tiger(3), whirlpool(3)
The ADLER32 functions appeared in MirBSD #10.
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. MirBSD #10-current September 4, 2020 1