summaryrefslogtreecommitdiff
path: root/lib/md5.h
blob: 8415c77674dc0f8b2256b5cc644c839729749c00 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef MD5_H
#define MD5_H

/** \file lib/md5.h
 * @todo Eliminate, use rpmio version instead.
 */

#include <sys/types.h>

typedef unsigned int uint32;

/**
 * MD5 private data.
 */
struct MD5Context {
	uint32 buf[4];
	uint32 bits[2];
	unsigned char in[64];
	int doByteReverse;
};

/*
 * This is needed to make RSAREF happy on some MS-DOS compilers.
 */
typedef /*@abstract@*/ struct MD5Context MD5_CTX;

#ifdef __cplusplus
extern "C" {
#endif

/**
 * Initialize MD5 hash.
 * Set bit count to 0 and buffer to mysterious initialization constants.
 * @param context	MD5 private data
 * @param brokenEndian	calculate broken MD5 sum?
 */
void rpmMD5Init( /*@out@*/ struct MD5Context *context, int brokenEndian);

/**
 * Update context to reflect the concatenation of another buffer full
 * of bytes.
 * @param context	MD5 private data
 * @param data		next data buffer
 * @param len		no. bytes of data
 */
void rpmMD5Update(struct MD5Context *context, unsigned char const *buf,
	       unsigned len);
/**
 * Return MD5 digest, and reset context.
 * @retval		MD5 digest
 * @param context	MD5 private data
 */
void rpmMD5Final(unsigned char digest[16], struct MD5Context *context);

/**
 * The core of the MD5 algorithm.
 * This alters an existing MD5 hash to reflect the addition of 16 longwords
 * of new data.
 * @param buf		current MD5 variables
 * @param in		next block of data to add
 */
void rpmMD5Transform(uint32 buf[4], uint32 const in[16]);

/**
 * Return MD5 sum of file as ASCII string.
 * @param fn		file name
 * @retval digest	MD5 digest
 * @return		0 on success, 1 on error
 */
int mdfile(const char *fn, unsigned char *digest);

/**
 * Return MD5 sum of file as binary data.
 * @param fn		file name
 * @retval bindigest	MD5 digest
 * @return		0 on success, 1 on error
 */
int mdbinfile(const char *fn, unsigned char *bindigest);

/* These assume a little endian machine and return incorrect results!
   They are here for compatibility with old (broken) versions of RPM */

/**
 * Return (broken!) MD5 sum of file as ASCII string.
 * @deprecated Here for compatibility with old (broken) versions of RPM.
 * @param fn		file name
 * @retval digest	MD5 digest
 * @return		0 on success, 1 on error
 */
int mdfileBroken(const char *fn, unsigned char *digest);

/**
 * Return (broken!) MD5 sum of file as binary data.
 * @deprecated Here for compatibility with old (broken) versions of RPM.
 * @param fn		file name
 * @retval bindigest	MD5 digest
 * @return		0 on success, 1 on error
 */
int mdbinfileBroken(const char *fn, unsigned char *bindigest);

#ifdef __cplusplus
}
#endif

#endif	/* MD5_H */