From: Martin Mares Date: Sun, 18 Mar 2012 22:05:21 +0000 (+0100) Subject: CRC: Documentation X-Git-Tag: v5.99~185 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=078dd50e9e9d322db3f5ac8d0c434ebeeac10a79;p=libucw.git CRC: Documentation --- diff --git a/ucw/crc.h b/ucw/crc.h index 0e3d0137..28d59acf 100644 --- a/ucw/crc.h +++ b/ucw/crc.h @@ -16,7 +16,7 @@ * Adapted for LibUCW by Martin Mares in 2012. */ -/* +/** * Internal CRC calculator context. * You should use it just as an opaque handle only. */ @@ -25,23 +25,32 @@ typedef struct crc32_context { void (*update_func)(struct crc32_context *ctx, const byte *buf, uns len); } crc32_context; +/** + * Initialize new calculation of CRC in a given context. + * @crc_mode selects which algorithm should be used. + **/ void crc32_init(crc32_context *ctx, uns crc_mode); +/** + * Algorithm used for CRC calculation. The algorithms differ by the amount + * of precomputed tables they use. Bigger tables imply faster calculation + * at the cost of an increased cache footprint. + **/ enum crc_mode { - CRC_MODE_DEFAULT, - CRC_MODE_SMALL, - CRC_MODE_BIG, + CRC_MODE_DEFAULT, /* Default algorithm (4K table) */ + CRC_MODE_SMALL, /* Optimize for small data (1K table) */ + CRC_MODE_BIG, /* Optimize for large data (8K table) */ CRC_MODE_MAX, }; -static inline void -crc32_update(crc32_context *ctx, const byte *buf, uns len) +/** Feed @len bytes starting at @buf to the CRC calculator. **/ +static inline void crc32_update(crc32_context *ctx, const byte *buf, uns len) { ctx->update_func(ctx, buf, len); } -static inline u32 -crc32_final(crc32_context *ctx) +/** Finish calculation and return the CRC value. **/ +static inline u32 crc32_final(crc32_context *ctx) { return ctx->state ^ 0xffffffff; } diff --git a/ucw/doc/hash.txt b/ucw/doc/hash.txt index 3e01b941..788a382c 100644 --- a/ucw/doc/hash.txt +++ b/ucw/doc/hash.txt @@ -1,22 +1,21 @@ Hashing routines ================ -Libucw contains two cryptographic hash algorithms: MD5 (RFC 1321) and SHA1 (RFC -3174). A SHA1-HMAC (RFC 2104) message authentication is available. +LibUCW contains implementations of several hash algorithms. -There are non-cryptographic hashes as well. +<>: -<>: - -- <> -- <> -- <> +- <> (RFC 1321) +- <> (RFC 3174) +- <> (RFC 2104) - <> <>: + - <> +- <> -<>: +<>: - <> - <> @@ -73,8 +72,23 @@ Checksums Their purpose is checking against random data changes, hardware failures and alike. They are not to be used against aimed attacks. +Adler-32 +~~~~~~~~ + The <> is documented in the -<>. +<>. + +CRC-32 +~~~~~~ + +32-bit Cyclic Redundancy Check with the polynomial suggested by +Castagnoli et al.: Optimization of Cyclic Redundancy-Check Codes +with 24 and 32 Parity Bits", IEEE Trans. on Communications, Vol. 41, +No. 6, 1993. + +The interface is similar to the one we use for the cryptographic hashes. + +!!ucw/crc.h [[nocrypto]] Non-cryptographic hashes