64
64
* You should have received a copy of the GNU General Public License
65
65
* along with this program; if not, write to the Free Software
66
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
66
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
68
68
* Modified by Barry Leslie on 10/17/08.
69
69
* I have put a C++ wrapper around the data and functions to create an Md5 class.
72
72
#ifndef md5_INCLUDED
75
74
#include <string.h>
79
76
/* Define the state of the MD5 Algorithm. */
80
79
typedef unsigned int md5_word_t;
80
#define CHECKSUM_VALUE_SIZE 16
82
#define MD5_CHECKSUM_SIZE CHECKSUM_VALUE_SIZE
83
#define MD5_CHECKSUM_STRING_SIZE (CHECKSUM_VALUE_SIZE * 2 + 1)
83
u_char val[CHECKSUM_VALUE_SIZE];
87
88
struct md5_state_s {
88
md5_word_t count[2]; /* message length in bits, lsw first */
89
md5_word_t abcd[4]; /* digest buffer */
90
u_char buf[64]; /* accumulate block */
89
md5_word_t count[2]; /* message length in bits, lsw first */
90
md5_word_t abcd[4]; /* digest buffer */
91
u_char buf[64]; /* accumulate block */
93
u_char digest[MD5_CHECKSUM_SIZE];
94
char digest_cstr[MD5_CHECKSUM_STRING_SIZE];
96
94
void md5_process(const u_char *data /*[64]*/);
106
104
/* Append a string to the message. */
107
105
void md5_append(const u_char *data, int nbytes);
109
void md5_append(const char *data) {
106
void md5_append(const char *data)
110
108
md5_append((const u_char *) data, strlen(data));
113
112
/* Finish the message and return the digest. */
115
// Returns the raw bin digest.
116
const u_char *md5_get_digest() {
113
void md5_digest(Md5Digest *digest);
122
// Returns the bin/hex digest.
123
void md5_get_digest(Md5Digest *d) {
127
memcpy(d->val, digest, CHECKSUM_VALUE_SIZE);
130
// Returns the bin/hex digest.
131
const char *md5_get_digest_cstr() {
139
117
#endif /* md5_INCLUDED */