diff -Nru -X /home/michele/svn/programming/vte/dontdiff gnome-terminal/ChangeLog gnome-terminal.skey-fixed/ChangeLog
--- gnome-terminal/ChangeLog	2005-07-05 00:19:18.000000000 +0200
+++ gnome-terminal.skey-fixed/ChangeLog	2005-07-05 00:19:50.000000000 +0200
@@ -1,3 +1,23 @@
+2005-07-05  Michele Baldessari <michele@pupazzo.org>
+
+	* configure.in: Add AC_C_BIGENDIAN check for new md4,md5 routines
+
+	* src/skey/Makefile.am
+	* src/skey/donkey.c: Added a small testing program 
+
+	* src/skey/mhash_md4.h
+	* src/skey/md4.c
+	* src/skey/mhash_md5.h
+	* src/skey/md5.c: Fixed #305216 and replaced non-free md4/5
+	with public domain ones taken from the mhash library. 
+	md4 is LGPL copyrighted by Nikos Mavroyanopoulos, and md5 
+	is written by Colin Plumb and is in the public domain. 
+	Removed md2 in the process since it was segfaulting in the original
+	implementation anyhow and it would require more work to fit it in for
+	little need. Drop me a note if you need it and I'll add support for it.
+
+	* src/skey/md2.c: Removed
+
 2005-05-31  Rodrigo Moya <rodrigo@novell.com>
 
 	* src/gnome-terminal.server: added name attribute.
diff -Nru -X /home/michele/svn/programming/vte/dontdiff gnome-terminal/configure.in gnome-terminal.skey-fixed/configure.in
--- gnome-terminal/configure.in	2005-04-01 02:48:40.000000000 +0200
+++ gnome-terminal.skey-fixed/configure.in	2005-07-04 23:18:52.000000000 +0200
@@ -8,6 +8,8 @@
 AC_SUBST(GETTEXT_PACKAGE)
 AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE")
 
+AC_C_BIGENDIAN
+
 AM_MAINTAINER_MODE
 
 AC_PROG_CC
Binary files gnome-terminal/src/gnome-terminal and gnome-terminal.skey-fixed/src/gnome-terminal differ
Binary files gnome-terminal/src/skey/donkey and gnome-terminal.skey-fixed/src/skey/donkey differ
diff -Nru -X /home/michele/svn/programming/vte/dontdiff gnome-terminal/src/skey/donkey.c gnome-terminal.skey-fixed/src/skey/donkey.c
--- gnome-terminal/src/skey/donkey.c	2002-11-03 22:20:48.000000000 +0100
+++ gnome-terminal.skey-fixed/src/skey/donkey.c	2005-07-04 23:37:39.000000000 +0200
@@ -54,3 +54,23 @@
 	return (strdup (btoe(key)));
 
 }
+
+#ifdef DONKEY_MAIN
+int main(int argc, char *argv[])
+{
+	char *buf;
+	if (argc != 3) {
+		printf("Use %s: seed password\n", argv[0]);
+		return -1;
+	}
+
+
+	buf = skey(MD4, 10, argv[1], argv[2]);
+	printf("MD4 %s\n", buf);
+	free(buf);
+	buf = skey(MD5, 10, argv[1], argv[2]);
+	printf("MD5 %s\n", buf);
+	free(buf);
+	return 0;
+}
+#endif
diff -Nru -X /home/michele/svn/programming/vte/dontdiff gnome-terminal/src/skey/Makefile.am gnome-terminal.skey-fixed/src/skey/Makefile.am
--- gnome-terminal/src/skey/Makefile.am	2002-11-03 22:20:48.000000000 +0100
+++ gnome-terminal.skey-fixed/src/skey/Makefile.am	2005-07-04 23:40:25.000000000 +0200
@@ -10,8 +10,9 @@
 	donkey.c	\
 	md.h		\
 	md.c		\
-	md2.c		\
+	mhash_md4.h	\
 	md4.c		\
+	mhash_md5.h	\
 	md5.c		\
 	skey.c		\
 	skey.h		\
@@ -22,3 +23,20 @@
 libskey_la_SOURCES=$(SKEYFILES)
 
 libskey_la_LDFLAGS= @TERM_LIBS@
