8415c77674dc0f8b2256b5cc644c839729749c00
[tools/librpm-tizen.git] / lib / md5.h
1 #ifndef MD5_H
2 #define MD5_H
3
4 /** \file lib/md5.h
5  * @todo Eliminate, use rpmio version instead.
6  */
7
8 #include <sys/types.h>
9
10 typedef unsigned int uint32;
11
12 /**
13  * MD5 private data.
14  */
15 struct MD5Context {
16         uint32 buf[4];
17         uint32 bits[2];
18         unsigned char in[64];
19         int doByteReverse;
20 };
21
22 /*
23  * This is needed to make RSAREF happy on some MS-DOS compilers.
24  */
25 typedef /*@abstract@*/ struct MD5Context MD5_CTX;
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 /**
32  * Initialize MD5 hash.
33  * Set bit count to 0 and buffer to mysterious initialization constants.
34  * @param context       MD5 private data
35  * @param brokenEndian  calculate broken MD5 sum?
36  */
37 void rpmMD5Init( /*@out@*/ struct MD5Context *context, int brokenEndian);
38
39 /**
40  * Update context to reflect the concatenation of another buffer full
41  * of bytes.
42  * @param context       MD5 private data
43  * @param data          next data buffer
44  * @param len           no. bytes of data
45  */
46 void rpmMD5Update(struct MD5Context *context, unsigned char const *buf,
47                unsigned len);
48 /**
49  * Return MD5 digest, and reset context.
50  * @retval              MD5 digest
51  * @param context       MD5 private data
52  */
53 void rpmMD5Final(unsigned char digest[16], struct MD5Context *context);
54
55 /**
56  * The core of the MD5 algorithm.
57  * This alters an existing MD5 hash to reflect the addition of 16 longwords
58  * of new data.
59  * @param buf           current MD5 variables
60  * @param in            next block of data to add
61  */
62 void rpmMD5Transform(uint32 buf[4], uint32 const in[16]);
63
64 /**
65  * Return MD5 sum of file as ASCII string.
66  * @param fn            file name
67  * @retval digest       MD5 digest
68  * @return              0 on success, 1 on error
69  */
70 int mdfile(const char *fn, unsigned char *digest);
71
72 /**
73  * Return MD5 sum of file as binary data.
74  * @param fn            file name
75  * @retval bindigest    MD5 digest
76  * @return              0 on success, 1 on error
77  */
78 int mdbinfile(const char *fn, unsigned char *bindigest);
79
80 /* These assume a little endian machine and return incorrect results!
81    They are here for compatibility with old (broken) versions of RPM */
82
83 /**
84  * Return (broken!) MD5 sum of file as ASCII string.
85  * @deprecated Here for compatibility with old (broken) versions of RPM.
86  * @param fn            file name
87  * @retval digest       MD5 digest
88  * @return              0 on success, 1 on error
89  */
90 int mdfileBroken(const char *fn, unsigned char *digest);
91
92 /**
93  * Return (broken!) MD5 sum of file as binary data.
94  * @deprecated Here for compatibility with old (broken) versions of RPM.
95  * @param fn            file name
96  * @retval bindigest    MD5 digest
97  * @return              0 on success, 1 on error
98  */
99 int mdbinfileBroken(const char *fn, unsigned char *bindigest);
100
101 #ifdef __cplusplus
102 }
103 #endif
104
105 #endif  /* MD5_H */