]> mj.ucw.cz Git - libucw.git/blob - ucw/md5.h
Mapping of whole files: Converted to size_t.
[libucw.git] / ucw / md5.h
1 /*
2  *      UCW Library -- MD5 Message Digest
3  *
4  *      This file is in public domain (see ucw/md5.c).
5  */
6
7 #ifndef _UCW_MD5_H
8 #define _UCW_MD5_H
9
10 #ifdef CONFIG_UCW_CLEAN_ABI
11 #define md5_final ucw_md5_final
12 #define md5_hash_buffer ucw_md5_hash_buffer
13 #define md5_init ucw_md5_init
14 #define md5_transform ucw_md5_transform
15 #define md5_update ucw_md5_update
16 #endif
17
18 /**
19  * Internal MD5 hash state.
20  * You should use it just as an opaque handle only.
21  */
22 typedef struct {
23         u32 buf[4];
24         u32 bits[2];
25         byte in[64];
26 } md5_context;
27
28 void md5_init(md5_context *context); /** Initialize the MD5 hashing algorithm in @context. **/
29 /**
30  * Push another @len bytes of data from @buf to the MD5 hash
31  * represented by @context. You can call it multiple time on the same
32  * @context without reinitializing it and the result will be the same
33  * as if you concatenated all the data together and fed them here all at
34  * once.
35  */
36 void md5_update(md5_context *context, const byte *buf, uns len);
37 /**
38  * Call this after the last @md5_update(). It will terminate the
39  * algorithm and return a pointer to the result.
40  *
41  * Note that the data it points to are stored inside the @context, so
42  * if you use it to compute another hash or it ceases to exist, the
43  * pointer becomes invalid.
44  *
45  * To convert the hash to its usual hexadecimal representation, see
46  * <<string:mem_to_hex()>>.
47  */
48 byte *md5_final(md5_context *context);
49
50 /**
51  * This is the core routine of the MD5 algorithm. It takes 16 longwords of
52  * data in @in and transforms the hash in @buf according to them.
53  *
54  * You probably do not want to call this one directly.
55  */
56 void md5_transform(u32 buf[4], const u32 in[16]);
57
58 /**
59  * MD5 one-shot convenience method. It takes @length bytes from
60  * @buffer, creates the hash from them and returns it in @output.
61  *
62  * It is equivalent to this code:
63  *
64  *  md5_context c;
65  *  md5_init(&c);
66  *  md5_update(&c, buffer, length);
67  *  memcpy(outbuf, md5_final(&c), MD5_SIZE);
68  */
69 void md5_hash_buffer(byte *outbuf, const byte *buffer, uns length);
70
71 #define MD5_HEX_SIZE 33 /** How many bytes a string buffer for MD5 in hexadecimal format should have. **/
72 #define MD5_SIZE 16 /** Number of bytes the MD5 hash takes in the binary form. **/
73
74 #endif /* !_UCW_MD5_H */