+
+noinst_PROGRAMS=donkey
+donkey_CFLAGS = @CFLAGS@ @TERM_CFLAGS@ -DDONKEY_MAIN
+donkey_SOURCES = \
+	donkey.c \
+	donkey.h \
+	btoe.c \
+	config.h \
+	md4.c \
+	md5.c \
+	md.c \
+	md.h \
+	mhash_md4.h \
+	mhash_md5.h \
+	skey.c \
+	skey.h \
+	tailor.h
diff -Nru -X /home/michele/svn/programming/vte/dontdiff gnome-terminal/src/skey/md2.c gnome-terminal.skey-fixed/src/skey/md2.c
--- gnome-terminal/src/skey/md2.c	2002-10-30 21:26:23.000000000 +0100
+++ gnome-terminal.skey-fixed/src/skey/md2.c	1970-01-01 01:00:00.000000000 +0100
@@ -1,206 +0,0 @@
-/*
- * md2.c
- *		 Copyright (C) 1995 Kazuhiko Yamamoto
- *	      Kazuhiko Yamamoto <kazu@is.aist-nara.ac.jp>
- */
-
-#include "config.h"
-#include "md.h"
-
-private void MD2Transform PROTO((UINT1 [16], UINT1 [16], UINT1 [16]));
-
-
-/*
- * Permutation of 0..255 constructed from the digits of pi. It gives a
- * "random" nonlinear byte substitution operation.
- */
-
-private UINT1 PI_SUBST[256] = {
-	41, 46, 67, 201, 162, 216, 124, 1, 61, 54, 84, 161, 236, 240, 6,
-	19, 98, 167, 5, 243, 192, 199, 115, 140, 152, 147, 43, 217, 188,
-	76, 130, 202, 30, 155, 87, 60, 253, 212, 224, 22, 103, 66, 111, 24,
-	138, 23, 229, 18, 190, 78, 196, 214, 218, 158, 222, 73, 160, 251,
-	245, 142, 187, 47, 238, 122, 169, 104, 121, 145, 21, 178, 7, 63,
-	148, 194, 16, 137, 11, 34, 95, 33, 128, 127, 93, 154, 90, 144, 50,
-	39, 53, 62, 204, 231, 191, 247, 151, 3, 255, 25, 48, 179, 72, 165,
-	181, 209, 215, 94, 146, 42, 172, 86, 170, 198, 79, 184, 56, 210,
-	150, 164, 125, 182, 118, 252, 107, 226, 156, 116, 4, 241, 69, 157,
-	112, 89, 100, 113, 135, 32, 134, 91, 207, 101, 230, 45, 168, 2, 27,
-	96, 37, 173, 174, 176, 185, 246, 28, 70, 97, 105, 52, 64, 126, 15,
-	85, 71, 163, 35, 221, 81, 175, 58, 195, 92, 249, 206, 186, 197,
-	234, 38, 44, 83, 13, 110, 133, 40, 132, 9, 211, 223, 205, 244, 65,
-	129, 77, 82, 106, 220, 55, 200, 108, 193, 171, 250, 36, 225, 123,
-	8, 12, 189, 177, 74, 120, 136, 149, 139, 227, 99, 232, 109, 233,
-	203, 213, 254, 59, 0, 29, 57, 242, 239, 183, 14, 102, 88, 208, 228,
-	166, 119, 114, 248, 235, 117, 75, 10, 49, 68, 80, 180, 143, 237,
-	31, 26, 219, 153, 141, 51, 159, 17, 131, 20
-	};
-
-private POINTER PADDING[] = {
-	(POINTER)"",
-	(POINTER)"\001",
-	(POINTER)"\002\002",
-	(POINTER)"\003\003\003",
-	(POINTER)"\004\004\004\004",
-	(POINTER)"\005\005\005\005\005",
-	(POINTER)"\006\006\006\006\006\006",
-	(POINTER)"\007\007\007\007\007\007\007",
-	(POINTER)"\010\010\010\010\010\010\010\010",
-	(POINTER)"\011\011\011\011\011\011\011\011\011",
-	(POINTER)"\012\012\012\012\012\012\012\012\012\012",
-	(POINTER)"\013\013\013\013\013\013\013\013\013\013\013",
-	(POINTER)"\014\014\014\014\014\014\014\014\014\014\014\014",
-	(POINTER)"\015\015\015\015\015\015\015\015\015\015\015\015\015",
-	(POINTER)"\016\016\016\016\016\016\016\016\016\016\016\016\016\016",
-	(POINTER)"\017\017\017\017\017\017\017\017\017\017\017\017\017\017\017",
-	(POINTER)"\020\020\020\020\020\020\020\020\020\020\020\020\020\020\020\020"
-	};
-
-
-/*
- * MD2 initialization. Begins an MD2 operation, writing a new context.
- */
-
-void MD2Init (ptr)
-POINTER ptr;
-{
-	MD2_CTX *context = (MD2_CTX *)ptr;
-	
-	context->count = 0;
-	memset((POINTER)context->state, 0, sizeof (context->state));
-	memset((POINTER)context->checksum, 0, sizeof (context->checksum));
-}
-
-/*
- * MD2 block update operation. Continues an MD2 message-digest
- * operation, processing another message block, and updating the
- * context.
- */
-
-void MD2Update (ptr, input, inputLen)
-POINTER ptr;		/* context */
-UINT1 *input;		/* input block */
-unsigned int inputLen;	/* length of input block */
-{
-	MD2_CTX *context = (MD2_CTX *)ptr;
-	unsigned int i, index, partLen;
-	
-	/* Update number of bytes mod 16 */
-	index = context->count;
-	context->count = (index + inputLen) & 0xf;
-	
-	partLen = 16 - index;
-	
-	/* Transform as many times as possible.
-	 */
-	if (inputLen >= partLen) {
-		memcpy((POINTER)&context->buffer[index],
-		       (POINTER)input, partLen);
-		MD2Transform(context->state,
-			     context->checksum, context->buffer);
-		for (i = partLen; i + 15 < inputLen; i += 16)
-			MD2Transform(context->state,
-				     context->checksum, &input[i]);
-		index = 0;
-	} else
-		i = 0;
-	
-	/* Buffer remaining input */
-	memcpy((POINTER)&context->buffer[index],
-	       (POINTER)&input[i], inputLen - i);
-}
-
-/*
- * MD2 finalization. Ends an MD2 message-digest operation, writing the
- * message digest and zeroizing the context.
- */
-
-void MD2Final (digest, ptr)
-UINT1 digest[16];	/* message digest */
-POINTER ptr;		/* context */
-{
-	MD2_CTX *context = (MD2_CTX *)ptr;
-	unsigned int index, padLen;
-	
-	/*
-	 * Pad out to multiple of 16.
-	 */
-	index = context->count;
-	padLen = 16 - index;
-	MD2Update((POINTER)context, PADDING[padLen], padLen);
-	
-	/* Extend with checksum */
-	MD2Update((POINTER)context, context->checksum, 16);
-	
-	/* Store state in digest */
-	memcpy((POINTER)digest, (POINTER)context->state, 16);
-	
-	/*
-	 * Zeroize sensitive information.
-	 */
-	memset((POINTER)context, 0, sizeof (*context));
-}
-
-
-/*
- * MD2 basic transformation. Transforms state and updates checksum
- * based on block.
- */
-
-private void MD2Transform (state, checksum, block)
-UINT1 state[16];
-UINT1 checksum[16];
-UINT1 block[16];
-{
-	UINT4 i, j, t;
-	UINT1 x[48];
-	
-	/*
-	 * Form encryption block from state, block, state ^ block.
-	 */
-	memcpy((POINTER)x, (POINTER)state, 16);
-	memcpy((POINTER)x+16, (POINTER)block, 16);
-	for (i = 0; i < 16; i++)
-		x[i+32] = state[i] ^ block[i];
-	
-	/*
-	 * Encrypt block (18 rounds).
-	 */
-	t = 0;
-	for(i = 0; i < 18; i++) {
-		for (j = 0; j < 48; j++)
-			t = x[j] ^= PI_SUBST[t];
-		t = (t + i) & 0xff;
-	}
-	
-	/* Save new state */
-	memcpy ((POINTER)state, (POINTER)x, 16);
-	
-	/* Update checksum.
-	 */
-	t = checksum[15];
-	for (i = 0; i < 16; i++)
-		t = checksum[i] ^= PI_SUBST[block[i] ^ t];
-	
-	/* Zeroize sensitive information.
-	 */
-	memset ((POINTER)x, 0, sizeof (x));
-}
-
-/* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All
- * rights reserved.
- *
- * License to copy and use this software is granted for
- * non-commercial Internet Privacy-Enhanced Mail provided that it is
- * identified as the "RSA Data Security, Inc. MD2 Message Digest
- * Algorithm" in all material mentioning or referencing this software
- * or this function.
- *
- * 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.
- */
diff -Nru -X /home/michele/svn/programming/vte/dontdiff gnome-terminal/src/skey/md4.c gnome-terminal.skey-fixed/src/skey/md4.c
--- gnome-terminal/src/skey/md4.c	2002-10-30 21:26:23.000000000 +0100
+++ gnome-terminal.skey-fixed/src/skey/md4.c	2005-07-04 23:18:52.000000000 +0200
@@ -1,248 +1,255 @@
 /*
- * md4.c
- *		 Copyright (C) 1995 Kazuhiko Yamamoto
- *	      Kazuhiko Yamamoto <kazu@is.aist-nara.ac.jp>
+ *    Copyright (C) 2001 Nikos Mavroyanopoulos
+ *
+ *    This library is free software; you can redistribute it and/or modify it 
+ *    under the terms of the GNU Library General Public License as published 
+ *    by the Free Software Foundation; either version 2 of the License, or 
+ *    (at your option) any later version.
+ *
+ *    This library 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
+ *    Library General Public License for more details.
+ *
+ *    You should have received a copy of the GNU Library General Public
+ *    License along with this library; if not, write to the
+ *    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ *    Boston, MA 02111-1307, USA.
  */
 
