2 * SHA-1 Hash Function (FIPS 180-1, RFC 3174)
4 * (c) 2008--2009 Martin Mares <mj@ucw.cz>
6 * Based on the code from libgcrypt-1.2.3, which was:
8 * Copyright (C) 1998, 2001, 2002, 2003 Free Software Foundation, Inc.
10 * This software may be freely distributed and used according to the terms
11 * of the GNU Lesser General Public License.
17 #ifdef CONFIG_UCW_CLEAN_ABI
18 #define sha1_final ucw_sha1_final
19 #define sha1_hash_buffer ucw_sha1_hash_buffer
20 #define sha1_hmac ucw_sha1_hmac
21 #define sha1_hmac_final ucw_sha1_hmac_final
22 #define sha1_hmac_init ucw_sha1_hmac_init
23 #define sha1_hmac_update ucw_sha1_hmac_update
24 #define sha1_init ucw_sha1_init
25 #define sha1_update ucw_sha1_update
29 * Internal SHA1 state.
30 * You should use it just as an opaque handle only.
39 void sha1_init(sha1_context *hd); /** Initialize new algorithm run in the @hd context. **/
41 * Push another @inlen bytes of data pointed to by @inbuf onto the
42 * SHA1 hash currently in @hd. You can call this any times you want on
43 * the same hash (and you do not need to reinitialize it by
44 * @sha1_init()). It has the same effect as concatenating all the data
45 * together and passing them at once.
47 void sha1_update(sha1_context *hd, const byte *inbuf, uns inlen);
49 * No more @sha1_update() calls will be done. This terminates the hash
50 * and returns a pointer to it.
52 * Note that the pointer points into data in the @hd context. If it ceases
53 * to exist, the pointer becomes invalid.
55 * To convert the hash to its usual hexadecimal representation, see
56 * <<string:mem_to_hex()>>.
58 byte *sha1_final(sha1_context *hd);
61 * A convenience one-shot function for SHA1 hash.
62 * It is equivalent to this snippet of code:
66 * sha1_update(&hd, buffer, length);
67 * memcpy(outbuf, sha1_final(&hd), SHA1_SIZE);
69 void sha1_hash_buffer(byte *outbuf, const byte *buffer, uns length);
72 * SHA1 HMAC message authentication. If you provide @key and @data,
73 * the result will be stored in @outbuf.
75 void sha1_hmac(byte *outbuf, const byte *key, uns keylen, const byte *data, uns datalen);
78 * The HMAC also exists in a stream version in a way analogous to the
79 * plain SHA1. Pass this as a context.
86 void sha1_hmac_init(sha1_hmac_context *hd, const byte *key, uns keylen); /** Initialize HMAC with context @hd and the given key. See sha1_init(). */
87 void sha1_hmac_update(sha1_hmac_context *hd, const byte *data, uns datalen); /** Hash another @datalen bytes of data. See sha1_update(). */
88 byte *sha1_hmac_final(sha1_hmac_context *hd); /** Terminate the HMAC and return a pointer to the allocated hash. See sha1_final(). */
90 #define SHA1_SIZE 20 /** Size of the SHA1 hash in its binary representation **/
91 #define SHA1_HEX_SIZE 41 /** Buffer length for a string containing SHA1 in hexadecimal format. **/
92 #define SHA1_BLOCK_SIZE 64 /** SHA1 splits input to blocks of this size. **/