/* md5.c - MD5 Message-Digest Algorithm
- * Copyright (c) 1994 by Werner Koch (dd9jn)
+ * Copyright (C) 1995,1996,1998,1999,2001,2002,
+ * 2003 Free Software Foundation, Inc.
*
- * This is a hacked version from WkLib
+ * This file is part of Libgcrypt.
*
- * This file is part of WkLib.
+ * Libgcrypt is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
*
- * WkLib is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * Libgcrypt is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
*
- * WkLib is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- ***********************************************************************
- ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. **
- ** **
- ** License to copy and use this software is granted provided that **
- ** it is identified as the "RSA Data Security, Inc. MD5 Message- **
- ** Digest Algorithm" in all material mentioning or referencing this **
- ** software or this function. **
- ** **
- ** License is also granted to make and use derivative works **
- ** provided that such works are identified as "derived from the RSA **
- ** Data Security, Inc. MD5 Message-Digest Algorithm" in all **
- ** material mentioning or referencing the derived work. **
- ** **
- ** RSA Data Security, Inc. makes no representations concerning **
- ** either the merchantability of this software or the suitability **
- ** of this software for any particular purpose. It is provided "as **
- ** is" without express or implied warranty of any kind. **
- ** **
- ** These notices must be retained in any copies of any part of this **
- ** documentation and/or software. **
- ***********************************************************************
- *
- * History:
- * 16.01.95 wk now uses generic base-64 support
- * 24.01.95 wk changed back to original base-64 coding, because
- * the generic base-64 support was changed to go conform
- * with RFC1113 !
+ * According to the definition of MD5 in RFC 1321 from April 1992.
+ * NOTE: This is *not* the same file as the one from glibc.
+ * Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
+ * heavily modified for GnuPG by Werner Koch <wk@gnupg.org>
*/
/* Test values:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <assert.h>
-#include "util.h"
-#include "md5.h"
-#include "memory.h"
-
-
-#if __WATCOMC__ && defined(M_I86)
- /* 16-Bit Compiler breaks Code in Function Transform() */
- /* (at least when compiling for windows) */
- #ifndef __SW_OD
- #error must be compiled without optimizations
- #endif
-#endif
-
-
-static void Transform(u32 *buf,u32 *in);
-
-static byte PADDING[64] = {
- 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-};
-
-/* F, G, H and I are basic MD5 functions */
-#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
-#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
-#define H(x, y, z) ((x) ^ (y) ^ (z))
-#define I(x, y, z) ((y) ^ ((x) | (~z)))
-
-/* ROTATE_LEFT rotates x left n bits */
-#if defined(__GNUC__) && defined(__i386__)
-static inline u32
-ROTATE_LEFT(u32 x, int n)
-{
- __asm__("roll %%cl,%0"
- :"=r" (x)
- :"0" (x),"c" (n));
- return x;
-}
-#else
- #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
-#endif
-
-/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 */
-/* Rotation is separate from addition to prevent recomputation */
-#define FF(a, b, c, d, x, s, ac) \
- {(a) += F ((b), (c), (d)) + (x) + (u32)(ac); \
- (a) = ROTATE_LEFT ((a), (s)); \
- (a) += (b); \
- }
-#define GG(a, b, c, d, x, s, ac) \
- {(a) += G ((b), (c), (d)) + (x) + (u32)(ac); \
- (a) = ROTATE_LEFT ((a), (s)); \
- (a) += (b); \
- }
-#define HH(a, b, c, d, x, s, ac) \
- {(a) += H ((b), (c), (d)) + (x) + (u32)(ac); \
- (a) = ROTATE_LEFT ((a), (s)); \
- (a) += (b); \
- }
-#define II(a, b, c, d, x, s, ac) \
- {(a) += I ((b), (c), (d)) + (x) + (u32)(ac); \
- (a) = ROTATE_LEFT ((a), (s)); \
- (a) += (b); \
- }
-
-
-void
-md5_init( MD5_CONTEXT *mdContext)
+
+#include "g10lib.h"
+#include "cipher.h"
+
+#include "bithelp.h"
+#include "bufhelp.h"
+#include "hash-common.h"
+
+
+typedef struct {
+ gcry_md_block_ctx_t bctx;
+ u32 A,B,C,D; /* chaining variables */
+} MD5_CONTEXT;
+
+static unsigned int
+transform ( void *ctx, const unsigned char *data );
+
+static void
+md5_init( void *context )
{
- mdContext->i[0] = mdContext->i[1] = (u32)0;
- /* Load magic initialization constants.
- */
- mdContext->buf[0] = (u32)0x67452301L;
- mdContext->buf[1] = (u32)0xefcdab89L;
- mdContext->buf[2] = (u32)0x98badcfeL;
- mdContext->buf[3] = (u32)0x10325476L;
- mdContext->count = 0;
+ MD5_CONTEXT *ctx = context;
+
+ ctx->A = 0x67452301;
+ ctx->B = 0xefcdab89;
+ ctx->C = 0x98badcfe;
+ ctx->D = 0x10325476;
+
+ ctx->bctx.nblocks = 0;
+ ctx->bctx.nblocks_high = 0;
+ ctx->bctx.count = 0;
+ ctx->bctx.blocksize = 64;
+ ctx->bctx.bwrite = transform;
}
-/* The routine Update updates the message-digest context to
- * account for the presence of each of the characters inBuf[0..inLen-1]
- * in the message whose digest is being computed.
+
+/* These are the four functions used in the four steps of the MD5 algorithm
+ and defined in the RFC 1321. The first function is a little bit optimized
+ (as found in Colin Plumbs public domain implementation). */
+/* #define FF(b, c, d) ((b & c) | (~b & d)) */
+#define FF(b, c, d) (d ^ (b & (c ^ d)))
+#define FG(b, c, d) FF (d, b, c)
+#define FH(b, c, d) (b ^ c ^ d)
+#define FI(b, c, d) (c ^ (b | ~d))
+
+
+/****************
+ * transform n*64 bytes
*/
-void
-md5_write( MD5_CONTEXT *mdContext, byte *inBuf, size_t inLen)
+static unsigned int
+transform ( void *c, const unsigned char *data )
{
- register int i, ii;
- int mdi;
- u32 in[16];
-
- if(mdContext->count) { /* flush the buffer */
- i = mdContext->count;
- mdContext->count = 0;
- md5_write( mdContext, mdContext->digest, i);
- }
- if( !inBuf )
- return;
-
- /* compute number of bytes mod 64 */
- mdi = (int)((mdContext->i[0] >> 3) & 0x3F);
-
- /* update number of bits */
- if((mdContext->i[0] + ((u32)inLen << 3)) < mdContext->i[0])
- mdContext->i[1]++;
- mdContext->i[0] += ((u32)inLen << 3);
- mdContext->i[1] += ((u32)inLen >> 29);
-
- while(inLen--) {
- /* add new character to buffer, increment mdi */
- mdContext->in[mdi++] = *inBuf++;
-
- /* transform if necessary */
- if( mdi == 0x40 ) {
- for(i = 0, ii = 0; i < 16; i++, ii += 4)
- in[i] = (((u32)mdContext->in[ii+3]) << 24) |
- (((u32)mdContext->in[ii+2]) << 16) |
- (((u32)mdContext->in[ii+1]) << 8) |
- ((u32)mdContext->in[ii]);
- Transform(mdContext->buf, in);
- mdi = 0;
- }
- }
+ MD5_CONTEXT *ctx = c;
+ u32 correct_words[16];
+ register u32 A = ctx->A;
+ register u32 B = ctx->B;
+ register u32 C = ctx->C;
+ register u32 D = ctx->D;
+ u32 *cwp = correct_words;
+ int i;
+
+ for ( i = 0; i < 16; i++ )
+ correct_words[i] = buf_get_le32(data + i * 4);
+
+#define OP(a, b, c, d, s, T) \
+ do \
+ { \
+ a += FF (b, c, d) + (*cwp++) + T; \
+ a = rol(a, s); \
+ a += b; \
+ } \
+ while (0)
+
+ /* Before we start, one word about the strange constants.
+ They are defined in RFC 1321 as
+
+ T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..64
+ */
+
+ /* Round 1. */
+ OP (A, B, C, D, 7, 0xd76aa478);
+ OP (D, A, B, C, 12, 0xe8c7b756);
+ OP (C, D, A, B, 17, 0x242070db);
+ OP (B, C, D, A, 22, 0xc1bdceee);
+ OP (A, B, C, D, 7, 0xf57c0faf);
+ OP (D, A, B, C, 12, 0x4787c62a);
+ OP (C, D, A, B, 17, 0xa8304613);
+ OP (B, C, D, A, 22, 0xfd469501);
+ OP (A, B, C, D, 7, 0x698098d8);
+ OP (D, A, B, C, 12, 0x8b44f7af);
+ OP (C, D, A, B, 17, 0xffff5bb1);
+ OP (B, C, D, A, 22, 0x895cd7be);
+ OP (A, B, C, D, 7, 0x6b901122);
+ OP (D, A, B, C, 12, 0xfd987193);
+ OP (C, D, A, B, 17, 0xa679438e);
+ OP (B, C, D, A, 22, 0x49b40821);
+
+#undef OP
+#define OP(f, a, b, c, d, k, s, T) \
+ do \
+ { \
+ a += f (b, c, d) + correct_words[k] + T; \
+ a = rol(a, s); \
+ a += b; \
+ } \
+ while (0)
+
+ /* Round 2. */
+ OP (FG, A, B, C, D, 1, 5, 0xf61e2562);
+ OP (FG, D, A, B, C, 6, 9, 0xc040b340);
+ OP (FG, C, D, A, B, 11, 14, 0x265e5a51);
+ OP (FG, B, C, D, A, 0, 20, 0xe9b6c7aa);
+ OP (FG, A, B, C, D, 5, 5, 0xd62f105d);
+ OP (FG, D, A, B, C, 10, 9, 0x02441453);
+ OP (FG, C, D, A, B, 15, 14, 0xd8a1e681);
+ OP (FG, B, C, D, A, 4, 20, 0xe7d3fbc8);
+ OP (FG, A, B, C, D, 9, 5, 0x21e1cde6);
+ OP (FG, D, A, B, C, 14, 9, 0xc33707d6);
+ OP (FG, C, D, A, B, 3, 14, 0xf4d50d87);
+ OP (FG, B, C, D, A, 8, 20, 0x455a14ed);
+ OP (FG, A, B, C, D, 13, 5, 0xa9e3e905);
+ OP (FG, D, A, B, C, 2, 9, 0xfcefa3f8);
+ OP (FG, C, D, A, B, 7, 14, 0x676f02d9);
+ OP (FG, B, C, D, A, 12, 20, 0x8d2a4c8a);
+
+ /* Round 3. */
+ OP (FH, A, B, C, D, 5, 4, 0xfffa3942);
+ OP (FH, D, A, B, C, 8, 11, 0x8771f681);
+ OP (FH, C, D, A, B, 11, 16, 0x6d9d6122);
+ OP (FH, B, C, D, A, 14, 23, 0xfde5380c);
+ OP (FH, A, B, C, D, 1, 4, 0xa4beea44);
+ OP (FH, D, A, B, C, 4, 11, 0x4bdecfa9);
+ OP (FH, C, D, A, B, 7, 16, 0xf6bb4b60);
+ OP (FH, B, C, D, A, 10, 23, 0xbebfbc70);
+ OP (FH, A, B, C, D, 13, 4, 0x289b7ec6);
+ OP (FH, D, A, B, C, 0, 11, 0xeaa127fa);
+ OP (FH, C, D, A, B, 3, 16, 0xd4ef3085);
+ OP (FH, B, C, D, A, 6, 23, 0x04881d05);
+ OP (FH, A, B, C, D, 9, 4, 0xd9d4d039);
+ OP (FH, D, A, B, C, 12, 11, 0xe6db99e5);
+ OP (FH, C, D, A, B, 15, 16, 0x1fa27cf8);
+ OP (FH, B, C, D, A, 2, 23, 0xc4ac5665);
+
+ /* Round 4. */
+ OP (FI, A, B, C, D, 0, 6, 0xf4292244);
+ OP (FI, D, A, B, C, 7, 10, 0x432aff97);
+ OP (FI, C, D, A, B, 14, 15, 0xab9423a7);
+ OP (FI, B, C, D, A, 5, 21, 0xfc93a039);
+ OP (FI, A, B, C, D, 12, 6, 0x655b59c3);
+ OP (FI, D, A, B, C, 3, 10, 0x8f0ccc92);
+ OP (FI, C, D, A, B, 10, 15, 0xffeff47d);
+ OP (FI, B, C, D, A, 1, 21, 0x85845dd1);
+ OP (FI, A, B, C, D, 8, 6, 0x6fa87e4f);
+ OP (FI, D, A, B, C, 15, 10, 0xfe2ce6e0);
+ OP (FI, C, D, A, B, 6, 15, 0xa3014314);
+ OP (FI, B, C, D, A, 13, 21, 0x4e0811a1);
+ OP (FI, A, B, C, D, 4, 6, 0xf7537e82);
+ OP (FI, D, A, B, C, 11, 10, 0xbd3af235);
+ OP (FI, C, D, A, B, 2, 15, 0x2ad7d2bb);
+ OP (FI, B, C, D, A, 9, 21, 0xeb86d391);
+
+ /* Put checksum in context given as argument. */
+ ctx->A += A;
+ ctx->B += B;
+ ctx->C += C;
+ ctx->D += D;
+
+ return /*burn_stack*/ 80+6*sizeof(void*);
}
* Returns 16 bytes representing the digest.
*/
-void
-md5_final( MD5_CONTEXT *mdContext )
+static void
+md5_final( void *context)
{
- u32 in[16];
- int mdi;
- unsigned int i, ii;
- unsigned int padLen;
-
- if(mdContext->count) /* flush buffer */
- md5_write(mdContext, NULL, 0 );
- /* save number of bits */
- in[14] = mdContext->i[0];
- in[15] = mdContext->i[1];
-
- /* compute number of bytes mod 64 */
- mdi = (int)((mdContext->i[0] >> 3) & 0x3F);
-
- /* pad out to 56 mod 64 */
- padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi);
- md5_write(mdContext, PADDING, padLen);
-
- /* append length in bits and transform */
- for(i = 0, ii = 0; i < 14; i++, ii += 4)
- in[i] = (((u32)mdContext->in[ii+3]) << 24) |
- (((u32)mdContext->in[ii+2]) << 16) |
- (((u32)mdContext->in[ii+1]) << 8) |
- ((u32)mdContext->in[ii]);
- Transform(mdContext->buf, in);
-
- /* store buffer in digest */
- for(i = 0, ii = 0; i < 4; i++, ii += 4) {
- mdContext->digest[ii] = (byte)(mdContext->buf[i] & 0xFF);
- mdContext->digest[ii+1] = (byte)((mdContext->buf[i] >> 8) & 0xFF);
- mdContext->digest[ii+2] = (byte)((mdContext->buf[i] >> 16) & 0xFF);
- mdContext->digest[ii+3] = (byte)((mdContext->buf[i] >> 24) & 0xFF);
+ MD5_CONTEXT *hd = context;
+ u32 t, th, msb, lsb;
+ byte *p;
+ unsigned int burn;
+
+ _gcry_md_block_write(hd, NULL, 0); /* flush */;
+
+ t = hd->bctx.nblocks;
+ if (sizeof t == sizeof hd->bctx.nblocks)
+ th = hd->bctx.nblocks_high;
+ else
+ th = hd->bctx.nblocks >> 32;
+
+ /* multiply by 64 to make a byte count */
+ lsb = t << 6;
+ msb = (th << 6) | (t >> 26);
+ /* add the count */
+ t = lsb;
+ if( (lsb += hd->bctx.count) < t )
+ msb++;
+ /* multiply by 8 to make a bit count */
+ t = lsb;
+ lsb <<= 3;
+ msb <<= 3;
+ msb |= t >> 29;
+
+ if( hd->bctx.count < 56 ) /* enough room */
+ {
+ hd->bctx.buf[hd->bctx.count++] = 0x80; /* pad */
+ while( hd->bctx.count < 56 )
+ hd->bctx.buf[hd->bctx.count++] = 0; /* pad */
}
-}
+ else /* need one extra block */
+ {
+ hd->bctx.buf[hd->bctx.count++] = 0x80; /* pad character */
+ while( hd->bctx.count < 64 )
+ hd->bctx.buf[hd->bctx.count++] = 0;
+ _gcry_md_block_write(hd, NULL, 0); /* flush */;
+ memset(hd->bctx.buf, 0, 56 ); /* fill next block with zeroes */
+ }
+ /* append the 64 bit count */
+ buf_put_le32(hd->bctx.buf + 56, lsb);
+ buf_put_le32(hd->bctx.buf + 60, msb);
+ burn = transform( hd, hd->bctx.buf );
+ _gcry_burn_stack (burn);
+
+ p = hd->bctx.buf;
+#define X(a) do { *(u32*)p = le_bswap32((*hd).a) ; p += 4; } while(0)
+ X(A);
+ X(B);
+ X(C);
+ X(D);
+#undef X
+}
-/* Basic MD5 step. Transforms buf based on in. Note that if the Mysterious
- * Constants are arranged backwards in little-endian order and decrypted with
- * the DES they produce OCCULT MESSAGES!
- */
-static void
-Transform(register u32 *buf,register u32 *in)
+static byte *
+md5_read( void *context )
{
- register u32 a = buf[0], b = buf[1], c = buf[2], d = buf[3];
-
- /* Round 1 */
-#define S11 7
-#define S12 12
-#define S13 17
-#define S14 22
- FF ( a, b, c, d, in[ 0], S11, 0xD76AA478L); /* 1 */
- FF ( d, a, b, c, in[ 1], S12, 0xE8C7B756L); /* 2 */
- FF ( c, d, a, b, in[ 2], S13, 0x242070DBL); /* 3 */
- FF ( b, c, d, a, in[ 3], S14, 0xC1BDCEEEL); /* 4 */
- FF ( a, b, c, d, in[ 4], S11, 0xF57C0FAFL); /* 5 */
- FF ( d, a, b, c, in[ 5], S12, 0x4787C62AL); /* 6 */
- FF ( c, d, a, b, in[ 6], S13, 0xA8304613L); /* 7 */
- FF ( b, c, d, a, in[ 7], S14, 0xFD469501L); /* 8 */
- FF ( a, b, c, d, in[ 8], S11, 0x698098D8L); /* 9 */
- FF ( d, a, b, c, in[ 9], S12, 0x8B44F7AFL); /* 10 */
- FF ( c, d, a, b, in[10], S13, 0xFFFF5BB1L); /* 11 */
- FF ( b, c, d, a, in[11], S14, 0x895CD7BEL); /* 12 */
- FF ( a, b, c, d, in[12], S11, 0x6B901122L); /* 13 */
- FF ( d, a, b, c, in[13], S12, 0xFD987193L); /* 14 */
- FF ( c, d, a, b, in[14], S13, 0xA679438EL); /* 15 */
- FF ( b, c, d, a, in[15], S14, 0x49B40821L); /* 16 */
-
- /* Round 2 */
-#define S21 5
-#define S22 9
-#define S23 14
-#define S24 20
- GG ( a, b, c, d, in[ 1], S21, 0xF61E2562L); /* 17 */
- GG ( d, a, b, c, in[ 6], S22, 0xC040B340L); /* 18 */
- GG ( c, d, a, b, in[11], S23, 0x265E5A51L); /* 19 */
- GG ( b, c, d, a, in[ 0], S24, 0xE9B6C7AAL); /* 20 */
- GG ( a, b, c, d, in[ 5], S21, 0xD62F105DL); /* 21 */
- GG ( d, a, b, c, in[10], S22, 0x02441453L); /* 22 */
- GG ( c, d, a, b, in[15], S23, 0xD8A1E681L); /* 23 */
- GG ( b, c, d, a, in[ 4], S24, 0xE7D3FBC8L); /* 24 */
- GG ( a, b, c, d, in[ 9], S21, 0x21E1CDE6L); /* 25 */
- GG ( d, a, b, c, in[14], S22, 0xC33707D6L); /* 26 */
- GG ( c, d, a, b, in[ 3], S23, 0xF4D50D87L); /* 27 */
- GG ( b, c, d, a, in[ 8], S24, 0x455A14EDL); /* 28 */
- GG ( a, b, c, d, in[13], S21, 0xA9E3E905L); /* 29 */
- GG ( d, a, b, c, in[ 2], S22, 0xFCEFA3F8L); /* 30 */
- GG ( c, d, a, b, in[ 7], S23, 0x676F02D9L); /* 31 */
- GG ( b, c, d, a, in[12], S24, 0x8D2A4C8AL); /* 32 */
-
- /* Round 3 */
-#define S31 4
-#define S32 11
-#define S33 16
-#define S34 23
- HH ( a, b, c, d, in[ 5], S31, 0xFFFA3942L); /* 33 */
- HH ( d, a, b, c, in[ 8], S32, 0x8771F681L); /* 34 */
- HH ( c, d, a, b, in[11], S33, 0x6D9D6122L); /* 35 */
- HH ( b, c, d, a, in[14], S34, 0xFDE5380CL); /* 36 */
- HH ( a, b, c, d, in[ 1], S31, 0xA4BEEA44L); /* 37 */
- HH ( d, a, b, c, in[ 4], S32, 0x4BDECFA9L); /* 38 */
- HH ( c, d, a, b, in[ 7], S33, 0xF6BB4B60L); /* 39 */
- HH ( b, c, d, a, in[10], S34, 0xBEBFBC70L); /* 40 */
- HH ( a, b, c, d, in[13], S31, 0x289B7EC6L); /* 41 */
- HH ( d, a, b, c, in[ 0], S32, 0xEAA127FAL); /* 42 */
- HH ( c, d, a, b, in[ 3], S33, 0xD4EF3085L); /* 43 */
- HH ( b, c, d, a, in[ 6], S34, 0x04881D05L); /* 44 */
- HH ( a, b, c, d, in[ 9], S31, 0xD9D4D039L); /* 45 */
- HH ( d, a, b, c, in[12], S32, 0xE6DB99E5L); /* 46 */
- HH ( c, d, a, b, in[15], S33, 0x1FA27CF8L); /* 47 */
- HH ( b, c, d, a, in[ 2], S34, 0xC4AC5665L); /* 48 */
-
- /* Round 4 */
-#define S41 6
-#define S42 10
-#define S43 15
-#define S44 21
- II ( a, b, c, d, in[ 0], S41, 0xF4292244L); /* 49 */
- II ( d, a, b, c, in[ 7], S42, 0x432AFF97L); /* 50 */
- II ( c, d, a, b, in[14], S43, 0xAB9423A7L); /* 51 */
- II ( b, c, d, a, in[ 5], S44, 0xFC93A039L); /* 52 */
- II ( a, b, c, d, in[12], S41, 0x655B59C3L); /* 53 */
- II ( d, a, b, c, in[ 3], S42, 0x8F0CCC92L); /* 54 */
- II ( c, d, a, b, in[10], S43, 0xFFEFF47DL); /* 55 */
- II ( b, c, d, a, in[ 1], S44, 0x85845DD1L); /* 56 */
- II ( a, b, c, d, in[ 8], S41, 0x6FA87E4FL); /* 57 */
- II ( d, a, b, c, in[15], S42, 0xFE2CE6E0L); /* 58 */
- II ( c, d, a, b, in[ 6], S43, 0xA3014314L); /* 59 */
- II ( b, c, d, a, in[13], S44, 0x4E0811A1L); /* 60 */
- II ( a, b, c, d, in[ 4], S41, 0xF7537E82L); /* 61 */
- II ( d, a, b, c, in[11], S42, 0xBD3AF235L); /* 62 */
- II ( c, d, a, b, in[ 2], S43, 0x2AD7D2BBL); /* 63 */
- II ( b, c, d, a, in[ 9], S44, 0xEB86D391L); /* 64 */
-
- buf[0] += a;
- buf[1] += b;
- buf[2] += c;
- buf[3] += d;
+ MD5_CONTEXT *hd = (MD5_CONTEXT *) context;
+ return hd->bctx.buf;
}
-
-
-/* end of file */
+static byte asn[18] = /* Object ID is 1.2.840.113549.2.5 */
+ { 0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86,0x48,
+ 0x86, 0xf7, 0x0d, 0x02, 0x05, 0x05, 0x00, 0x04, 0x10 };
+
+static gcry_md_oid_spec_t oid_spec_md5[] =
+ {
+ /* iso.member-body.us.rsadsi.pkcs.pkcs-1.4 (md5WithRSAEncryption) */
+ { "1.2.840.113549.1.1.4" },
+ /* RSADSI digestAlgorithm MD5 */
+ { "1.2.840.113549.2.5" },
+ { NULL },
+ };
+
+gcry_md_spec_t _gcry_digest_spec_md5 =
+ {
+ GCRY_MD_MD5, {0, 1},
+ "MD5", asn, DIM (asn), oid_spec_md5, 16,
+ md5_init, _gcry_md_block_write, md5_final, md5_read,
+ sizeof (MD5_CONTEXT)
+ };