-#include "config.h"
-#include "md.h"
-
-private void MD4Transform PROTO((UINT4 [4], UINT1 [64]));
+/* 
+ * The algorithm is due to Ron Rivest.  This code is based on code
+ * written by Colin Plumb in 1993.
+ */
+ 
 
 /*
- * Constants for MD4Transform routine.
+ * This code implements the MD4 message-digest algorithm.
  */
-#define S11 3
-#define S12 7
-#define S13 11
-#define S14 19
-#define S21 3
-#define S22 5
-#define S23 9
-#define S24 13
-#define S31 3
-#define S32 9
-#define S33 11
-#define S34 15
 
-private UINT1 PADDING[64] = {
-	0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-	};
+#include <string.h>
+#include "mhash_md4.h"
+
+#ifndef WORDS_BIGENDIAN
+#define byteReverse(buf, len)	/* Nothing */
+#else
+static void byteReverse(unsigned char *buf, unsigned longs);
+
 
 /*
- * F, G and H are basic MD4 functions.
+ * Note: this code is harmless on little-endian machines.
  */
-#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
-#define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
-#define H(x, y, z) ((x) ^ (y) ^ (z))
+static void byteReverse(unsigned char *buf, unsigned longs)
+{
+	guint32 t;
+	do {
+		t = (guint32) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
+		    ((unsigned) buf[1] << 8 | buf[0]);
+		*(guint32 *) buf = t;
+		buf += 4;
+	} while (--longs);
+}
+#endif
+
+#define rotl32(x,n)   (((x) << ((guint32)(n))) | ((x) >> (32 - (guint32)(n))))
 
 /*
- * ROTATE_LEFT rotates x left n bits.
+ * Start MD4 accumulation.  Set bit count to 0 and buffer to mysterious
+ * initialization constants.
  */
-#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
-
-/* FF, GG and HH are transformations for rounds 1, 2 and 3 */
-/* Rotation is separate from addition to prevent recomputation */
+void MD4Init(struct MD4Context *ctx)
+{
+	ctx->buf[0] = 0x67452301;
+	ctx->buf[1] = 0xefcdab89;
+	ctx->buf[2] = 0x98badcfe;
+	ctx->buf[3] = 0x10325476;
 
-#define FF(a, b, c, d, x, s) { \
-	(a) += F ((b), (c), (d)) + (x); \
-	(a) = ROTATE_LEFT ((a), (s)); \
-}
-#define GG(a, b, c, d, x, s) { \
-	(a) += G ((b), (c), (d)) + (x) + (UINT4)0x5a827999; \
-	(a) = ROTATE_LEFT ((a), (s)); \
-}
-#define HH(a, b, c, d, x, s) { \
-	(a) += H ((b), (c), (d)) + (x) + (UINT4)0x6ed9eba1; \
-	(a) = ROTATE_LEFT ((a), (s)); \
+	ctx->bits[0] = 0;
+	ctx->bits[1] = 0;
 }
 
 /*
- * MD4 initialization. Begins an MD4 operation, writing a new context.
+ * Update context to reflect the concatenation of another buffer full
+ * of bytes.
  */
