md5.c revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
/*
* Copyright (C) 2000, 2001, 2004, 2005, 2007, 2009, 2014-2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* $Id: md5.c,v 1.16 2009/02/06 23:47:42 tbox Exp $ */
/*! \file
* This code implements the MD5 message-digest algorithm.
* The algorithm is due to Ron Rivest. This code was
* written by Colin Plumb in 1993, no copyright is claimed.
* This code is in the public domain; do with it what you wish.
*
* Equivalent code is available from RSA Data Security, Inc.
* This code has been tested against that, and is equivalent,
* except that you don't need to include two pages of legalese
* with every copy.
*
* To compute the message digest of a chunk of bytes, declare an
* MD5Context structure, pass it to MD5Init, call MD5Update as
* needed on buffers full of bytes, and then call MD5Final, which
* will fill a supplied 16-byte array with the digest.
*/
#include "config.h"
#include <isc/assertions.h>
#include <isc/platform.h>
#if PKCS11CRYPTO
#include <pk11/internal.h>
#endif
#ifdef ISC_PLATFORM_OPENSSLHASH
void
}
void
}
void
if (len == 0U)
return;
(const void *) buf,
}
void
}
void
}
void
return;
}
void
}
void
}
#else
static void
{
unsigned char *p = (unsigned char *)buf;
do {
((unsigned)p[1] << 8 | p[0]);
p += 4;
} while (--words);
}
/*!
* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
* initialization constants.
*/
void
}
void
}
/*@{*/
/*! 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 F3(x, y, z) (x ^ y ^ z)
#define F4(x, y, z) (y ^ (x | ~z))
/*@}*/
/*! This is the central step in the MD5 algorithm. */
(w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
/*!
* The core of the MD5 algorithm, this alters an existing MD5 hash to
* reflect the addition of 16 longwords of new data. MD5Update blocks
* the data and converts bytes into longwords for this routine.
*/
static void
register isc_uint32_t a, b, c, d;
a = buf[0];
b = buf[1];
c = buf[2];
d = buf[3];
buf[0] += a;
buf[1] += b;
buf[2] += c;
buf[3] += d;
}
/*!
* Update context to reflect the concatenation of another buffer full
* of bytes.
*/
void
isc_uint32_t t;
/* Update byte count */
t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */
if (t > len) {
return;
}
/* First chunk is an odd size */
buf += t;
len -= t;
/* Process data in 64-byte chunks */
while (len >= 64) {
buf += 64;
len -= 64;
}
/* Handle any remaining bytes of data. */
}
/*!
* Final wrapup - pad to 64-byte boundary with the bit pattern
* 1 0* (64-bit count of bits processed, MSB-first)
*/
void
/* Set the first char of padding to 0x80. There is always room. */
*p++ = 0x80;
/* Bytes of padding needed to make 56 bytes (-8..55) */
if (count < 0) { /* Padding forces an extra block */
count = 56;
}
/* Append length in bits and transform */
}
#endif