aboutsummaryrefslogtreecommitdiff
path: root/src/old/md5.h
blob: 7f77d83454b31c2ac6c0c7458e811911b74b0805 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef MD5_H
#define MD5_H

/**
 * Used to store an MD5 sum in a handy container.
 */
typedef struct
{
	/** The actual data-storage for an MD5 sum. */
	long data[4];
} md5sum;

/**
 * Class for easily calculating MD5 sums of just about any data.
 *@author Mike Buland
 */
class md5
{
public:
	/** Build an MD5 sum builder. */
	md5();

	/** Deconstruct */
	virtual ~md5();

	/**
	 * Create a sum of a standard c string, null terminated.  This is probably
	 * the easiest function to use.
	 *@param pSum The MD5 sum structure to fill up.
	 *@param sStr The null-terminated string to turn into an MD5 sum.
	 */
	void sumString( md5sum *pSum, const char *sStr );

	/**
	 * Create a sum of an array of arbitrary data.  This is the most handy for
	 * dealing with files and so on.
	 *@param pSum The MD5 sum structure to fill up.
	 *@param aData A pointer to the base of the data to sum.
	 *@param nLen The number of bytes to use in the sum.
	 */
	void sumData( md5sum *pSum, const char *aData, long nLen );

	/**
	 * Convert an md5sum to standard hex representation.  Make sure that sHex
	 * contains at least 17 characters of space.
	 *@param pSum The sum structure to convert to hex.
	 *@param sHex The string to store the hex value in.
	 */
	void sumToHex( md5sum *pSum, char *sHex );

private:
	/**
	 * Do the bulk of the work of the md5 algorithm.
	 *@param x I'm not sure.  I'll need to look it up.
	 *@param len The length of the data.
	 *@param output The sum structure to put the output in.
	 */
	void core_md5( long *x, long len, md5sum *output );

	/**
	 * Convert an array of charaters to an array of longs in a very crafty way.
	 * This also applies standard MD5 obfuscation to the resulting array, and
	 * makes it fit within MD5 size constraints.
	 *@param str The data to convert.
	 *@param len The length of the data.
	 *@param nNewLen A pointer to a variable that will hold the new length of
	 * the resulting array of longs.
	 *@returns The newly obfuscated and resized long array.
	 */
	long *c2l( const char *str, long len, long *nNewLen );

	/**
	 * Backend helper to convert an array of longs into a hex string.
	 *@param binarray The binary data to convert.
	 *@param str The string to store the hex string in.
	 */
	void l2hexstr( long *binarray, char *str );
	
};

#endif