SFV(3) BSD Programmer's Manual SFV(3)
SFVInit, SFVUpdate, SFVPad, SFVFinal, SFVEnd, SFVFile, SFVFileChunk, SFVData - calculate the SFV checksum
#include <sys/types.h> #include <sfv.h> void SFVInit(SFV_CTX *ctx); void SFVUpdate(SFV_CTX *ctx, const uint8_t *data, size_t noctets); void SFVPad(SFV_CTX *ctx); void SFVFinal(uint8_t digest[SFV_DIGEST_LENGTH], SFV_CTX *ctx); char * SFVEnd(SFV_CTX *ctx, char *digest); char * SFVFile(const char *filename, char *digest); char * SFVFileChunk(const char *filename, char *digest, off_t offset, off_t length); char * SFVData(const uint8_t *data, size_t len, char *digest);
The SFV functions implement the 32-bit SFV cyclic redundancy checksum. It is often vulgarly known as CRC or CRC32. They share a similar API to the md5(3) interface. The SFVInit() function initialises a SFV_CTX context for use with SFVUp- date() and SFVFinal(). The SFVUpdate() function adds (condenses) data of length noctets to the context. SFVFinal() is called after processing and stores a message digest in the digest parameter. 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 "352441C2". SFV_CTX context; uint8_t result[SFV_DIGEST_LENGTH]; const char buf[] = "abc"; size_t n = strlen(buf); SFVInit(&context); SFVUpdate(&context, buf, n); SFVFinal(result, &context); /* print the digest as one long sedecimal value */ printf("0x"); for (n = 0; n < SFV_DIGEST_LENGTH; n++) printf("%02X", result[n]); putchar('\n'); Alternately, the helper functions could be used in the following way: SFV_CTX context; uint8_t output[SFV_DIGEST_STRING_LENGTH]; const char buf[] = "abc"; printf("0x%s\n", SFVData(buf, strlen(buf), output));
cksum(1), adler32(3), md4(3), md5(3), rmd160(3), sha1(3), sha2(3), suma(3), tiger(3), whirlpool(3) http://www.fodder.org/cksfv/
The SFV functions appeared in MirBSD #10.
This implementation of SFV was written by Thorsten Glaser <tg@mirbsd.de> and is compatible with Bryan Call's cksfv. The SFVEnd(), SFVFile(), SFVFileChunk(), and SFVData() helper functions are derived from code written by Poul-Henning Kamp. MirBSD #10-current September 4, 2020 1