-void MD4Init (ptr)
-POINTER ptr;
+void MD4Update(struct MD4Context *ctx, unsigned char const *buf,
+	       unsigned len)
 {
-	MD4_CTX *context = (MD4_CTX *)ptr;
-	
-	context->count[0] = context->count[1] = 0;
-	
-	/* Load magic initialization constants.
-	 */
-	context->state[0] = 0x67452301;
-	context->state[1] = 0xefcdab89;
-	context->state[2] = 0x98badcfe;
-	context->state[3] = 0x10325476;
+	register guint32 t;
+
+	/* Update bitcount */
+
+	t = ctx->bits[0];
+	if ((ctx->bits[0] = t + ((guint32) len << 3)) < 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) {
+		unsigned char *p = (unsigned char *) ctx->in + t;
+
+		t = 64 - t;
+		if (len < t) {
+			memcpy(p, buf, len);
+			return;
+		}
+		memcpy(p, buf, t);
+		byteReverse(ctx->in, 16);
+		MD4Transform(ctx->buf, (guint32 *) ctx->in);
+		buf += t;
+		len -= t;
+	}
+	/* Process data in 64-byte chunks */
+
+	while (len >= 64) {
+		memcpy(ctx->in, buf, 64);
+		byteReverse(ctx->in, 16);
+		MD4Transform(ctx->buf, (guint32 *) ctx->in);
+		buf += 64;
+		len -= 64;
+	}
+
+	/* Handle any remaining bytes of data. */
+
+	memcpy(ctx->in, buf, len);
 }
 
 /*
- * MD4 block update operation. Continues an MD4 message-digest
- * operation, processing another message block, and updating the
- * context.
- */
-void MD4Update (ptr, input, inputLen)
-POINTER ptr; 
-POINTER input;		/* input block */
-unsigned int inputLen;	/* length of input block */
+ * Final wrapup - pad to 64-byte boundary with the bit pattern 
+ * 1 0* (64-bit count of bits processed, MSB-first)
+ */
+void MD4Final(struct MD4Context *ctx, unsigned char* digest)
 {
-	MD4_CTX *context = (MD4_CTX *)ptr;
-	unsigned int i, index, partLen;
-	
+	unsigned int count;
+	unsigned char *p;
+
 	/* Compute number of bytes mod 64 */
-	index = (unsigned int)((context->count[0] >> 3) & 0x3F);
-	/* Update number of bits */
-	if ((context->count[0] += ((UINT4)inputLen << 3))
-	    < ((UINT4)inputLen << 3))
-		context->count[1]++;
-	context->count[1] += ((UINT4)inputLen >> 29);
-	
-	partLen = 64 - index;
-	
-	/* Transform as many times as possible.
-	 */
-	if (inputLen >= partLen) {
-		memcpy((POINTER)&context->buffer[index],
-		       (POINTER)input, partLen);
-		MD4Transform (context->state, context->buffer);
-		
-		for (i = partLen; i + 63 < inputLen; i += 64)
-			MD4Transform (context->state, &input[i]);
-		
-		index = 0;
+	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);
+		byteReverse(ctx->in, 16);
+		MD4Transform(ctx->buf, (guint32 *) 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);
 	}
-	else
-		i = 0;
+	byteReverse(ctx->in, 14);
+
+	/* Append length in bits and transform */
+	((guint32 *) ctx->in)[14] = ctx->bits[0];
+	((guint32 *) ctx->in)[15] = ctx->bits[1];
+
+	MD4Transform(ctx->buf, (guint32 *) ctx->in);
+	byteReverse((unsigned char *) ctx->buf, 4);
 	
-	/* Buffer remaining input */
-	memcpy((POINTER)&context->buffer[index],
-	       (POINTER)&input[i], inputLen-i);
+	if (digest!=NULL)
+		memcpy(digest, ctx->buf, 16);
+	memset(ctx, 0, sizeof(ctx));	/* In case it's sensitive */
 }
 
+/* The three core functions */
+
+#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
+#define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
+#define H(x, y, z) ((x) ^ (y) ^ (z))
+
+#define FF(a, b, c, d, x, s) { \
+    (a) += F ((b), (c), (d)) + (x); \
+    (a) = rotl32 ((a), (s)); \
+  }
+#define GG(a, b, c, d, x, s) { \
+    (a) += G ((b), (c), (d)) + (x) + (guint32)0x5a827999; \
+    (a) = rotl32 ((a), (s)); \
+  }
+#define HH(a, b, c, d, x, s) { \
+    (a) += H ((b), (c), (d)) + (x) + (guint32)0x6ed9eba1; \
+    (a) = rotl32 ((a), (s)); \
+  }
+
+
 /*
- * MD4 finalization. Ends an MD4 message-digest operation, writing the
- * the message digest and zeroizing the context.
+ * The core of the MD4 algorithm
  */
-void MD4Final (digest, ptr)
-UINT1 digest[16];                         /* message digest */
-POINTER ptr;                                      /* context */
+void MD4Transform(guint32 buf[4], guint32 const in[16])
 {
-	MD4_CTX *context = (MD4_CTX *)ptr;
-	UINT1 bits[8];
-	UINT4 index, padLen;
-	
-	/* Save number of bits */
-	MDEncode(bits, context->count, 8);
-	
-	/* Pad out to 56 mod 64.
-	 */
-	index = (UINT4)((context->count[0] >> 3) & 0x3f);
-	padLen = (index < 56) ? (56 - index) : (120 - index);
-	MD4Update((POINTER)context, PADDING, padLen);
-	
-	/* Append length (before padding) */
-	MD4Update((POINTER)context, bits, 8);
-	/* Store state in digest */
-	MDEncode(digest, context->state, 16);
-	
-	/* Zeroize sensitive information.
-	 */
-	memset((POINTER)context, 0, sizeof (*context));
-}
+	register guint32 a, b, c, d;
 
