gloox  1.1-svn
md4.h
1 /*
2  Copyright (c) 2006-2009 by Jakob Schroeter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 /*
14  Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved.
15 
16  This software is provided 'as-is', without any express or implied
17  warranty. In no event will the authors be held liable for any damages
18  arising from the use of this software.
19 
20  Permission is granted to anyone to use this software for any purpose,
21  including commercial applications, and to alter it and redistribute it
22  freely, subject to the following restrictions:
23 
24  1. The origin of this software must not be misrepresented; you must not
25  claim that you wrote the original software. If you use this software
26  in a product, an acknowledgment in the product documentation would be
27  appreciated but is not required.
28  2. Altered source versions must be plainly marked as such, and must not be
29  misrepresented as being the original software.
30  3. This notice may not be removed or altered from any source distribution.
31 
32  L. Peter Deutsch
33  ghost@aladdin.com
34 
35  */
36 /* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */
37 /*
38  Independent implementation of MD5 (RFC 1321).
39 
40  This code implements the MD5 Algorithm defined in RFC 1321, whose
41  text is available at
42  http://www.ietf.org/rfc/rfc1321.txt
43  The code is derived from the text of the RFC, including the test suite
44  (section A.5) but excluding the rest of Appendix A. It does not include
45  any code or documentation that is identified in the RFC as being
46  copyrighted.
47 
48  The original and principal author of md5.h is L. Peter Deutsch
49  <ghost@aladdin.com>. Other authors are noted in the change history
50  that follows (in reverse chronological order):
51 
52  2002-04-13 lpd Removed support for non-ANSI compilers; removed
53  references to Ghostscript; clarified derivation from RFC 1321;
54  now handles byte order either statically or dynamically.
55  1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
56  1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
57  added conditionalization for C++ compilation from Martin
58  Purschke <purschke@bnl.gov>.
59  1999-05-03 lpd Original version.
60  */
61 
62 #ifndef MD4_H__
63 #define MD4_H__
64 
65 #include "macros.h"
66 
67 #include <string>
68 
69 namespace gloox
70 {
71 
81  class GLOOX_API MD4
82  {
83  public:
89  static const std::string md4( const std::string& data );
90 
94  MD4();
95 
99  virtual ~MD4();
100 
106  void feed( const unsigned char* data, int bytes );
107 
112  void feed( const std::string& data );
113 
118  void finalize();
119 
124  const std::string hex();
125 
130  const std::string binary();
131 
135  void reset();
136 
137  private:
138  struct MD4State
139  {
140  unsigned int count[2]; /* message length in bits, lsw first */
141  unsigned int abcd[4]; /* digest buffer */
142  unsigned char buf[64]; /* accumulate block */
143  } m_state;
144 
145  void init();
146  void process( const unsigned char* data );
147 
148  static const unsigned char pad[64];
149 
150  bool m_finished;
151 
152  };
153 
154 }
155 
156 #endif // MD4_H__