/* This code was modified in 1997 by Jim Kingdon of Cyclic Software to notrequireanintegertypewhichisexactly32bits.Thiswork drawsonthechangesforthesamepurposebyTatuYlonen <ylo@cs.hut.fi>aspartofSSH,butsinceIdidn'tactuallyuse thatcode,thereisnocopyrightissue.Iherebydisclaim copyrightinanychangesIhavemade;thiscoderemainsinthe
public domain. */
#include <string.h> /* for memcpy() */
#include"md5.h"
/* Little-endian byte-swapping routines. Note that these do not dependonthesizeofdatatypessuchasuint32_t,nordotheyrequire ustodetecttheendiannessofthemachinewearerunningon.It ispossibletheyshouldbemacrosforspeed,butIwouldbe
surprised if they were a performance bottleneck for MD5. */
t = ctx->bits[0]; if ((ctx->bits[0] = (t + ((uint32_t)len << 3)) & 0xffffffff) < t)
ctx->bits[1]++; /* Carry from low to high */
ctx->bits[1] += len >> 29;
t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
/* Handle any leading odd-sized chunks */
if ( t ) {
uint8_t *p = ctx->in + t;
t = 64-t; if (len < t) {
memcpy(p, buf, len); return;
}
memcpy(p, buf, t);
MD5Transform(ctx->buf, ctx->in);
buf += t;
len -= t;
}
/* Process data in 64-byte chunks */
while (len >= 64) {
memcpy(ctx->in, buf, 64);
MD5Transform(ctx->buf, ctx->in);
buf += 64;
len -= 64;
}
/* Compute number of bytes mod 64 */
count = (ctx->bits[0] >> 3) & 0x3F;
/* Set the first char of padding to 0x80. This is safe since there is
always at least one byte free */
p = ctx->in + count;
*p++ = 0x80;
/* Bytes of padding needed to make 64 bytes */
count = 64 - 1 - count;
/* Pad out to 56 mod 64 */ if (count < 8) { /* Two lots of padding: Pad the first block to 64 bytes */
memset(p, 0, count);
MD5Transform(ctx->buf, ctx->in);
/* Now fill the next block with 56 bytes */
memset(ctx->in, 0, 56);
} else { /* Pad block to 56 bytes */
memset(p, 0, count-8);
}
/* Append length in bits and transform */
putu32(ctx->bits[0], ctx->in + 56);
putu32(ctx->bits[1], ctx->in + 60);
/* The four core functions - F1 is optimized somewhat */
/* #define F1(x, y, z) (x & y | ~x & z) */ #define F1(x, y, z) (z ^ (x & (y ^ z))) #define F2(x, y, z) F1(z, x, y) #define F3(x, y, z) (x ^ y ^ z) #define F4(x, y, z) (y ^ (x | ~z))
/* This is the central step in the MD5 algorithm. */ #define MD5STEP(f, w, x, y, z, data, s) \
( w += f(x, y, z) + data, w &= 0xffffffff, w = w<<s | w>>(32-s), w += x )
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.