Hashing routines ================ LibUCW contains implementations of several hash algorithms. <>: - <> (RFC 1321) - <> (RFC 3174) - <> (RFC 2104) - <> <>: - <> - <> <>: - <> - <> [[crypto]] Cryptographic hashes -------------------- [[md5]] MD5 ~~~ !!ucw/md5.h [[sha1]] SHA1 ~~~~ !!ucw/sha1.h [[usage]] Common usage ~~~~~~~~~~~~ There are two ways you can use the hashing routines. - Single-shot interface. If you have an in-memory buffer of the whole message you want to hash, you can use this. char *message = "Hello world"; byte output[MD5_SIZE]; md5_hash_buffer(output, message, strlen(message)); - Multi-shot interface. If you have the message scattered in many buffers or you get it by parts, you do not need to concatenate the parts together. byte buffer[MAX_BUFFER]; uint buffer_len; md5_context c; md5_init(&c); while(buffer_len = get_chunk(buffer, MAX_BUFFER)) { md5_update(&c, buffer, buffer_len); } byte output[MD5_SIZE]; memcpy(output, md5_final(&c), MD5_SIZE); SHA1 has the same interface, so the same two ways apply. See also <>. [[checksum]] 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 ------------------------ They are usually used to identify values in hash tables. All these functions expect to be moduled by the size of a hash table. The size should be a prime number (it gives better distribution). !!ucw/hashfunc.h