hacking the server
[reposerve] / server / src / md5.h
1 /* MD5 message digest
2  * Author: John Tsiombikas <nuclear@member.fsf.org>
3  *
4  * This software is public domain. Feel free to use it any way you like.
5  *
6  * If public domain is not applicable in your part of the world, you may use
7  * this under the terms of the Creative Commons CC-0 license:
8  * http://creativecommons.org/publicdomain/zero/1.0/
9  *
10  *
11  * usage example 1: compute the md5 sum of the string "hello world"
12  *
13  *    struct md5_state md;
14  *    md5_begin(&md);
15  *    md5_msg(&md, "hello world", 11);
16  *    md5_end(&md);
17  *
18  * md5 sum in: md5_state.sum[0..4]
19  * To print it you may use the helper function md5_sumstr:
20  *    printf("%s\n", md5_sumstr(&md));
21  *
22  * usage example 2: comput the md5 sum of whatever comes through stdin
23  *
24  *     int sz;
25  *     struct md5_state md;
26  *     char buf[1024];
27  *
28  *     md5_begin(&md);
29  *     while((sz = fread(buf, 1, sizeof buf, stdin)) > 0) {
30  *         md5_msg(&md, buf, sz);
31  *     }
32  *     md5_end(&md);
33  */
34 #ifndef NUCLEAR_DROPCODE_MD5_H_
35 #define NUCLEAR_DROPCODE_MD5_H_
36
37 #include <stdint.h>
38
39 struct md5_state {
40         uint32_t sum[4];
41         uint64_t len;
42         unsigned char blockbuf[64];
43         int bblen;
44 };
45
46 void md5_begin(struct md5_state *md);
47 void md5_msg(struct md5_state *md, void *msg, int msg_size);
48 void md5_end(struct md5_state *md);
49
50 /* after computing the md5 sum, you may use this function to get a pointer
51  * to a canonical string representation of the sum (identical to GNU md5sum)
52  */
53 const char *md5_sumstr(struct md5_state *md);
54
55 #endif  /* NUCLEAR_DROPCODE_MD5_H_ */