4 Libucw contains two cryptographic hash algorithms: MD5 (RFC 1321) and SHA1 (RFC
5 3174). A SHA1-HMAC (RFC 2104) message authentication is available.
7 There are non-cryptographic hashes as well.
9 <<crypto,Cryptographic ones>>:
13 - <<sha1:sha1_hmac(),SHA1_HMAC>>
14 - <<usage,Common usage>>
16 <<checksum,Checksums>>:
17 - <<crypto:adler,Adler-32>>
19 <<nocrypto,Non-cryptographic ones>>:
21 - <<strhash,String & block hashes>>
22 - <<inthash,Integer hashes>>
42 There are two ways you can use the hashing routines.
44 - Single-shot interface. If you have an in-memory buffer of the whole
45 message you want to hash, you can use this.
47 char *message = "Hello world";
48 byte output[MD5_SIZE];
49 md5_hash_buffer(output, message, strlen(message));
51 - Multi-shot interface. If you have the message scattered in many
52 buffers or you get it by parts, you do not need to concatenate the
55 byte buffer[MAX_BUFFER];
59 while(buffer_len = get_chunk(buffer, MAX_BUFFER)) {
60 md5_update(&c, buffer, buffer_len);
62 byte output[MD5_SIZE];
63 memcpy(output, md5_final(&c), MD5_SIZE);
65 SHA1 has the same interface, so the same two ways apply.
67 See also <<string:mem_to_hex()>>.
73 Their purpose is checking against random data changes, hardware
74 failures and alike. They are not to be used against aimed attacks.
76 The <<compress:adler,Adler-32 checksum>> is documented in the
77 <<compression,compression capter>>.
80 Non-cryptographic hashes
81 ------------------------
83 They are usually used to identify values in hash tables.
85 All these functions expect to be moduled by the size of a hash table.
86 The size should be a prime number (it gives better distribution).