-/* MD4 basic transformation. Transforms state based on block.
- */
-private void MD4Transform (state, block)
-UINT4 state[4];
-UINT1 block[64];
-{
-	UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
-	
-	MDDecode(x, block, 64);
-	
-	/* Round 1 */
-	FF (a, b, c, d, x[ 0], S11); /* 1 */
-	FF (d, a, b, c, x[ 1], S12); /* 2 */
-	FF (c, d, a, b, x[ 2], S13); /* 3 */
-	FF (b, c, d, a, x[ 3], S14); /* 4 */
-	FF (a, b, c, d, x[ 4], S11); /* 5 */
-	FF (d, a, b, c, x[ 5], S12); /* 6 */
-	FF (c, d, a, b, x[ 6], S13); /* 7 */
-	FF (b, c, d, a, x[ 7], S14); /* 8 */
-	FF (a, b, c, d, x[ 8], S11); /* 9 */
-	FF (d, a, b, c, x[ 9], S12); /* 10 */
-	FF (c, d, a, b, x[10], S13); /* 11 */
-	FF (b, c, d, a, x[11], S14); /* 12 */
-	FF (a, b, c, d, x[12], S11); /* 13 */
-	FF (d, a, b, c, x[13], S12); /* 14 */
-	FF (c, d, a, b, x[14], S13); /* 15 */
-	FF (b, c, d, a, x[15], S14); /* 16 */
-	
-	/* Round 2 */
-	GG (a, b, c, d, x[ 0], S21); /* 17 */
-	GG (d, a, b, c, x[ 4], S22); /* 18 */
-	GG (c, d, a, b, x[ 8], S23); /* 19 */
-	GG (b, c, d, a, x[12], S24); /* 20 */
-	GG (a, b, c, d, x[ 1], S21); /* 21 */
-	GG (d, a, b, c, x[ 5], S22); /* 22 */
-	GG (c, d, a, b, x[ 9], S23); /* 23 */
-	GG (b, c, d, a, x[13], S24); /* 24 */
-	GG (a, b, c, d, x[ 2], S21); /* 25 */
-	GG (d, a, b, c, x[ 6], S22); /* 26 */
-	GG (c, d, a, b, x[10], S23); /* 27 */
-	GG (b, c, d, a, x[14], S24); /* 28 */
-	GG (a, b, c, d, x[ 3], S21); /* 29 */
-	GG (d, a, b, c, x[ 7], S22); /* 30 */
-	GG (c, d, a, b, x[11], S23); /* 31 */
-	GG (b, c, d, a, x[15], S24); /* 32 */
-	
-	/* Round 3 */
-	HH (a, b, c, d, x[ 0], S31); /* 33 */
-	HH (d, a, b, c, x[ 8], S32); /* 34 */
-	HH (c, d, a, b, x[ 4], S33); /* 35 */
-	HH (b, c, d, a, x[12], S34); /* 36 */
-	HH (a, b, c, d, x[ 2], S31); /* 37 */
-	HH (d, a, b, c, x[10], S32); /* 38 */
-	HH (c, d, a, b, x[ 6], S33); /* 39 */
-	HH (b, c, d, a, x[14], S34); /* 40 */
-	HH (a, b, c, d, x[ 1], S31); /* 41 */
-	HH (d, a, b, c, x[ 9], S32); /* 42 */
-	HH (c, d, a, b, x[ 5], S33); /* 43 */
-	HH (b, c, d, a, x[13], S34); /* 44 */
-	HH (a, b, c, d, x[ 3], S31); /* 45 */
-	HH (d, a, b, c, x[11], S32); /* 46 */
-	HH (c, d, a, b, x[ 7], S33); /* 47 */
-	HH (b, c, d, a, x[15], S34); /* 48 */
-	
-	state[0] += a;
-	state[1] += b;
-	state[2] += c;
-	state[3] += d;
-	
-	/* Zeroize sensitive information.
-	 */
-	memset((POINTER)x, 0, sizeof (x));
+	a = buf[0];
+	b = buf[1];
+	c = buf[2];
+	d = buf[3];
+
+	FF(a, b, c, d, in[0], 3);	/* 1 */
+	FF(d, a, b, c, in[1], 7);	/* 2 */
+	FF(c, d, a, b, in[2], 11);	/* 3 */
+	FF(b, c, d, a, in[3], 19);	/* 4 */
+	FF(a, b, c, d, in[4], 3);	/* 5 */
+	FF(d, a, b, c, in[5], 7);	/* 6 */
+	FF(c, d, a, b, in[6], 11);	/* 7 */
+	FF(b, c, d, a, in[7], 19);	/* 8 */
+	FF(a, b, c, d, in[8], 3);	/* 9 */
+	FF(d, a, b, c, in[9], 7);	/* 10 */
+	FF(c, d, a, b, in[10], 11);	/* 11 */
+	FF(b, c, d, a, in[11], 19);	/* 12 */
+	FF(a, b, c, d, in[12], 3);	/* 13 */
+	FF(d, a, b, c, in[13], 7);	/* 14 */
+	FF(c, d, a, b, in[14], 11);	/* 15 */
+	FF(b, c, d, a, in[15], 19);	/* 16 */
+
+	GG(a, b, c, d, in[0], 3);	/* 17 */
+	GG(d, a, b, c, in[4], 5);	/* 18 */
+	GG(c, d, a, b, in[8], 9);	/* 19 */
+	GG(b, c, d, a, in[12], 13);	/* 20 */
+	GG(a, b, c, d, in[1], 3);	/* 21 */
+	GG(d, a, b, c, in[5], 5);	/* 22 */
+	GG(c, d, a, b, in[9], 9);	/* 23 */
+	GG(b, c, d, a, in[13], 13);	/* 24 */
+	GG(a, b, c, d, in[2], 3);	/* 25 */
+	GG(d, a, b, c, in[6], 5);	/* 26 */
+	GG(c, d, a, b, in[10], 9);	/* 27 */
+	GG(b, c, d, a, in[14], 13);	/* 28 */
+	GG(a, b, c, d, in[3], 3);	/* 29 */
+	GG(d, a, b, c, in[7], 5);	/* 30 */
+	GG(c, d, a, b, in[11], 9);	/* 31 */
+	GG(b, c, d, a, in[15], 13);	/* 32 */
+
+	HH(a, b, c, d, in[0], 3);	/* 33 */
+	HH(d, a, b, c, in[8], 9);	/* 34 */
+	HH(c, d, a, b, in[4], 11);	/* 35 */
+	HH(b, c, d, a, in[12], 15);	/* 36 */
+	HH(a, b, c, d, in[2], 3);	/* 37 */
+	HH(d, a, b, c, in[10], 9);	/* 38 */
+	HH(c, d, a, b, in[6], 11);	/* 39 */
+	HH(b, c, d, a, in[14], 15);	/* 40 */
+	HH(a, b, c, d, in[1], 3);	/* 41 */
+	HH(d, a, b, c, in[9], 9);	/* 42 */
+	HH(c, d, a, b, in[5], 11);	/* 43 */
+	HH(b, c, d, a, in[13], 15);	/* 44 */
+	HH(a, b, c, d, in[3], 3);	/* 45 */
+	HH(d, a, b, c, in[11], 9);	/* 46 */
+	HH(c, d, a, b, in[7], 11);	/* 47 */
+	HH(b, c, d, a, in[15], 15);	/* 48 */
+
+
+	buf[0] += a;
+	buf[1] += b;
+	buf[2] += c;
+	buf[3] += d;
 }
