1 /* MD5
2  * converted to C++ class by Frank Thilo (thilo@unix-ag.org)
3  * for bzflag (http://www.bzflag.org)
4  *
5  *  based on:
6  *
7  * This is the header file for the MD5 message-digest algorithm.
8  * The algorithm is due to Ron Rivest.  This code was
9  * written by Colin Plumb in 1993, no copyright is claimed.
10  * This code is in the public domain; do with it what you wish.
11  *
12  * Equivalent code is available from RSA Data Security, Inc.
13  * This code has been tested against that, and is equivalent,
14  * except that you don't need to include two pages of legalese
15  * with every copy.
16  *
17  * To compute the message digest of a chunk of bytes, declare an
18  * MD5Context structure, pass it to MD5Init, call MD5Update as
19  * needed on buffers full of bytes, and then call MD5Final, which
20  * will fill a supplied 16-byte array with the digest.
21  *
22  * Changed so as no longer to depend on Colin Plumb's `usual.h'
23  * header definitions; now uses stuff from dpkg's config.h
24  *  - Ian Jackson <ian@chiark.greenend.org.uk>.
25  * Still in the public domain.
26 */
27 
28 #ifndef BZF_MD5_H
29 #define BZF_MD5_H
30 
31 #include "common.h"
32 
33 /* system interface headers */
34 #include <string>
35 #include <iostream>
36 
37 
38 // a small class for calculating MD5 hashes of strings or byte arrays
39 // it is not meant to be fast or secure
40 //
41 // usage: 1) feed it blocks of uchars with update()
42 //  2) finalize()
43 //  3) get hexdigest() string
44 //      or
45 //  MD5(std::string).hexdigest()
46 //
47 // assumes that char is 8 bit and int is 32 bit
48 class MD5
49 {
50 public:
51     uint8_t digest[16];
52     MD5();
53     MD5(const std::string& text);
54     void update(const unsigned char *buf, uint32_t length);
55     void finalize();
56     std::string hexdigest() const;
57     friend std::ostream& operator<<(std::ostream&, MD5 md5);
58 
59 private:
60     uint32_t buf[4];
61     uint32_t bytes[2];
62     uint32_t in[16];
63     bool finalized;
64     void init(void);
65     void transform(void);
66 };
67 
68 #endif
69 
70 // Local Variables: ***
71 // mode: C++ ***
72 // tab-width: 4 ***
73 // c-basic-offset: 4 ***
74 // indent-tabs-mode: nil ***
75 // End: ***
76 // ex: shiftwidth=4 tabstop=4
77