1
/////////////////////////////////////////////////////////////////////////
3
// Implementation file for MD5 class
5
// This C++ Class implementation of the original RSA Data Security, Inc.
6
// MD5 Message-Digest Algorithm is copyright (c) 2002, Gary McNickle.
7
// All rights reserved. This software is a derivative of the "RSA Data
8
// Security, Inc. MD5 Message-Digest Algorithm"
10
// You may use this software free of any charge, but without any
11
// warranty or implied warranty, provided that you follow the terms
12
// of the original RSA copyright, listed below.
14
// Original RSA Data Security, Inc. Copyright notice
15
/////////////////////////////////////////////////////////////////////////
17
// Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
20
// License to copy and use this software is granted provided that it
21
// is identified as the "RSA Data Security, Inc. MD5 Message-Digest
22
// Algorithm" in all material mentioning or referencing this software
24
// License is also granted to make and use derivative works provided
25
// that such works are identified as "derived from the RSA Data
26
// Security, Inc. MD5 Message-Digest Algorithm" in all material
27
// mentioning or referencing the derived work.
28
// RSA Data Security, Inc. makes no representations concerning either
29
// the merchantability of this software or the suitability of this
30
// software for any particular purpose. It is provided "as is"
31
// without express or implied warranty of any kind.
32
// These notices must be retained in any copies of any part of this
33
// documentation and/or software.
34
/////////////////////////////////////////////////////////////////////////
36
/*------------------------------------------------------------------------------
37
* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
39
* Distributable under the terms of either the Apache License (Version 2.0) or
40
* the GNU Lesser General Public License, as specified in the COPYING file.
41
------------------------------------------------------------------------------*/
43
#ifndef _lucene_util_MD5Digester_H
44
#define _lucene_util_MD5Digester_H
49
typedef unsigned short int uint2;
51
char* PrintMD5(uint8_t md5Digest[16]);
52
char* MD5String(char* szString);
53
char* MD5File(char* szFilename);
61
void Update(uint8_t* chInput, uint32_t nInputLen);
63
uint8_t* Digest() { return m_Digest; }
67
void Transform(uint8_t* block);
68
void Encode(uint8_t* dest, uint32_t* src, uint32_t nLength);
69
void Decode(uint32_t* dest, uint8_t* src, uint32_t nLength);
72
inline uint32_t rotate_left(uint32_t x, uint32_t n)
73
{ return ((x << n) | (x >> (32-n))); }
75
inline uint32_t F(uint32_t x, uint32_t y, uint32_t z)
76
{ return ((x & y) | (~x & z)); }
78
inline uint32_t G(uint32_t x, uint32_t y, uint32_t z)
79
{ return ((x & z) | (y & ~z)); }
81
inline uint32_t H(uint32_t x, uint32_t y, uint32_t z)
82
{ return (x ^ y ^ z); }
84
inline uint32_t I(uint32_t x, uint32_t y, uint32_t z)
85
{ return (y ^ (x | ~z)); }
87
inline void FF(uint32_t& a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac)
88
{ a += F(b, c, d) + x + ac; a = rotate_left(a, s); a += b; }
90
inline void GG(uint32_t& a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac)
91
{ a += G(b, c, d) + x + ac; a = rotate_left(a, s); a += b; }
93
inline void HH(uint32_t& a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac)
94
{ a += H(b, c, d) + x + ac; a = rotate_left(a, s); a += b; }
96
inline void II(uint32_t& a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac)
97
{ a += I(b, c, d) + x + ac; a = rotate_left(a, s); a += b; }
103
uint8_t m_Buffer[64];
104
uint8_t m_Digest[16];