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 <<nocrypto,Non-cryptographic ones>>:
18 - <<strhash,String & block hashes>>
19 - <<inthash,Integer hashes>>
39 There are two ways you can use the hashing routines.
41 - Single-shot interface. If you have an in-memory buffer of the whole
42 message you want to hash, you can use this.
44 char *message = "Hello world";
45 byte output[MD5_SIZE];
46 md5_hash_buffer(output, message, strlen(message));
48 - Multi-shot interface. If you have the message scattered in many
49 buffers or you get it by parts, you do not need to concatenate the
52 byte buffer[MAX_BUFFER];
56 while(buffer_len = get_chunk(buffer, MAX_BUFFER)) {
57 md5_update(&c, buffer, buffer_len);
59 byte output[MD5_SIZE];
60 memcpy(output, md5_final(&c), MD5_SIZE);
62 SHA1 has the same interface, so the same two ways apply.
64 See also <<string:mem_to_hex()>>.
67 Non-cryptographic hashes
68 ------------------------
70 All these functions expect to be moduled by the size of a hash table.
71 The size should be a prime number (it gives better distribution).