/*
* This is an OpenSSL-compatible implementation of the RSA Data Security,
* Inc. MD5 Message-Digest Algorithm.
*
* Written by Solar Designer <solar@openwall.com> in 2001, and placed in
* the public domain. There's absolutely no warranty.
*
* This differs from Colin Plumb's older public domain implementation in
* that no 32-bit integer data type is required, there's no compile-time
* endianness configuration, and the function prototypes match OpenSSL's.
* The primary goals are portability and ease of use.
*
* This implementation is meant to be fast, but not as fast as possible.
* Some known optimizations are not included to reduce source code size
* and avoid compile-time configuration.
*/
#include "lib.h"
#include "safe-memset.h"
#include "md5.h"
/*
* The basic MD5 functions.
*
* F is optimized compared to its RFC 1321 definition just like in Colin
* Plumb's implementation.
*/
#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
#define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y))))
#define H(x, y, z) ((x) ^ (y) ^ (z))
#define I(x, y, z) ((y) ^ ((x) | ~(z)))
/*
* The MD5 transformation for all four rounds.
*/
#define STEP(f, a, b, c, d, x, t, s) \
(a) += f((b), (c), (d)) + (x) + (t); \
(a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \
(a) += (b);
/*
* SET reads 4 input bytes in little-endian byte order and stores them
* in a properly aligned word in host byte order.
*
* The check for little-endian architectures which tolerate unaligned
* memory accesses is just an optimization. Nothing will break if it
* doesn't work.
*/
#define SET(n) \
#define GET(n) \
SET(n)
#else
#define SET(n) \
#define GET(n) \
#endif
/*
* This processes one or more 64-byte data blocks, but does NOT update
* the bit counters. There're no alignment requirements.
*/
static const void * ATTR_NOWARN_UNUSED_RESULT ATTR_UNSIGNED_WRAPS
{
const unsigned char *ptr;
uint_fast32_t a, b, c, d;
a = ctx->a;
b = ctx->b;
c = ctx->c;
d = ctx->d;
do {
saved_a = a;
saved_b = b;
saved_c = c;
saved_d = d;
/* Round 1 */
/* Round 2 */
/* Round 3 */
/* Round 4 */
a += saved_a;
b += saved_b;
c += saved_c;
d += saved_d;
ptr += 64;
} while ((size -= 64) != 0);
ctx->a = a;
ctx->b = b;
ctx->c = c;
ctx->d = d;
return ptr;
}
{
ctx->a = 0x67452301;
ctx->b = 0xefcdab89;
ctx->c = 0x98badcfe;
ctx->d = 0x10325476;
}
void ATTR_UNSIGNED_WRAPS
{
/* @UNSAFE */
if (used != 0) {
return;
}
}
if (size >= 64) {
size &= 0x3f;
}
}
void ATTR_UNSIGNED_WRAPS
{
/* @UNSAFE */
if (free < 8) {
used = 0;
free = 64;
}
}
{
}
{
}
{
}
{
}
"md5",
sizeof(struct md5_context),
};