1 //------------------------------------------------------------------------
2 //  EDGE MD5 : Message-Digest (Secure Hash)
3 //------------------------------------------------------------------------
4 //
5 //  Copyright (c) 2003-2008  The EDGE Team.
6 //
7 //  This program is free software; you can redistribute it and/or
8 //  modify it under the terms of the GNU General Public License
9 //  as published by the Free Software Foundation; either version 2
10 //  of the License, or (at your option) any later version.
11 //
12 //  This program is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //  GNU General Public License for more details.
16 //
17 //------------------------------------------------------------------------
18 //
19 //  Based on the MD5 code in the Linux kernel, which says:
20 //
21 //  |  The code for MD5 transform was taken from Colin Plumb's
22 //  |  implementation, which has been placed in the public domain.  The
23 //  |  MD5 cryptographic checksum was devised by Ronald Rivest, and is
24 //  |  documented in RFC 1321, "The MD5 Message Digest Algorithm".
25 //
26 //------------------------------------------------------------------------
27 
28 #ifndef __EPI_MD5_H__
29 #define __EPI_MD5_H__
30 
31 namespace epi
32 {
33 
34 class md5hash_c
35 {
36 	/* sealed */
37 
38 public:
39 	byte hash[16];
40 
41 	md5hash_c();
42 	md5hash_c(const byte *message, unsigned int len);
43 
~md5hash_c()44 	~md5hash_c()
45   { }
46 
47 	void Compute(const byte *message, unsigned int len);
48 
49 private:
50 	// a class used while computing the MD5 sum.
51 	// Not actually used with a member variable.
52 
53   class packhash_c
54   {
55 	public:
56 		u32_t pack[4];
57 
58 		packhash_c();
~packhash_c()59 		~packhash_c() { }
60 
61 		void Transform(const u32_t extra[16]);
62 		void TransformBytes(const byte chunk[64]);
63 		void Encode(byte *hash);
64   };
65 };
66 
67 } // namespace epi
68 
69 //------------------------------------------------------------------------
70 //
71 //  DEBUG STUFF
72 //
73 
74 #ifdef DEBUG_EPI
75 namespace debugepi
76 {
77 	void TestMd5Hash();
78 };
79 #endif  // DEBUG_EPI
80 
81 #endif  /* __EPI_MD5_H__ */
82 
83 //--- editor settings ---
84 // vi:ts=4:sw=4:noexpandtab
85