-
-/*
- * Copyright (C) 1990-2, 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. MD4 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. MD4 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.
- */
diff -Nru -X /home/michele/svn/programming/vte/dontdiff gnome-terminal/src/skey/md5.c gnome-terminal.skey-fixed/src/skey/md5.c
--- gnome-terminal/src/skey/md5.c	2002-10-30 21:26:23.000000000 +0100
+++ gnome-terminal.skey-fixed/src/skey/md5.c	2005-07-04 23:18:52.000000000 +0200
@@ -1,275 +1,249 @@
 /*
- * md5.c
- *		 Copyright (C) 1995 Kazuhiko Yamamoto
- *	      Kazuhiko Yamamoto <kazu@is.aist-nara.ac.jp>
+ * 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 "md.h"
+#include <string.h>
+#include "mhash_md5.h"
 
-private void MD5Transform PROTO((UINT4 [4], unsigned char [64]));
+#ifndef WORDS_BIGENDIAN
+#define byteReverse(buf, len)	/* Nothing */
+#else
+static void byteReverse(unsigned char *buf, unsigned longs);
 
 /*
- * Constants for MD5Transform routine.
+ * Note: this code is harmless on little-endian machines.
  */
-#define S11 7
-#define S12 12
-#define S13 17
-#define S14 22
-#define S21 5
-#define S22 9
-#define S23 14
-#define S24 20
-#define S31 4
-#define S32 11
-#define S33 16
-#define S34 23
-#define S41 6
-#define S42 10
-#define S43 15
-#define S44 21
-
-private UINT1 PADDING[64] = {
-	0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-	};
-
-/*
- * 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)))
+static void byteReverse(unsigned char *buf, unsigned longs)
+{
+    guint32 t;
+    do {
+	t = (guint32) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
+	    ((unsigned) buf[1] << 8 | buf[0]);
+	*(guint32 *) buf = t;
+	buf += 4;
+    } while (--longs);
+}
+#endif
 
 /*
- * ROTATE_LEFT rotates x left n bits.
+ * Start MD5 accumulation.  Set bit count to 0 and buffer to mysterious
+ * initialization constants.
  */
