/*
* MD4 (RFC-1320) message digest.
* Modified from MD5 code by Andrey Panin <pazke@donpac.ru>
*
* 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 "md4.h"
/*
* The basic MD4 functions.
*/
#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
#define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
#define H(x, y, z) ((x) ^ (y) ^ (z))
/*
* The MD4 transformation for all four rounds.
*/
#define STEP(f, a, b, c, d, x, s) \
(a) += f((b), (c), (d)) + (x); \
(a) = ((a) << (s)) | ((a) >> (32 - (s)))
/*
* 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.
*/
/* uint_fast32_t might be 64 bit, and thus may read 4 more bytes
* beyond the end of the buffer. So only read precisely 32 bits
*/
#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;
uint32_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 */
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;
}
{
/* @UNSAFE */
if (used != 0) {
return;
}
}
if (size >= 64) {
size &= 0x3f;
}
}
{
/* @UNSAFE */
if (free < 8) {
used = 0;
free = 64;
}
}
{
}
{
}
{
}
{
}
"md4",
sizeof(struct md4_context),
};