|
Packit |
875988 |
/*
|
|
Packit |
875988 |
* This code implements the MD5 message-digest algorithm.
|
|
Packit |
875988 |
* The algorithm is due to Ron Rivest. This code was
|
|
Packit |
875988 |
* written by Colin Plumb in 1993, no copyright is claimed.
|
|
Packit |
875988 |
* This code is in the public domain; do with it what you wish.
|
|
Packit |
875988 |
*
|
|
Packit |
875988 |
* Equivalent code is available from RSA Data Security, Inc.
|
|
Packit |
875988 |
* This code has been tested against that, and is equivalent,
|
|
Packit |
875988 |
* except that you don't need to include two pages of legalese
|
|
Packit |
875988 |
* with every copy.
|
|
Packit |
875988 |
*
|
|
Packit |
875988 |
* To compute the message digest of a chunk of bytes, declare an
|
|
Packit |
875988 |
* MD5Context structure, pass it to MD5Init, call MD5Update as
|
|
Packit |
875988 |
* needed on buffers full of bytes, and then call MD5Final, which
|
|
Packit |
875988 |
* will fill a supplied 16-byte array with the digest.
|
|
Packit |
875988 |
*/
|
|
Packit |
875988 |
|
|
Packit |
875988 |
#ifndef MHD_MD5_H
|
|
Packit |
875988 |
#define MHD_MD5_H
|
|
Packit |
875988 |
|
|
Packit |
875988 |
#include "platform.h"
|
|
Packit |
875988 |
|
|
Packit |
875988 |
#define MD5_BLOCK_SIZE 64
|
|
Packit |
875988 |
#define MD5_DIGEST_SIZE 16
|
|
Packit |
875988 |
#define MD5_DIGEST_STRING_LENGTH (MD5_DIGEST_SIZE * 2 + 1)
|
|
Packit |
875988 |
|
|
Packit |
875988 |
struct MD5Context
|
|
Packit |
875988 |
{
|
|
Packit |
875988 |
uint32_t state[4]; /* state */
|
|
Packit |
875988 |
uint64_t count; /* number of bits, mod 2^64 */
|
|
Packit |
875988 |
uint8_t buffer[MD5_BLOCK_SIZE]; /* input buffer */
|
|
Packit |
875988 |
};
|
|
Packit |
875988 |
|
|
Packit |
875988 |
/*
|
|
Packit |
875988 |
* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
|
|
Packit |
875988 |
* initialization constants.
|
|
Packit |
875988 |
*/
|
|
Packit |
875988 |
void MD5Init(struct MD5Context *ctx);
|
|
Packit |
875988 |
|
|
Packit |
875988 |
/*
|
|
Packit |
875988 |
* Update context to reflect the concatenation of another buffer full
|
|
Packit |
875988 |
* of bytes.
|
|
Packit |
875988 |
*/
|
|
Packit |
875988 |
void MD5Update(struct MD5Context *ctx, const unsigned char *input, size_t len);
|
|
Packit |
875988 |
|
|
Packit |
875988 |
/*
|
|
Packit |
875988 |
* Pad pad to 64-byte boundary with the bit pattern
|
|
Packit |
875988 |
* 1 0* (64-bit count of bits processed, MSB-first)
|
|
Packit |
875988 |
*/
|
|
Packit |
875988 |
void MD5Pad(struct MD5Context *ctx);
|
|
Packit |
875988 |
|
|
Packit |
875988 |
/*
|
|
Packit |
875988 |
* Final wrapup--call MD5Pad, fill in digest and zero out ctx.
|
|
Packit |
875988 |
*/
|
|
Packit |
875988 |
void MD5Final(unsigned char digest[MD5_DIGEST_SIZE], struct MD5Context *ctx);
|
|
Packit |
875988 |
|
|
Packit |
875988 |
/*
|
|
Packit |
875988 |
* The core of the MD5 algorithm, this alters an existing MD5 hash to
|
|
Packit |
875988 |
* reflect the addition of 16 longwords of new data. MD5Update blocks
|
|
Packit |
875988 |
* the data and converts bytes into longwords for this routine.
|
|
Packit |
875988 |
*/
|
|
Packit |
875988 |
void MD5Transform(uint32_t state[4], const uint8_t block[MD5_BLOCK_SIZE]);
|
|
Packit |
875988 |
|
|
Packit |
875988 |
#endif /* !MHD_MD5_H */
|