-#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
+void MD5Init(struct MD5Context *ctx)
+{
+    ctx->buf[0] = 0x67452301;
+    ctx->buf[1] = 0xefcdab89;
+    ctx->buf[2] = 0x98badcfe;
+    ctx->buf[3] = 0x10325476;
 
-/*
- * 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) + (UINT4)(ac); \
-	(a) = ROTATE_LEFT ((a), (s)); \
-	(a) += (b); \
-}
-#define GG(a, b, c, d, x, s, ac) { \
-	(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
-	(a) = ROTATE_LEFT ((a), (s)); \
-	(a) += (b); \
-}
-#define HH(a, b, c, d, x, s, ac) { \
-	(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
-	(a) = ROTATE_LEFT ((a), (s)); \
-	(a) += (b); \
-}
-#define II(a, b, c, d, x, s, ac) { \
-	(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
-	(a) = ROTATE_LEFT ((a), (s)); \
-	(a) += (b); \
+    ctx->bits[0] = 0;
+    ctx->bits[1] = 0;
 }
 
 /*
- * MD5 initialization. Begins an MD5 operation, writing a new context.
+ * Update context to reflect the concatenation of another buffer full
+ * of bytes.
  */
-void MD5Init (ptr)
-POINTER ptr;
+void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
 {
-	MD5_CTX *context = (MD5_CTX *) ptr;
+    register guint32 t;
 
-	context->count[0] = context->count[1] = 0;
-	/* Load magic initialization constants. */
-	context->state[0] = 0x67452301;
-	context->state[1] = 0xefcdab89;
-	context->state[2] = 0x98badcfe;
-	context->state[3] = 0x10325476;
-}
+    /* Update bitcount */
 
-/* MD5 block update operation. Continues an MD5 message-digest
-  operation, processing another message block, and updating the
-  context.
- */
-void MD5Update (ptr, input, inputLen)
-POINTER ptr;
-POINTER input;		/* input block */
-unsigned int inputLen;	/* length of input block */
-{
-	MD5_CTX *context = (MD5_CTX *) ptr;
-	UINT4 index;
-	unsigned int i, partLen;
-
-	/* Compute number of bytes mod 64 */
-	index = (UINT4)((context->count[0] >> 3) & 0x3F);
-
-	/* Update number of bits */
-	if ((context->count[0] += ((UINT4)inputLen << 3))
-	    < ((UINT4)inputLen << 3))
-		context->count[1]++;
-	context->count[1] += ((UINT4)inputLen >> 29);
-
-	partLen = 64 - index;
-
-	/* Transform as many times as possible. */
-	if (inputLen >= partLen) {
-		memcpy((POINTER)&context->buffer[index],
-		       (POINTER)input, partLen);
-		MD5Transform(context->state, context->buffer);
+    t = ctx->bits[0];
+    if ((ctx->bits[0] = t + ((guint32) len << 3)) < 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 */
 
-		for (i = partLen; i + 63 < inputLen; i += 64)
-			MD5Transform (context->state, &input[i]);
+    if (t) {
+	unsigned char *p = (unsigned char *) ctx->in + t;
 
-		index = 0;
+	t = 64 - t;
+	if (len < t) {
+	    memcpy(p, buf, len);
+	    return;
 	}
-	else
-		i = 0;
+	memcpy(p, buf, t);
+	byteReverse(ctx->in, 16);
+	MD5Transform(ctx->buf, (guint32 *) ctx->in);
+	buf += t;
+	len -= t;
+    }
+    /* Process data in 64-byte chunks */
 
-	/* Buffer remaining input */
-	memcpy((POINTER)&context->buffer[index],
-	       (POINTER)&input[i], inputLen-i);
-}
+    while (len >= 64) {
+	memcpy(ctx->in, buf, 64);
+	byteReverse(ctx->in, 16);
+	MD5Transform(ctx->buf, (guint32 *) ctx->in);
+	buf += 64;
+	len -= 64;
+    }
 
-/* MD5 finalization. Ends an MD5 message-digest operation, writing the
-  the message digest and zeroizing the context.
- */
-void MD5Final (digest, ptr)
-UINT1 digest[16];                         /* message digest */
-POINTER ptr;
-{
-	MD5_CTX *context = (MD5_CTX *)ptr;
-	UINT1 bits[8];
-	UINT4 index, padLen;
-
-	/* Save number of bits */
-	MDEncode(bits, context->count, 8);
-
-	/* Pad out to 56 mod 64. */
-	index = (UINT4)((context->count[0] >> 3) & 0x3f);
-	padLen = (index < 56) ? (56 - index) : (120 - index);
-	MD5Update((POINTER)context, PADDING, padLen);
-
-	/* Append length (before padding) */
-	MD5Update((POINTER)context, bits, 8);
-	/* Store state in digest */
-	MDEncode(digest, context->state, 16);
+    /* Handle any remaining bytes of data. */
 
-	/* Zeroize sensitive information. */
-	memset((POINTER)context, 0, sizeof (*context));
+    memcpy(ctx->in, buf, len);
 }
 
-/* MD5 basic transformation. Transforms state based on block.
+/*
+ * Final wrapup - pad to 64-byte boundary with the bit pattern 
+ * 1 0* (64-bit count of bits processed, MSB-first)
  */
-private void MD5Transform (state, block)
-UINT4 state[4];
-UINT1 block[64];
+void MD5Final(struct MD5Context *ctx, unsigned char* digest)
 {
-	UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
-	
-	MDDecode(x, block, 64);
-	
-	/* Round 1 */
-	FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
-	FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
-	FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
-	FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
-	FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
-	FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
-	FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
-	FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
-	FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
-	FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
-	FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
-	FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
-	FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
-	FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
-	FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
-	FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
-	
-	/* Round 2 */
-	GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
-	GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
-	GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
-	GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
-	GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
-	GG (d, a, b, c, x[10], S22,  0x2441453); /* 22 */
-	GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
-	GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
-	GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
-	GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
-	GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
-	GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
-	GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
-	GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
-	GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
-	GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
-	
-	/* Round 3 */
-	HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
-	HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
-	HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
-	HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
-	HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
-	HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
-	HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
-	HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
-	HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
-	HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
-	HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
-	HH (b, c, d, a, x[ 6], S34,  0x4881d05); /* 44 */
-	HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
-	HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
-	HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
-	HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
-	
-	/* Round 4 */
-	II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
-	II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
-	II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
-	II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
-	II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
-	II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
-	II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
-	II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
-	II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
-	II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
-	II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
-	II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
-	II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
-	II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
-	II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
-	II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
-	
-	state[0] += a;
-	state[1] += b;
-	state[2] += c;
-	state[3] += d;
-	
-	/* Zeroize sensitive information. */
-	memset((POINTER)x, 0, sizeof (x));
-}
+    unsigned int count;
+    unsigned char *p;
 
-/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. 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.
+    /* 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);
+	byteReverse(ctx->in, 16);
+	MD5Transform(ctx->buf, (guint32 *) 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);
+    }
+    byteReverse(ctx->in, 14);
+
+    /* Append length in bits and transform */
+    ((guint32 *) ctx->in)[14] = ctx->bits[0];
+    ((guint32 *) ctx->in)[15] = ctx->bits[1];
+
+    MD5Transform(ctx->buf, (guint32 *) ctx->in);
+    byteReverse((unsigned char *) ctx->buf, 4);
+    
+    if (digest!=NULL)
+	    memcpy(digest, ctx->buf, 16);
+    memset(ctx, 0, sizeof(ctx));	/* In case it's sensitive */
+}
+
+/* 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 = w<<s | w>>(32-s),  w += 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.
  */
+void MD5Transform(guint32 buf[4], guint32 const in[16])
+{
+    register guint32 a, b, c, d;
 
+    a = buf[0];
+    b = buf[1];
+    c = buf[2];
+    d = buf[3];
+
+    MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
+    MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
+    MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
+    MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
+    MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
+    MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
+    MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
+    MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
+    MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
+    MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
+    MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
+    MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
+    MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
+    MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
+    MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
+    MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
+
+    MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
+    MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
+    MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
+    MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
+    MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
+    MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
+    MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
+    MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
+    MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
+    MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
+    MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
+    MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
+    MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
+    MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
+    MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
+    MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
+
+    MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
+    MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
+    MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
+    MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
+    MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
+    MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
+    MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
+    MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
+    MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
+    MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
+    MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
+    MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
+    MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
+    MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
+    MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
+    MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
+
+    MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
+    MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
+    MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
+    MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
+    MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
+    MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
+    MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
+    MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
+    MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
+    MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
+    MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
+    MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
+    MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
+    MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
+    MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
+    MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
+
+    buf[0] += a;
+    buf[1] += b;
+    buf[2] += c;
+    buf[3] += d;
+}
diff -Nru -X /home/michele/svn/programming/vte/dontdiff gnome-terminal/src/skey/md.c gnome-terminal.skey-fixed/src/skey/md.c
--- gnome-terminal/src/skey/md.c	2002-10-30 21:26:23.000000000 +0100
+++ gnome-terminal.skey-fixed/src/skey/md.c	2005-07-04 23:18:52.000000000 +0200
@@ -8,7 +8,6 @@
 #include "md.h"
 
 struct mdsw mdsw[] = {
-    {MD2Init, MD2Update, MD2Final},
     {MD4Init, MD4Update, MD4Final},
     {MD5Init, MD5Update, MD5Final},
 };
diff -Nru -X /home/michele/svn/programming/vte/dontdiff gnome-terminal/src/skey/md.h gnome-terminal.skey-fixed/src/skey/md.h
--- gnome-terminal/src/skey/md.h	2002-11-03 22:20:48.000000000 +0100
+++ gnome-terminal.skey-fixed/src/skey/md.h	2005-07-05 00:07:24.000000000 +0200
@@ -5,34 +5,23 @@
  */
 
 #include "config.h"
-#define MD2 0
-#define MD4 1
-#define MD5 2
+
+#include "mhash_md4.h"
+#include "mhash_md5.h"
+
+#define MD4 0 
+#define MD5 1
 /* see mdsw in md.c */
 
 extern int MD;
 
 /*
- * MD
+ * MD4_CTX and MD5_CTX are the exact same
  */
 
-typedef struct {
-	UINT1 state[16];    /* state */
-	UINT1 checksum[16]; /* checksum */
-	unsigned int count; /* number of bytes, modulo 16 */
-	UINT1 buffer[16];   /* input buffer */
-} MD2_CTX;
-
-typedef struct {
-	UINT4 state[4];		/* state (ABCD) */
-	UINT4 count[2];		/* number of bits, modulo 2^64 (lsb first) */
-	UINT1 buffer[64];	/* input buffer */
-} MD4_CTX;
-
 #define MD5_CTX MD4_CTX
 
 typedef union {
-	MD2_CTX md2;
 	MD4_CTX md4;
 } MD_CTX;
 
@@ -44,30 +33,6 @@
 
 
 /*
- * MD2
- */
-
-void MD2Init   PROTO((POINTER));
-void MD2Update PROTO((POINTER, UINT1 *, unsigned int));
-void MD2Final  PROTO((UINT1 [16], POINTER));
-
-/*
- * MD4
- */
-
-void MD4Init   PROTO((POINTER));
-void MD4Update PROTO((POINTER, UINT1 *, unsigned int));
-void MD4Final  PROTO((UINT1 [16], POINTER));
-
-/*
- * MD5
- */
-
-void MD5Init   PROTO((POINTER));
-void MD5Update PROTO((POINTER, UINT1 *, unsigned int));
-void MD5Final  PROTO((UINT1 [16], POINTER));
-
-/*
  * MD Switch
  */
 
diff -Nru -X /home/michele/svn/programming/vte/dontdiff gnome-terminal/src/skey/mhash_md4.h gnome-terminal.skey-fixed/src/skey/mhash_md4.h
--- gnome-terminal/src/skey/mhash_md4.h	1970-01-01 01:00:00.000000000 +0100
+++ gnome-terminal.skey-fixed/src/skey/mhash_md4.h	2005-07-04 23:18:52.000000000 +0200
@@ -0,0 +1,20 @@
+#ifndef MD4_H
+#define MD4_H
+
+#include <glib.h>
+ 
+struct MD4Context {
+	guint32 buf[4];
+	guint32 bits[2];
+	unsigned char in[64];
+};
+
+void MD4Init(struct MD4Context *context);
+void MD4Update(struct MD4Context *context, unsigned char const *buf,
+	       unsigned len);
+void MD4Final( struct MD4Context *context, unsigned char *digest);
+void MD4Transform(guint32 buf[4], guint32 const in[16]);
+
+typedef struct MD4Context MD4_CTX;
+
+#endif /* !MD4_H */
diff -Nru -X /home/michele/svn/programming/vte/dontdiff gnome-terminal/src/skey/mhash_md5.h gnome-terminal.skey-fixed/src/skey/mhash_md5.h
--- gnome-terminal/src/skey/mhash_md5.h	1970-01-01 01:00:00.000000000 +0100
+++ gnome-terminal.skey-fixed/src/skey/mhash_md5.h	2005-07-04 23:18:52.000000000 +0200
@@ -0,0 +1,23 @@
+#ifndef MD5_H
+#define MD5_H
+
+#include <glib.h>
+
+struct MD5Context {
+	guint32 buf[4];
+	guint32 bits[2];
+	unsigned char in[64];
+};
+
+void MD5Init(struct MD5Context *context);
+void MD5Update(struct MD5Context *context, unsigned char const *buf,
+	       unsigned len);
+void MD5Final(struct MD5Context *context, unsigned char *digest);
+void MD5Transform(guint32 buf[4], guint32 const in[16]);
+
+/*
+ * This is needed to make RSAREF happy on some MS-DOS compilers.
+ */
+typedef struct MD5Context MD5_CTX;
+
+#endif /* !MD5_H */
diff -Nru -X /home/michele/svn/programming/vte/dontdiff gnome-terminal/src/skey/skey.h gnome-terminal.skey-fixed/src/skey/skey.h
--- gnome-terminal/src/skey/skey.h	2002-10-30 21:26:23.000000000 +0100
+++ gnome-terminal.skey-fixed/src/skey/skey.h	2005-07-04 23:45:09.000000000 +0200
@@ -1,9 +1,8 @@
 #ifndef __SKEY_H__
 #define __SKEY_H__
 
-#define MD2 0
-#define MD4 1
-#define MD5 2
+#define MD4 0
+#define MD5 1
 
 char *skey (int         md,
 	    int         seq,
