diff -X /home/michele/svn/programming/vte/dontdiff -urN gnome-terminal/ChangeLog gnome-terminal.skeyfixed/ChangeLog
--- gnome-terminal/ChangeLog	2005-07-04 14:35:51.000000000 +0200
+++ gnome-terminal.skeyfixed/ChangeLog	2005-07-15 17:01:09.000000000 +0200
@@ -1,3 +1,20 @@
+2005-07-12  Michele Baldessari  <michele@pupazzo.org>
+
+	* configure.in: Added AC_C_BIGENDIAN check
+	* src/skey/donkey.h, src/skey/donkey.c, src/skey/md2.c
+	* src/skey/tailor.h, src/skey/config.h: Removed due to 
+	license issues (#305216)
+	* src/skey/md5.c, src/skey/md5.h, src/skey/md4.c
+	* src/skey/md4.h, src/skey/sha1.h, src/skey/sha1.c: 
+	Added new non-license violating implementations for these 
+	hashes algorithms. MD4 and MD5 are taken from the mhash library
+	which in turn are based on public domain implementations by Colin Plumb.
+	SHA1 is from the public domain implementation of Steve Reid.
+	* src/skey/skey.c, src/skey/skey.h, src/skey/skeyutil.c,
+	* src/skey/skeyutil.h: Reimplementation from scratch of the previous
+	S/Key support (RFC1760). Removed MD2 support and added SHA1 support, 
+	in order to be able one day to support RFC2289.
+
 2005-07-04  Kjartan Maraas  <kmaraas@gnome.org>
 
 	* configure.in: Post release bump to 2.11.2
diff -X /home/michele/svn/programming/vte/dontdiff -urN gnome-terminal/configure.in gnome-terminal.skeyfixed/configure.in
--- gnome-terminal/configure.in	2005-07-04 14:35:51.000000000 +0200
+++ gnome-terminal.skeyfixed/configure.in	2005-07-15 17:01:09.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
diff -X /home/michele/svn/programming/vte/dontdiff -urN gnome-terminal/src/skey/00readme gnome-terminal.skeyfixed/src/skey/00readme
--- gnome-terminal/src/skey/00readme	2002-10-30 21:26:23.000000000 +0100
+++ gnome-terminal.skeyfixed/src/skey/00readme	1970-01-01 01:00:00.000000000 +0100
@@ -1,103 +0,0 @@
-			  Readme for Donkey
-
-			  Kazuhiko Yamamoto
-		       kazu@is.aist-nara.ac.jp
-
-			   October 4, 1995
-
-<What's Donkey?>
-
-Donkey is an alternative for S/KEY's "key" command. The new feature that
-the original key doesn't have is print an entry for skeykeys as
-follows;
-
-	kazu 0099 al02004          115d83956f1089b6  Apr 26,1995 22:13:27
-
-This means that donkey is also an alternative for "keyinit". Since the
-entry is printed to stdout (not to /etc/skeykeys), you can easily sent
-it to remote operator by e-mail (with PGP signature or something). So,
-it possible to initiate S/KEY without login from the console of the
-host.
-
-The name "Donkey" is an acronym of "Don't Key".
-
-
-<How to use Donkey>
-
-(1) Calculate an One-Time-Password.
-
-Execute Donkey with sequence and seed, then input your passphrase.
-
-	% donkey 80 is12345
-	Enter passphrase : xxxxxxxxxxxxxxxxxxxxxxx
-	SOFT O SAW SWAB CON RODE
-
-You can choose hash function from MD2, MD4, and MD5.
-
-	% donkey 80 is12345
-	Enter passphrase : xxxxxxxxxxxxxxxxxxxxxxx
-	SOFT O SAW SWAB CON RODE
-
-	%donkey -f md5 80 is12345
-	Enter passphrase : xxxxxxxxxxxxxxxxxxxxxxx
-	LACK WIN ROSE ANNA STUN REEK
-
-The default hash function is MD4 due to the historical reason.
-
-
-(2) Calculate some One-Time-Passwords at once.
-
-Use -n option.
-
-	% donkey -n 10 80 is12345
-	Enter passphrase : xxxxxxxxxxxxxxxxxxxxxxx
-	71: WORE HELL CUB FAR DORA MALE  
-	72: SAIL DAN DONE BEER DAYS MOS  
-	73: PAN TONE THAT TOUT BURY EST  
-	74: KEN ROAM HEAT NAN MEAN HEN   
-	75: MINI MARS HASH BOTH SITU SING
-	76: TOW SHIN FLUE ARID AHOY NE   
-	77: SLID LEEK NO TREE STOW BEY   
-	78: RUDY WINE GIFT FUSS AGEE SUE 
-	79: GELD THIN MAID THIN BUD TURF 
-	80: SOFT O SAW SWAB CON RODE     
-
-Note that though "Enter passphrase" is printed out to stderr,
-One-Time-Passwords is to stdout. So, you can redirect the output
-safely.
-
-(3) Print skeykeys entry.
-
-Use -i option without argments. Then, enter login name, sequence and
-seed. If you like default value, just type RET. Input your passphrase
-twice to get the entry.
-
-	% donkey -i
-	Enter login name [default kazu]: 
-	Enter sequence 1 to 999 [default 99]: 
-	Enter new seed [default ur18122]: 
-	Please choose passphrase between 8 and 256 characters.
-	Enter passphrase : xxxxxxxxxxxxxxxxxxxxxxxxxxx
-	Re-enter passphrase : xxxxxxxxxxxxxxxxxxxxxxxxxxx
-	kazu 0099 ur18122          fc5b023e684968ff  Oct 02,1995 16:15:30
-	WINK SEAM GRAB ROAD HELL FEST
-
-
-<Copyright>
-
-Donkey conforms GNU GENERAL PUBLIC LICENSE Version 2.
-
-
-<Availability> 
-
-Donkey is available from the following repository. 
-
-"ftp://ftp.aist-nara.ac.jp/pub/Security/tool/donkey/donkey-current.tar.gz"
-
-
-<Things to do>
-
-* Support other one time passwords such as OTP.
-* Support other secure hash functions. 
-
-That's it.
diff -X /home/michele/svn/programming/vte/dontdiff -urN gnome-terminal/src/skey/btoe.c gnome-terminal.skeyfixed/src/skey/btoe.c
--- gnome-terminal/src/skey/btoe.c	2003-06-29 06:29:44.000000000 +0200
+++ gnome-terminal.skeyfixed/src/skey/btoe.c	2005-07-15 17:01:09.000000000 +0200
@@ -1,13 +1,17 @@
 /*
- * btoe.c
- *		 Copyright (C) 1995 Kazuhiko Yamamoto
- *	      Kazuhiko Yamamoto <kazu@is.aist-nara.ac.jp>
+ * This code is imported from Bollcore's S/KEY + some simple glib adaptations
+ * (See rfc2289 and rfc1760)
  */
 
-#include "config.h"
-#include "donkey.h"
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <glib.h>
 
-static UINT4 extract PROTO((char *s, int start, int length));
+#include "skey.h"
+#include "btoe.h"
+
+static guint32 extract (char *s, int start, int length);
 
 /* Dictionary for integer-word translations */
 char Wp[2048][4] = { "A", "ABE", "ACE", "ACT", "AD", "ADA", "ADD",
@@ -239,15 +243,15 @@
  * Returns a pointer to a static buffer
  */
 
-public char *btoe(md)
-char *md;
+char *btoe(md)
+unsigned char *md;
 {
         char cp[9];	/* 64 + 2 = 66 bits */
         int p, i;
 	static int buf[BUFSIZ];
 	char *engout = (char *)buf;
 	
-        memcpy(cp, md, 8);
+        memcpy(cp, md, SKEY_SIZE);
         /* compute parity */
         for(p = 0, i = 0; i < 64; i += 2)
                 p += extract(cp, i, 2);
@@ -276,31 +280,27 @@
  * starting with bit 'start'
  */
 
-private UINT4 extract(s, start, length)
+guint32 extract(s, start, length)
 char *s;
 int start, length;
 {
-        UINT1 cl;
-        UINT1 cc;
-        UINT1 cr;
-        UINT4  x;
+        guint8 cl;
+        guint8 cc;
+        guint8 cr;
+        guint32 x;
 
 	/* 66 = 11 x 6 */
 	
-        assert(length >= 0);	
-        assert(length <= 11);
-        assert(start >= 0);
-        assert(start + length <= 66);
+        g_assert(length >= 0);	
+        g_assert(length <= 11);
+        g_assert(start >= 0);
+        g_assert(start + length <= 66);
 
         cl = s[start/8];
         cc = s[start/8 + 1];
         cr = s[start/8 + 2];
-        x = (UINT4) ((((cl << 8) | cc) << 8) | cr);	/* 24 bits */
+        x = (guint32) ((((cl << 8) | cc) << 8) | cr);	/* 24 bits */
         x = x >> (24 - (length + (start % 8)));	        /* cut tail */
         x = (x & (0xffff >> (16 - length)));		/* cut head */
         return(x);					/* length */
 }
-
-/*
- * This code is imported from Bollcore's S/KEY
- */
diff -X /home/michele/svn/programming/vte/dontdiff -urN gnome-terminal/src/skey/btoe.h gnome-terminal.skeyfixed/src/skey/btoe.h
--- gnome-terminal/src/skey/btoe.h	1970-01-01 01:00:00.000000000 +0100
+++ gnome-terminal.skeyfixed/src/skey/btoe.h	2005-07-15 17:01:09.000000000 +0200
@@ -0,0 +1,2 @@
+char *btoe(unsigned char *md);
+
diff -X /home/michele/svn/programming/vte/dontdiff -urN gnome-terminal/src/skey/donkey.c gnome-terminal.skeyfixed/src/skey/donkey.c
--- gnome-terminal/src/skey/donkey.c	2002-11-03 22:20:48.000000000 +0100
+++ gnome-terminal.skeyfixed/src/skey/donkey.c	1970-01-01 01:00:00.000000000 +0100
@@ -1,56 +0,0 @@
-/*
- *			donkey  --- Don't Key
- *	       An alternative for S/KEY's key program.
- *
- *		 Copyright (C) 1995 Kazuhiko Yamamoto
- *
- * This software conforms GNU GENERAL PUBLIC LICENSE Version 2.
- *
- * Author:  Kazuhiko Yamamoto <kazu@is.aist-nara.ac.jp>
- * Created: April   25, 1995
- * Revised: October  4, 1995
- *
- */
-
-#include "config.h"
-#include "donkey.h"
-#include "md.h"
-
-/*
- * declaration of local functions
- */
-
-
-
-/*
- * global variables
- */
-
-int MD = DefaultMD; 
-
-/*
- * main
- */
-
-char *
-skey (int         md,
-      int         seq,
-      const char *seed,
-      const char *password)
-{
-	int i = 1;
-	char key[8];
-	/*
-	 * default option values
-	 */
-
-	MD = md;
-
-	if (keycrunch(key, seed, password) == RET_ERROR) {
-		return NULL;
-	}
-
-	for (i = 0; i < seq; i++) secure_hash(key);
-	return (strdup (btoe(key)));
-
-}
diff -X /home/michele/svn/programming/vte/dontdiff -urN gnome-terminal/src/skey/donkey.h gnome-terminal.skeyfixed/src/skey/donkey.h
--- gnome-terminal/src/skey/donkey.h	2002-11-03 22:20:48.000000000 +0100
+++ gnome-terminal.skeyfixed/src/skey/donkey.h	1970-01-01 01:00:00.000000000 +0100
@@ -1,10 +0,0 @@
-/*
- * donkey.h
- */
-
-/* should be included after config.h */
-
-char *btoe PROTO((char *md));
-int passphrase PROTO((char *prompt, char *phrase, int size, int rej));
-void secure_hash PROTO((char *x));
-int keycrunch PROTO((char *result, const char *seed, const char *passwd));
diff -X /home/michele/svn/programming/vte/dontdiff -urN gnome-terminal/src/skey/Makefile.am gnome-terminal.skeyfixed/src/skey/Makefile.am
--- gnome-terminal/src/skey/Makefile.am	2002-11-03 22:20:48.000000000 +0100
+++ gnome-terminal.skeyfixed/src/skey/Makefile.am	2005-07-15 17:01:25.000000000 +0200
@@ -1,24 +1,41 @@
-
 ### FIXME
 INCLUDES=@TERM_CFLAGS@ -I$(srcdir)/..
 
 SKEYFILES =		\
 	btoe.c		\
-	config.h	\
+	btoe.h		\
 	skey.h		\
-	donkey.h	\
-	donkey.c	\
-	md.h		\
-	md.c		\
-	md2.c		\
+	skey.c		\
+	skeyutil.h	\
+	skeyutil.c	\
 	md4.c		\
+	md4.h		\
 	md5.c		\
-	skey.c		\
-	skey.h		\
-	tailor.h
+	md5.h		\
+	sha1.h		\
+	sha1.c
 
 noinst_LTLIBRARIES=libskey.la
 
 libskey_la_SOURCES=$(SKEYFILES)
 
 libskey_la_LDFLAGS= @TERM_LIBS@
+
+noinst_PROGRAMS=testskey
+
+testskey_CFLAGS = @CFLAGS@ @TERM_CFLAGS@ -DSKEY_MAIN
+testskey_LDFLAGS= @TERM_LIBS@
+testskey_SOURCES = \
+	btoe.c		\
+	btoe.h		\
+	skey.h		\
+	skey.c		\
+	skeyutil.h	\
+	skeyutil.c	\
+	md4.c		\
+	md4.h		\
+	md5.c		\
+	md5.h		\
+	sha1.h		\
+	sha1.c
+
diff -X /home/michele/svn/programming/vte/dontdiff -urN gnome-terminal/src/skey/md2.c gnome-terminal.skeyfixed/src/skey/md2.c
--- gnome-terminal/src/skey/md2.c	2002-10-30 21:26:23.000000000 +0100
+++ gnome-terminal.skeyfixed/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 -X /home/michele/svn/programming/vte/dontdiff -urN gnome-terminal/src/skey/md4.c gnome-terminal.skeyfixed/src/skey/md4.c
--- gnome-terminal/src/skey/md4.c	2002-10-30 21:26:23.000000000 +0100
+++ gnome-terminal.skeyfixed/src/skey/md4.c	2005-07-15 17:01:09.000000000 +0200
@@ -1,248 +1,335 @@
 /*
- * 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.
+ */
+
+/* 
+ * The algorithm is due to Ron Rivest.  This code is based on code
+ * written by Colin Plumb in 1993.
  */
 
+
+#include <string.h>
+#include <stdlib.h>
 #include "config.h"
-#include "md.h"
+#include "skey.h"
+#include "skeyutil.h"
+#include "md4.h"
+
+#ifndef WORDS_BIGENDIAN
+#define byteReverse(buf, len)	/* Nothing */
+#else
+static void byteReverse(unsigned char *buf, unsigned longs);
 
-private void MD4Transform PROTO((UINT4 [4], UINT1 [64]));
 
 /*
- * Constants for MD4Transform routine.
+ * Note: this code is harmless on little-endian machines.
  */
-#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
-	};
+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
 
-/*
- * F, G and H are basic MD4 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 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(MD4_CTX *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(MD4_CTX *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(unsigned char* digest, MD4_CTX *ctx)
 {
-	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;
-	
-	/* Buffer remaining input */
-	memcpy((POINTER)&context->buffer[index],
-	       (POINTER)&input[i], inputLen-i);
+	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);
+	
+	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;
+
+	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;
 }
 
-/* MD4 basic transformation. Transforms state based on block.
- */
-private void MD4Transform (state, block)
-UINT4 state[4];
-UINT1 block[64];
+int MD4Keycrunch( char *result, const char *seed, const char *passphrase)
 {
-	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));
+	int len;
+	char *buf;
+	MD4_CTX md;
+	guint32 results[4];
+
+	len = strlen(seed) + strlen(passphrase);
+	buf = (char *)malloc(len+1);
+	if (buf == NULL)
+		return -1;
+
+	strcpy(buf, seed);
+	skey_lowcase(buf);
+	strcat(buf, passphrase);
+	skey_sevenbit(buf);
+
+	MD4Init(&md);
+	MD4Update(&md, (unsigned char *)buf, len);
+	MD4Final((unsigned char *)results, &md);
+	free(buf);
+
+	results[0] ^= results[2];
+	results[1] ^= results[3];
+	memcpy((void *)result, (void *)results, SKEY_SIZE);
+
+	return 0;
 }
 
-/*
- * 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.
- */
+
+void MD4SKey(char *x)
+{
+	MD4_CTX md;
+	guint32 results[4];
+
+	MD4Init(&md);
+	MD4Update(&md, (unsigned char *)x, SKEY_SIZE);
+	MD4Final((unsigned char *)results, &md);
+
+	results[0] ^= results[2];
+	results[1] ^= results[3];
+
+	memcpy((void *)x, (void *)results, SKEY_SIZE);
+}
+
+#ifdef MD4_MAIN
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+int main(int argc, char *argv[])
+{
+	MD4_CTX *md4;
+	unsigned char digest[16];
+	unsigned char data[1024];
+	int i, r;
+
+	memset(digest, 0, 16);
+	printf("MD4 digest algorithm. End with Ctrl-D:\n");
+
+	md4 = (MD4_CTX *)malloc(sizeof(MD4_CTX));
+	MD4Init(md4);
+	do {
+		r = read(0, data, sizeof data);
+		MD4Update(md4, data, r);
+	} while (r);
+
+	MD4Final(digest, md4);
+	printf("MD4 Digest is: ");
+	for (i = 0; i < 16; i++)
+		printf("%02X", digest[i]);
+
+	printf("\n");
+	free(md4);
+	return 0;
+}
+
+#endif
diff -X /home/michele/svn/programming/vte/dontdiff -urN gnome-terminal/src/skey/md4.h gnome-terminal.skeyfixed/src/skey/md4.h
--- gnome-terminal/src/skey/md4.h	1970-01-01 01:00:00.000000000 +0100
+++ gnome-terminal.skeyfixed/src/skey/md4.h	2005-07-15 17:01:09.000000000 +0200
@@ -0,0 +1,19 @@
+#ifndef MD4_H
+#define MD4_H
+
+#include <glib.h>
+ 
+typedef struct {
+	guint32 buf[4];
+	guint32 bits[2];
+	unsigned char in[64];
+} MD4_CTX;
+
+void MD4Transform(guint32 buf[4], guint32 const in[16]);
+void MD4Init(MD4_CTX *context);
+void MD4Update(MD4_CTX *context, unsigned char const *buf, unsigned len);
+void MD4Final(unsigned char *digest, MD4_CTX *context);
+int  MD4Keycrunch(char *result, const char *seed, const char *passphrase);
+void MD4SKey(char *x);
+
+#endif /* !MD4_H */
diff -X /home/michele/svn/programming/vte/dontdiff -urN gnome-terminal/src/skey/md5.c gnome-terminal.skeyfixed/src/skey/md5.c
--- gnome-terminal/src/skey/md5.c	2002-10-30 21:26:23.000000000 +0100
+++ gnome-terminal.skeyfixed/src/skey/md5.c	2005-07-15 17:01:09.000000000 +0200
@@ -1,275 +1,334 @@
 /*
- * 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"
 
-private void MD5Transform PROTO((UINT4 [4], unsigned char [64]));
+#include <string.h>
+#include <stdlib.h>
+#include "config.h"
+#include "skey.h"
+#include "skeyutil.h"
+#include "md5.h"
+
+#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
-	};
+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
 
 /*
- * F, G, H and I are basic MD5 functions.
+ * Start MD5 accumulation.  Set bit count to 0 and buffer to mysterious
+ * initialization constants.
  */
-#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)))
+void MD5Init(MD5_CTX *ctx)
+{
+    ctx->buf[0] = 0x67452301;
+    ctx->buf[1] = 0xefcdab89;
+    ctx->buf[2] = 0x98badcfe;
+    ctx->buf[3] = 0x10325476;
+
+    ctx->bits[0] = 0;
+    ctx->bits[1] = 0;
+}
 
 /*
- * ROTATE_LEFT rotates x left n bits.
+ * Update context to reflect the concatenation of another buffer full
+ * of bytes.
  */
-#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
+void MD5Update(MD5_CTX *ctx, unsigned char const *buf, unsigned len)
+{
+    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);
+	MD5Transform(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);
+	MD5Transform(ctx->buf, (guint32 *) ctx->in);
+	buf += 64;
+	len -= 64;
+    }
+
+    /* Handle any remaining bytes of data. */
+
+    memcpy(ctx->in, buf, len);
+}
 
 /*
- * FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
- * Rotation is separate from addition to prevent recomputation.
+ * Final wrapup - pad to 64-byte boundary with the bit pattern 
+ * 1 0* (64-bit count of bits processed, MSB-first)
  */
-#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); \
+void MD5Final(unsigned char *digest, MD5_CTX *ctx)
+{
+    unsigned int count;
+    unsigned char *p;
+
+    /* 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 )
+
 /*
- * MD5 initialization. Begins an MD5 operation, writing a new context.
+ * 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 MD5Init (ptr)
-POINTER ptr;
+void MD5Transform(guint32 buf[4], guint32 const in[16])
 {
-	MD5_CTX *context = (MD5_CTX *) ptr;
+    register guint32 a, b, c, d;
 
-	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;
+    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;
 }
 
-/* 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 */
+int MD5Keycrunch(char *result, const char *seed, const char *passhrase)
 {
-	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);
+	char *buf;
+	MD5_CTX md;
+	guint32 results[4];
+	unsigned int len;
+
+	len = strlen(seed) + strlen(passhrase);
+	buf = (char *)malloc(len+1);
+	if (buf == NULL)
+		return -1;
+
+	strcpy(buf, seed);
+	skey_lowcase(buf);
+	strcat(buf, passhrase);
+	skey_sevenbit(buf);
+
+	MD5Init(&md);
+	MD5Update(&md, (unsigned char *)buf, len);
+	MD5Final((unsigned char *)results, &md);
+	free(buf);
 
-		for (i = partLen; i + 63 < inputLen; i += 64)
-			MD5Transform (context->state, &input[i]);
+	results[0] ^= results[2];
+	results[1] ^= results[3];
 
-		index = 0;
-	}
-	else
-		i = 0;
+	memcpy((void *)result, (void *)results, SKEY_SIZE);
 
-	/* Buffer remaining input */
-	memcpy((POINTER)&context->buffer[index],
-	       (POINTER)&input[i], inputLen-i);
+	return 0;
 }
 
-/* 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;
+void MD5SKey(char *x)
 {
-	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);
+	MD5_CTX md;
+	guint32 results[4];
+
+	MD5Init(&md);
+	MD5Update(&md, (unsigned char *)x, SKEY_SIZE);
+	MD5Final((unsigned char *)results, &md);
+
+	results[0] ^= results[2];
+	results[1] ^= results[3];
 
-	/* Zeroize sensitive information. */
-	memset((POINTER)context, 0, sizeof (*context));
+	memcpy((void *)x, (void *)results, SKEY_SIZE);
 }
 
-/* MD5 basic transformation. Transforms state based on block.
- */
-private void MD5Transform (state, block)
-UINT4 state[4];
-UINT1 block[64];
+
+#ifdef MD5_MAIN
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+int main(int argc, char *argv[])
 {
-	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));
+	MD5_CTX *md5;
+	unsigned char digest[16];
+	unsigned char data[1024];
+	int r;
+
+	md5 = (MD5_CTX *)malloc(sizeof(MD5_CTX));
+
+	printf("MD5 digest algorithm. End with Ctrl-D:\n");
+	MD5Init(md5);
+	do {
+		r = read(0, data, sizeof data);
+		MD5Update(md5, data, r);
+	} while (r);
+
+	MD5Final(digest, md5);
+	printf("MD5 Digest is: ");
+	for (r = 0; r < 16; r++)
+		printf("%02X", digest[r]);
+
+	printf("\n");
+	free(md5);
+	return 0;
 }
 
-/* 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.
- */
-
+#endif
diff -X /home/michele/svn/programming/vte/dontdiff -urN gnome-terminal/src/skey/md5.h gnome-terminal.skeyfixed/src/skey/md5.h
--- gnome-terminal/src/skey/md5.h	1970-01-01 01:00:00.000000000 +0100
+++ gnome-terminal.skeyfixed/src/skey/md5.h	2005-07-15 17:01:09.000000000 +0200
@@ -0,0 +1,20 @@
+#ifndef MD5_H
+#define MD5_H
+
+#include <glib.h>
+
+typedef struct {
+	guint32 buf[4];
+	guint32 bits[2];
+	unsigned char in[64];
+} MD5_CTX;
+
+void MD5Transform(guint32 buf[4], guint32 const in[16]);
+void MD5Init(MD5_CTX *context);
+void MD5Update(MD5_CTX *context, unsigned char const *buf, unsigned len);
+void MD5Final(unsigned char *digest, MD5_CTX *context);
+int  MD5Keycrunch(char *result, const char *seed, const char *passhrase);
+void MD5SKey(char *x);
+
+
+#endif /* !MD5_H */
diff -X /home/michele/svn/programming/vte/dontdiff -urN gnome-terminal/src/skey/md.c gnome-terminal.skeyfixed/src/skey/md.c
--- gnome-terminal/src/skey/md.c	2002-10-30 21:26:23.000000000 +0100
+++ gnome-terminal.skeyfixed/src/skey/md.c	1970-01-01 01:00:00.000000000 +0100
@@ -1,72 +0,0 @@
-/*
- * md.c
- *		 Copyright (C) 1995 Kazuhiko Yamamoto
- *	      Kazuhiko Yamamoto <kazu@is.aist-nara.ac.jp>
- */
-
-#include "config.h"
-#include "md.h"
-
-struct mdsw mdsw[] = {
-    {MD2Init, MD2Update, MD2Final},
-    {MD4Init, MD4Update, MD4Final},
-    {MD5Init, MD5Update, MD5Final},
-};
-
-/*
- * Encodes input (UINT4) into output (unsigned char). Assumes len is
- * a multiple of 4.
- */
-void MDEncode (output, input, len)
-POINTER output;
-UINT4 *input;
-unsigned int len;
-{
-	unsigned int i, j;
-	
-	for (i = 0, j = 0; j < len; i++, j += 4) {
-		output[j] = (unsigned char)(input[i] & 0xff);
-		output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
-		output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
-		output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
-	}
-}
-
-/*
- * Decodes input (unsigned char) into output (UINT4). Assumes len is
- * a multiple of 4.
- */
-void MDDecode (output, input, len)
-UINT4 *output;
-POINTER input;
-unsigned int len;
-{
-	unsigned int i, j;
-	
-	for (i = 0, j = 0; j < len; i++, j += 4)
-		output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
-			(((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
-}
-
-
-/*
- * 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 -X /home/michele/svn/programming/vte/dontdiff -urN gnome-terminal/src/skey/md.h gnome-terminal.skeyfixed/src/skey/md.h
--- gnome-terminal/src/skey/md.h	2002-11-03 22:20:48.000000000 +0100
+++ gnome-terminal.skeyfixed/src/skey/md.h	1970-01-01 01:00:00.000000000 +0100
@@ -1,77 +0,0 @@
-/*
- * md.h
- *		 Copyright (C) 1995 Kazuhiko Yamamoto
- *	      Kazuhiko Yamamoto <kazu@is.aist-nara.ac.jp>
- */
-
-#include "config.h"
-#define MD2 0
-#define MD4 1
-#define MD5 2
-/* see mdsw in md.c */
-
-extern int MD;
-
-/*
- * MD
- */
-
-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;
-
-struct mdsw {
-	void (*md_init)();
-	void (*md_update)();
-	void (*md_final)(); 	
-};
-
-
-/*
- * 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
- */
-
-extern struct mdsw mdsw[];
-
-void MDEncode PROTO((POINTER, UINT4 *, unsigned int));
-void MDDecode PROTO((UINT4 *, POINTER, unsigned int));
diff -X /home/michele/svn/programming/vte/dontdiff -urN gnome-terminal/src/skey/README gnome-terminal.skeyfixed/src/skey/README
--- gnome-terminal/src/skey/README	2002-10-30 21:26:23.000000000 +0100
+++ gnome-terminal.skeyfixed/src/skey/README	1970-01-01 01:00:00.000000000 +0100
@@ -1,3 +0,0 @@
-This skey implementation is a cut-n-paste of a program called donkey,
-written by Kazuhiko Yamamoto.  It has been minorly modified to get rid
-of argument parsing.
diff -X /home/michele/svn/programming/vte/dontdiff -urN gnome-terminal/src/skey/sha1.c gnome-terminal.skeyfixed/src/skey/sha1.c
--- gnome-terminal/src/skey/sha1.c	1970-01-01 01:00:00.000000000 +0100
+++ gnome-terminal.skeyfixed/src/skey/sha1.c	2005-07-15 17:01:09.000000000 +0200
@@ -0,0 +1,295 @@
+/*
+ * SHA-1 in C
+ * By Steve Reid <steve@edmweb.com>
+ * 100% Public Domain
+ *
+ * Test Vectors (from FIPS PUB 180-1)
+ * "abc"
+ *   A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
+ * "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
+ *   84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
+ * A million repetitions of "a"
+ *   34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
+ */
+#ifndef HAVE_SHA1_H
+
+#define SHA1HANDSOFF		/* Copies data before messing with it. */
+
+#include <sys/param.h>
+#include <string.h>
+#include <stdlib.h>
+#include <netinet/in.h>         /* ntohl */
+#include "config.h"
+#include "skey.h"
+#include "skeyutil.h"
+#include "sha1.h"
+
+#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
+
+/*
+ * blk0() and blk() perform the initial expand.
+ * I got the idea of expanding during the round function from SSLeay
+ */
+#ifndef WORDS_BIGENDIAN
+# define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \
+    |(rol(block->l[i],8)&0x00FF00FF))
+#else
+# define blk0(i) block->l[i]
+#endif
+#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
+    ^block->l[(i+2)&15]^block->l[i&15],1))
+
+/*
+ * (R0+R1), R2, R3, R4 are the different operations (rounds) used in SHA1
+ */
+#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30);
+#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30);
+#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);
+#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);
+#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
+
+#ifndef WORDS_BIGENDIAN
+#define byteReverse(buf, len)	/* Nothing */
+#else
+static void byteReverse(unsigned char *buf, unsigned longs);
+
+/*
+ * Note: this code is harmless on little-endian machines.
+ */
+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
+
+/*
+ * Hash a single 512-bit block. This is the core of the algorithm.
+ */
+void SHA1Transform(state, buffer)
+    guint32 state[5];
+    const unsigned char buffer[64];
+{
+    guint32 a, b, c, d, e;
+    typedef union {
+	unsigned char c[64];
+	unsigned int l[16];
+    } CHAR64LONG16;
+    CHAR64LONG16 *block;
+
+#ifdef SHA1HANDSOFF
+    static unsigned char workspace[64];
+    block = (CHAR64LONG16 *)workspace;
+    (void)memcpy(block, buffer, 64);
+#else
+    block = (CHAR64LONG16 *)buffer;
+#endif
+
+    /* Copy context->state[] to working vars */
+    a = state[0];
+    b = state[1];
+    c = state[2];
+    d = state[3];
+    e = state[4];
+
+    /* 4 rounds of 20 operations each. Loop unrolled. */
+    R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
+    R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
+    R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
+    R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
+    R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
+    R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
+    R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
+    R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
+    R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
+    R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
+    R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
+    R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
+    R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
+    R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
+    R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
+    R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
+    R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
+    R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
+    R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
+    R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
+
+    /* Add the working vars back into context.state[] */
+    state[0] += a;
+    state[1] += b;
+    state[2] += c;
+    state[3] += d;
+    state[4] += e;
+
+    /* Wipe variables */
+    a = b = c = d = e = 0;
+}
+
+
+/*
+ * SHA1Init - Initialize new context
+ */
+void SHA1Init(context)
+    SHA1_CTX *context;
+{
+
+    /* SHA1 initialization constants */
+    context->state[0] = 0x67452301;
+    context->state[1] = 0xEFCDAB89;
+    context->state[2] = 0x98BADCFE;
+    context->state[3] = 0x10325476;
+    context->state[4] = 0xC3D2E1F0;
+    context->count[0] = context->count[1] = 0;
+}
+
+
+/*
+ * Run your data through this.
+ */
+void SHA1Update(context, data, len)
+    SHA1_CTX *context;
+    const unsigned char *data;
+    unsigned int len;
+{
+    unsigned int i, j;
+
+    j = context->count[0];
+    if ((context->count[0] += len << 3) < j)
+	context->count[1] += (len>>29)+1;
+    j = (j >> 3) & 63;
+    if ((j + len) > 63) {
+	(void)memcpy(&context->buffer[j], data, (i = 64-j));
+	SHA1Transform(context->state, context->buffer);
+	for ( ; i + 63 < len; i += 64)
+	    SHA1Transform(context->state, &data[i]);
+	j = 0;
+    } else {
+	i = 0;
+    }
+    (void)memcpy(&context->buffer[j], &data[i], len - i);
+}
+
+
+/*
+ * Add padding and return the message digest.
+ */
+void SHA1Final(digest, context)
+    unsigned char digest[20];
+    SHA1_CTX* context;
+{
+    unsigned int i;
+    unsigned char finalcount[8];
+
+    for (i = 0; i < 8; i++) {
+	finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
+	 >> ((3-(i & 3)) * 8) ) & 255);	 /* Endian independent */
+    }
+    SHA1Update(context, (unsigned char *)"\200", 1);
+    while ((context->count[0] & 504) != 448)
+	SHA1Update(context, (unsigned char *)"\0", 1);
+    SHA1Update(context, finalcount, 8);  /* Should cause a SHA1Transform() */
+
+    if (digest) {
+	for (i = 0; i < 20; i++)
+	    digest[i] = (unsigned char)
+		((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
+    }
+}
+
+int SHA1Keycrunch(char *result, const char *seed, const char *passphrase)
+{
+	char *buf;
+	SHA1_CTX sha;
+	guint32 results[5];
+	unsigned int len;
+
+	len = strlen(seed) + strlen(passphrase);
+	if ((buf = (char *)malloc(len+1)) == NULL)
+		return -1;
+
+	strcpy(buf, seed);
+	skey_lowcase(buf);
+	strcat(buf, passphrase);
+	skey_sevenbit(buf);
+
+	SHA1Init(&sha);
+	SHA1Update(&sha, (unsigned char *)buf, len);
+	SHA1Final((unsigned char *)results, &sha);
+	free(buf);
+
+#ifndef WORDS_BIGENDIAN
+	HTONDIGEST(results);
+#else
+	byteReverse((unsigned char *)results, 5);
+#endif
+	results[0] ^= results[2];
+	results[1] ^= results[3];
+	results[0] ^= results[4];
+
+	memcpy((void *)result, (void *)results, SKEY_SIZE);
+
+	return 0;
+}
+
+void SHA1SKey(char *x)
+{
+	SHA1_CTX sha;
+	guint32 results[5];
+
+	SHA1Init(&sha);
+	SHA1Update(&sha, (unsigned char *)x, SKEY_SIZE);
+	SHA1Final((unsigned char *)results, &sha);
+
+#ifndef WORDS_BIGENDIAN
+	HTONDIGEST(results);
+#else
+	byteReverse((unsigned char *)results, 5);
+#endif
+
+	results[0] ^= results[2];
+	results[1] ^= results[3];
+	results[0] ^= results[4];
+
+	memcpy((void *)x, (void *)results, SKEY_SIZE);
+}
+
+#endif
+
+#ifdef SHA1_MAIN
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+int main(int argc, char *argv[])
+{
+	SHA1_CTX *sha1;
+	unsigned char digest[SHA1_DIGESTSIZE];
+	unsigned char data[1024];
+	int r;
+
+	sha1 = (SHA1_CTX *)malloc(sizeof(SHA1_CTX));
+
+	printf("SHA1 digest algorithm. End with Ctrl-D:\n");
+	SHA1Init(sha1);
+	do {
+		r = read(0, data, sizeof data);
+		SHA1Update(sha1, data, r);
+	} while (r);
+
+	SHA1Final(digest, sha1);
+	printf("SHA1 Digest is: ");
+	for (r = 0; r < 16; r++)
+		printf("%02X", digest[r]);
+
+	printf("\n");
+	free(sha1);
+	return 0;
+}
+
+#endif
diff -X /home/michele/svn/programming/vte/dontdiff -urN gnome-terminal/src/skey/sha1.h gnome-terminal.skeyfixed/src/skey/sha1.h
--- gnome-terminal/src/skey/sha1.h	1970-01-01 01:00:00.000000000 +0100
+++ gnome-terminal.skeyfixed/src/skey/sha1.h	2005-07-15 17:01:09.000000000 +0200
@@ -0,0 +1,41 @@
+/*
+ * SHA-1 in C
+ * By Steve Reid <steve@edmweb.com>
+ * 100% Public Domain
+ */
+
+#ifndef _SHA1_H
+#define _SHA1_H
+
+#include <glib.h>
+
+typedef struct {
+    guint32 state[5];
+    guint32 count[2];  
+    unsigned char buffer[64];
+} SHA1_CTX;
+  
+void SHA1Transform (guint32 state[5], const unsigned char buffer[64]);
+void SHA1Init (SHA1_CTX *context);
+void SHA1Update (SHA1_CTX *context, const unsigned char *data, guint len);
+void SHA1Final (unsigned char digest[20], SHA1_CTX *context);
+int  SHA1Keycrunch(char *result, const char *seed, const char *passphrase);
+void SHA1SKey(char *x);
+
+#define SHA1_DIGESTSIZE       20
+#define SHA1_BLOCKSIZE        64
+#define HTONDIGEST(x) { \
+      x[0] = htonl(x[0]); \
+      x[1] = htonl(x[1]); \
+      x[2] = htonl(x[2]); \
+      x[3] = htonl(x[3]); \
+      x[4] = htonl(x[4]); }
+
+#define NTOHDIGEST(x) { \
+      x[0] = ntohl(x[0]); \
+      x[1] = ntohl(x[1]); \
+      x[2] = ntohl(x[2]); \
+      x[3] = ntohl(x[3]); \
+      x[4] = ntohl(x[4]); }
+
+#endif /* _SHA1_H */
diff -X /home/michele/svn/programming/vte/dontdiff -urN gnome-terminal/src/skey/skey.c gnome-terminal.skeyfixed/src/skey/skey.c
--- gnome-terminal/src/skey/skey.c	2003-04-24 16:43:29.000000000 +0200
+++ gnome-terminal.skeyfixed/src/skey/skey.c	2005-07-15 17:01:09.000000000 +0200
@@ -1,74 +1,203 @@
-/*
- * skey.c
- *		 Copyright (C) 1995 Kazuhiko Yamamoto
- *	      Kazuhiko Yamamoto <kazu@is.aist-nara.ac.jp>
- */
-
-#include "config.h"
-#include "donkey.h"
-#include "md.h"
+#include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
 
-private void sevenbit PROTO((char *s));
+#include "md4.h"
+#include "md5.h"
+#include "sha1.h"
+#include "skey.h"
+#include "btoe.h"
+
+
+struct skey_hash {
+	int (*Keycrunch) (char *, const char *, const char *);
+	void (*Skey) (char *);
+};
+static struct skey_hash hash_table[] = {
+	{ MD4Keycrunch,  MD4SKey },
+	{ MD5Keycrunch,  MD5SKey },
+	{ SHA1Keycrunch, SHA1SKey }
+};
 
-public int keycrunch(result, seed, passwd)
-char *result;   /* 8-byte result */
-const char *seed;     /* Seed, any length */
-const char *passwd;   /* Password, any length */
-{
-	char *buf;
-	MDX_CTX md;
-	UINT4 results[4];
-	unsigned int buflen;
-	
-	buflen = strlen(seed) + strlen(passwd);
-	if((buf = malloc(buflen + 1)) == NULL)
-		return(RET_ERROR);
-	strcpy(buf, seed);
-	strcat(buf, passwd);
-
-	/* Crunch the key through MD[45] */
-	sevenbit(buf);
-	(*mdsw[MD].md_init)((POINTER)&md);
-	(*mdsw[MD].md_update)((POINTER)&md, (POINTER)buf, buflen);
-	(*mdsw[MD].md_final)((POINTER)results, (POINTER)&md);
-	free(buf);
 
-	results[0] ^= results[2];
-	results[1] ^= results[3];
+char *skey(int algorithm, int seq, const char *seed, const char *passphrase)
+{
+	char key[SKEY_SIZE];
+	int i;
+	g_assert(algorithm >= MD4);
+	g_assert(algorithm <= SHA1);
+	if (hash_table[algorithm].Keycrunch(key, seed, passphrase) == -1)
+		return NULL;
 
-	memcpy(result,(char *)results,8);
+	for (i = 0; i < seq; i++)
+		hash_table[algorithm].Skey(key);
 
-	return(RET_SUCCESS);
+	return strdup(btoe((unsigned char *)key));
 }
 
-private void sevenbit(s)
-char *s;
+#ifdef SKEY_MAIN
+
+struct test_entry {
+	const char *passphrase;
+	const char *seed;
+	int  count;
+	const char *hex;
+	const char *btoe;
+};
+
+static struct test_entry md4_test_vector[] = {
+	{"This is a test.", "TeSt",     0, "D185 4218 EBBB 0B51", "ROME MUG FRED SCAN LIVE LACE"},
+	{"This is a test.", "TeSt",     1, "6347 3EF0 1CD0 B444", "CARD SAD MINI RYE COL KIN"},
+	{"This is a test.", "TeSt",    99, "C5E6 1277 6E6C 237A", "NOTE OUT IBIS SINK NAVE MODE"},
+	{"AbCdEfGhIjK",     "alpha1",   0, "5007 6F47 EB1A DE4E", "AWAY SEN ROOK SALT LICE MAP"},
+	{"AbCdEfGhIjK",     "alpha1",   1, "65D2 0D19 49B5 F7AB", "CHEW GRIM WU HANG BUCK SAID"},
+	{"AbCdEfGhIjK",     "alpha1",  99, "D150 C82C CE6F 62D1", "ROIL FREE COG HUNK WAIT COCA"},
+	{"OTP's are good",  "correct",  0, "849C 79D4 F6F5 5388", "FOOL STEM DONE TOOL BECK NILE"},
+	{"OTP's are good",  "correct",  1, "8C09 92FB 2508 47B1", "GIST AMOS MOOT AIDS FOOD SEEM"},
+	{"OTP's are good",  "correct", 99, "3F3B F4B4 145F D74B", "TAG SLOW NOV MIN WOOL KENO"}
+};
+
+static struct test_entry md5_test_vector[] = {
+	{"This is a test.", "TeSt",     0, "9E87 6134 D904 99DD", "INCH SEA ANNE LONG AHEM TOUR"},
+	{"This is a test.", "TeSt",     1, "7965 E054 36F5 029F", "EASE OIL FUM CURE AWRY AVIS"},
+	{"This is a test.", "TeSt",    99, "50FE 1962 C496 5880", "BAIL TUFT BITS GANG CHEF THY"},
+	{"AbCdEfGhIjK",     "alpha1",   0, "8706 6DD9 644B F206", "FULL PEW DOWN ONCE MORT ARC"},
+	{"AbCdEfGhIjK",     "alpha1",   1, "7CD3 4C10 40AD D14B", "FACT HOOF AT FIST SITE KENT"},
+	{"AbCdEfGhIjK",     "alpha1",  99, "5AA3 7A81 F212 146C", "BODE HOP JAKE STOW JUT RAP"},
+	{"OTP's are good",  "correct",  0, "F205 7539 43DE 4CF9", "ULAN NEW ARMY FUSE SUIT EYED"},
+	{"OTP's are good",  "correct",  1, "DDCD AC95 6F23 4937", "SKIM CULT LOB SLAM POE HOWL"},
+	{"OTP's are good",  "correct", 99, "B203 E28F A525 BE47", "LONG IVY JULY AJAR BOND LEE"}
+};
+
+static struct test_entry sha1_test_vector[] = {
+	{"This is a test.", "TeSt",     0, "BB9E 6AE1 979D 8FF4", "MILT VARY MAST OK SEES WENT"},
+	{"This is a test.", "TeSt",     1, "63D9 3663 9734 385B", "CART OTTO HIVE ODE VAT NUT"},
+	{"This is a test.", "TeSt",    99, "87FE C776 8B73 CCF9", "GAFF WAIT SKID GIG SKY EYED"},
+	{"AbCdEfGhIjK",     "alpha1",   0, "AD85 F658 EBE3 83C9", "LEST OR HEEL SCOT ROB SUIT"},
+	{"AbCdEfGhIjK",     "alpha1",   1, "D07C E229 B5CF 119B", "RITE TAKE GELD COST TUNE RECK"},
+	{"AbCdEfGhIjK",     "alpha1",  99, "27BC 7103 5AAF 3DC6", "MAY STAR TIN LYON VEDA STAN"},
+	{"OTP's are good",  "correct",  0, "D51F 3E99 BF8E 6F0B", "RUST WELT KICK FELL TAIL FRAU"},
+	{"OTP's are good",  "correct",  1, "82AE B52D 9437 74E4", "FLIT DOSE ALSO MEW DRUM DEFY"},
+	{"OTP's are good",  "correct", 99, "4F29 6A74 FE15 67EC", "AURA ALOE HURL WING BERG WAIT"}
+};
+
+int skey_test()
 {
-	/* make sure there are only 7 bit code in the line*/
-	while(*s){
-		*s = 0x7f & (*s);
-		s++;
+	int i, n;
+	int failed = 0;
+	char *key;
+
+	printf("Testing of S/Key otp using Appendix C of rfc 2289\n");
+	printf("* MD4:\n");
+	n = sizeof(md4_test_vector) / sizeof(struct test_entry);
+	for (i = 0; i < n; i++) {
+		key = skey(MD4, md4_test_vector[i].count,
+			md4_test_vector[i].seed,
+			md4_test_vector[i].passphrase);
+		if (key == NULL) {
+			printf("Error calculating key\n");
+			continue;
+		}
+		printf("%15s %8s %02d %32s -> %32s",
+			md4_test_vector[i].passphrase,
+			md4_test_vector[i].seed,
+			md4_test_vector[i].count,
+			md4_test_vector[i].btoe,
+			key);
+		if (strcmp(key, md4_test_vector[i].btoe) != 0) {
+			printf(" - WRONG\n");
+			failed++;
+		} else
+			printf(" - OK\n");
+		free(key);
+	}
+
+	printf("\n* MD5:\n");
+	n = sizeof(md5_test_vector) / sizeof(struct test_entry);
+	for (i = 0; i < n; i++) {
+		key = skey(MD5, md5_test_vector[i].count,
+			md5_test_vector[i].seed,
+			md5_test_vector[i].passphrase);
+		if (key == NULL) {
+			printf("Error calculating key\n");
+			continue;
+		}
+		printf("%15s %8s %02d %32s -> %32s",
+			md5_test_vector[i].passphrase,
+			md5_test_vector[i].seed,
+			md5_test_vector[i].count,
+			md5_test_vector[i].btoe,
+			key);
+		if (strcmp(key, md5_test_vector[i].btoe) != 0) {
+			printf(" - WRONG\n");
+			failed++;
+		} else
+			printf(" - OK\n");
+		free(key);
+	}
+
+	printf("\n* SHA1:\n");
+	n = sizeof(sha1_test_vector) / sizeof(struct test_entry);
+	for (i = 0; i < n; i++) {
+		key = skey(SHA1, sha1_test_vector[i].count,
+			sha1_test_vector[i].seed,
+			sha1_test_vector[i].passphrase);
+		if (key == NULL) {
+			printf("Error calculating key\n");
+			continue;
+		}
+		printf("%15s %8s %02d %32s -> %32s",
+			sha1_test_vector[i].passphrase,
+			sha1_test_vector[i].seed,
+			sha1_test_vector[i].count,
+			sha1_test_vector[i].btoe,
+			key);
+		if (strcmp(key, sha1_test_vector[i].btoe) != 0) {
+			printf(" - WRONG\n");
+			failed++;
+		} else
+			printf(" - OK\n");
+		free(key);
 	}
+
+	printf("\nTotal test failures: %d\n", failed);
+	return failed;
 }
 
-public void secure_hash(x)
-char *x;
+int main(int argc, char *argv[])
 {
-	MDX_CTX md;
-	UINT4 results[4];
+	char *key;
+	int c;
+
+	if (argc != 4) {
+		printf("No arguments specified, will do automatic testing\n");
+		printf("If you don't want this:\n");
+		printf("Use %s <password> <count> <seed>\n", argv[0]);
+		return skey_test();
+	}
 
-	(*mdsw[MD].md_init)((POINTER)&md);
-	(*mdsw[MD].md_update)((POINTER)&md,(POINTER)x, 8);
-	(*mdsw[MD].md_final)((POINTER)results, (POINTER)&md);
-	/* Fold 128 to 64 bits */
-	results[0] ^= results[2];
-	results[1] ^= results[3];
+	c = atoi(argv[2]);
+	
+	key = skey(MD4, c, argv[3], argv[1]);
+	if (key != NULL) {
+		printf("MD4 %s\n", btoe((unsigned char *)key));
+		free(key);
+	}
+	
+	key = skey(MD5, c, argv[3], argv[1]);
+	if (key != NULL) {
+		printf("MD5  %s\n", btoe((unsigned char *)key));
+		free(key);
+	}
+
+	key = skey(SHA1,c, argv[3], argv[1]);
+	if (key != NULL) {
+		printf("SHA1 %s\n", btoe((unsigned char *)key));
+		free(key);
+	}
 
-	/* Only works on byte-addressed little-endian machines!! */
-	memcpy(x, (char *)results, 8);
+	return 0;
 }
 
-/*
- * This code is imported from Bollcore's S/KEY
- */
+#endif
diff -X /home/michele/svn/programming/vte/dontdiff -urN gnome-terminal/src/skey/skey.h gnome-terminal.skeyfixed/src/skey/skey.h
--- gnome-terminal/src/skey/skey.h	2002-10-30 21:26:23.000000000 +0100
+++ gnome-terminal.skeyfixed/src/skey/skey.h	2005-07-15 17:01:09.000000000 +0200
@@ -1,13 +1,8 @@
-#ifndef __SKEY_H__
-#define __SKEY_H__
+#define MD4  0
+#define MD5  1
+#define SHA1 2
 
-#define MD2 0
-#define MD4 1
-#define MD5 2
+#define SKEY_SIZE	8
 
-char *skey (int         md,
-	    int         seq,
-	    const char *seed,
-	    const char *password);
+char *skey(int algorithm, int seq, const char *seed, const char *passhrase);
 
-#endif
diff -X /home/michele/svn/programming/vte/dontdiff -urN gnome-terminal/src/skey/skeyutil.c gnome-terminal.skeyfixed/src/skey/skeyutil.c
--- gnome-terminal/src/skey/skeyutil.c	1970-01-01 01:00:00.000000000 +0100
+++ gnome-terminal.skeyfixed/src/skey/skeyutil.c	2005-07-15 17:01:09.000000000 +0200
@@ -0,0 +1,18 @@
+#include <ctype.h>
+
+void skey_sevenbit(char *s)
+{
+	char *p;
+
+	for (p = s; *p; p++)
+		*p &= 0x7f;
+}
+
+void skey_lowcase(char *s)
+{
+	char *p;
+
+	for (p = s; *p; p++)
+		if (isupper(*p))
+			*p = tolower(*p);
+}
diff -X /home/michele/svn/programming/vte/dontdiff -urN gnome-terminal/src/skey/skeyutil.h gnome-terminal.skeyfixed/src/skey/skeyutil.h
--- gnome-terminal/src/skey/skeyutil.h	1970-01-01 01:00:00.000000000 +0100
+++ gnome-terminal.skeyfixed/src/skey/skeyutil.h	2005-07-15 17:01:09.000000000 +0200
@@ -0,0 +1,3 @@
+void skey_sevenbit(char *s);
+void skey_lowcase(char *s);
+
diff -X /home/michele/svn/programming/vte/dontdiff -urN gnome-terminal/src/skey/tailor.h gnome-terminal.skeyfixed/src/skey/tailor.h
--- gnome-terminal/src/skey/tailor.h	2002-10-30 21:26:23.000000000 +0100
+++ gnome-terminal.skeyfixed/src/skey/tailor.h	1970-01-01 01:00:00.000000000 +0100
@@ -1,328 +0,0 @@
-/* tailor.h -- target dependent definitions
- * Copyright (C) 1992-1993 Jean-loup Gailly.
- * This is free software; you can redistribute it and/or modify it under the
- * terms of the GNU General Public License, see the file COPYING.
- */
-
-/* The target dependent definitions should be defined here only.
- * The target dependent functions should be defined in tailor.c.
- */
-
-/* $Id: tailor.h,v 1.1 2002/10/30 20:26:23 jrb Exp $ */
-
-#if defined(__MSDOS__) && !defined(MSDOS)
-#  define MSDOS
-#endif
-
-#if defined(__OS2__) && !defined(OS2)
-#  define OS2
-#endif
-
-#if defined(OS2) && defined(MSDOS) /* MS C under OS/2 */
-#  undef MSDOS
-#endif
-
-#ifdef MSDOS
-#  ifdef __GNUC__
-     /* DJGPP version 1.09+ on MS-DOS.
-      * The DJGPP 1.09 stat() function must be upgraded before gzip will
-      * fully work.
-      * No need for DIRENT, since <unistd.h> defines POSIX_SOURCE which
-      * implies DIRENT.
-      */
-#    define near
-#  else
-#    define MAXSEG_64K
-#    ifdef __TURBOC__
-#      define NO_OFF_T
-#      ifdef __BORLANDC__
-#        define DIRENT
-#      else
-#        define NO_UTIME
-#      endif
-#    else /* MSC */
-#      define HAVE_SYS_UTIME_H
-#      define NO_UTIME_H
-#    endif
-#  endif
-#  define PATH_SEP2 '\\'
-#  define PATH_SEP3 ':'
-#  define MAX_PATH_LEN  128
-#  define NO_MULTIPLE_DOTS
-#  define MAX_EXT_CHARS 3
-#  define Z_SUFFIX "z"
-#  define NO_CHOWN
-#  define PROTO
-#  define STDC_HEADERS
-#  define NO_SIZE_CHECK
-#  define casemap(c) tolow(c) /* Force file names to lower case */
-#  include <io.h>
-#  define OS_CODE  0x00
-#  define SET_BINARY_MODE(fd) setmode(fd, O_BINARY)
-#  if !defined(NO_ASM) && !defined(ASMV)
-#    define ASMV
-#  endif
-#else
-#  define near
-#endif
-
-#ifdef OS2
-#  define PATH_SEP2 '\\'
-#  define PATH_SEP3 ':'
-#  define MAX_PATH_LEN  260
-#  ifdef OS2FAT
-#    define NO_MULTIPLE_DOTS
-#    define MAX_EXT_CHARS 3
-#    define Z_SUFFIX "z"
-#    define casemap(c) tolow(c)
-#  endif
-#  define NO_CHOWN
-#  define PROTO
-#  define STDC_HEADERS
-#  include <io.h>
-#  define OS_CODE  0x06
-#  define SET_BINARY_MODE(fd) setmode(fd, O_BINARY)
-#  ifdef _MSC_VER
-#    define HAVE_SYS_UTIME_H
-#    define NO_UTIME_H
-#    define MAXSEG_64K
-#    undef near
-#    define near _near
-#  endif
-#  ifdef __EMX__
-#    define HAVE_SYS_UTIME_H
-#    define NO_UTIME_H
-#    define DIRENT
-#    define EXPAND(argc,argv) \
-       {_response(&argc, &argv); _wildcard(&argc, &argv);}
-#  endif
-#  ifdef __BORLANDC__
-#    define DIRENT
-#  endif
-#  ifdef __ZTC__
-#    define NO_DIR
-#    define NO_UTIME_H
-#    include <dos.h>
-#    define EXPAND(argc,argv) \
-       {response_expand(&argc, &argv);}
-#  endif
-#endif
-
-#ifdef WIN32 /* Windows NT */
-#  define HAVE_SYS_UTIME_H
-#  define NO_UTIME_H
-#  define PATH_SEP2 '\\'
-#  define PATH_SEP3 ':'
-#  define MAX_PATH_LEN  260
-#  define NO_CHOWN
-#  define PROTO
-#  define STDC_HEADERS
-#  define SET_BINARY_MODE(fd) setmode(fd, O_BINARY)
-#  include <io.h>
-#  include <malloc.h>
-#  ifdef NTFAT
-#    define NO_MULTIPLE_DOTS
-#    define MAX_EXT_CHARS 3
-#    define Z_SUFFIX "z"
-#    define casemap(c) tolow(c) /* Force file names to lower case */
-#  endif
-#  define OS_CODE  0x0b
-#endif
-
-#ifdef MSDOS
-#  ifdef __TURBOC__
-#    include <alloc.h>
-#    define DYN_ALLOC
-     /* Turbo C 2.0 does not accept static allocations of large arrays */
-     void * fcalloc (unsigned items, unsigned size);
-     void fcfree (void *ptr);
-#  else /* MSC */
-#    include <malloc.h>
-#    define fcalloc(nitems,itemsize) halloc((long)(nitems),(itemsize))
-#    define fcfree(ptr) hfree(ptr)
-#  endif
-#else
-#  ifdef MAXSEG_64K
-#    define fcalloc(items,size) calloc((items),(size))
-#  else
-#    define fcalloc(items,size) malloc((size_t)(items)*(size_t)(size))
-#  endif
-#  define fcfree(ptr) free(ptr)
-#endif
-
-#if defined(VAXC) || defined(VMS)
-#  define PATH_SEP ']'
-#  define PATH_SEP2 ':'
-#  define SUFFIX_SEP ';'
-#  define NO_MULTIPLE_DOTS
-#  define Z_SUFFIX "-gz"
-#  define RECORD_IO 1
-#  define casemap(c) tolow(c)
-#  define OS_CODE  0x02
-#  define OPTIONS_VAR "GZIP_OPT"
-#  define STDC_HEADERS
-#  define NO_UTIME
-#  define EXPAND(argc,argv) vms_expand_args(&argc,&argv);
-#  include <file.h>
-#  define unlink delete
-#  ifdef VAXC
-#    define NO_FCNTL_H
-#    include <unixio.h>
-#  endif
-#endif
-
-#ifdef AMIGA
-#  define PATH_SEP2 ':'
-#  define STDC_HEADERS
-#  define OS_CODE  0x01
-#  define ASMV
-#  ifdef __GNUC__
-#    define DIRENT
-#    define HAVE_UNISTD_H
-#  else /* SASC */
-#    define NO_STDIN_FSTAT
-#    define SYSDIR
-#    define NO_SYMLINK
-#    define NO_CHOWN
-#    define NO_FCNTL_H
-#    include <fcntl.h> /* for read() and write() */
-#    define direct dirent
-     extern void _expand_args(int *argc, char ***argv);
-#    define EXPAND(argc,argv) _expand_args(&argc,&argv);
-#    undef  O_BINARY /* disable useless --ascii option */
-#  endif
-#endif
-
-#if defined(ATARI) || defined(atarist)
-#  ifndef STDC_HEADERS
-#    define STDC_HEADERS
-#    define HAVE_UNISTD_H
-#    define DIRENT
-#  endif
-#  define ASMV
-#  define OS_CODE  0x05
-#  ifdef TOSFS
-#    define PATH_SEP2 '\\'
-#    define PATH_SEP3 ':'
-#    define MAX_PATH_LEN  128
-#    define NO_MULTIPLE_DOTS
-#    define MAX_EXT_CHARS 3
-#    define Z_SUFFIX "z"
-#    define NO_CHOWN
-#    define casemap(c) tolow(c) /* Force file names to lower case */
-#    define NO_SYMLINK
-#  endif
-#endif
-
-#ifdef MACOS
-#  define PATH_SEP ':'
-#  define DYN_ALLOC
-#  define PROTO
-#  define NO_STDIN_FSTAT
-#  define NO_CHOWN
-#  define NO_UTIME
-#  define chmod(file, mode) (0)
-#  define OPEN(name, flags, mode) open(name, flags)
-#  define OS_CODE  0x07
-#  ifdef MPW
-#    define isatty(fd) ((fd) <= 2)
-#  endif
-#endif
-
-#ifdef __50SERIES /* Prime/PRIMOS */
-#  define PATH_SEP '>'
-#  define STDC_HEADERS
-#  define NO_MEMORY_H
-#  define NO_UTIME_H
-#  define NO_UTIME
-#  define NO_CHOWN 
-#  define NO_STDIN_FSTAT 
-#  define NO_SIZE_CHECK 
-#  define NO_SYMLINK
-#  define RECORD_IO  1
-#  define casemap(c)  tolow(c) /* Force file names to lower case */
-#  define put_char(c) put_byte((c) & 0x7F)
-#  define get_char(c) ascii2pascii(get_byte())
-#  define OS_CODE  0x0F    /* temporary, subject to change */
-#  ifdef SIGTERM
-#    undef SIGTERM         /* We don't want a signal handler for SIGTERM */
-#  endif
-#endif
-
-#if defined(pyr) && !defined(NOMEMCPY) /* Pyramid */
-#  define NOMEMCPY /* problem with overlapping copies */
-#endif
-
-#ifdef TOPS20
-#  define OS_CODE  0x0a
-#endif
-
-#ifndef unix
-#  define NO_ST_INO /* don't rely on inode numbers */
-#endif
-
-
-	/* Common defaults */
-
-#ifndef OS_CODE
-#  define OS_CODE  0x03  /* assume Unix */
-#endif
-
-#ifndef PATH_SEP
-#  define PATH_SEP '/'
-#endif
-
-#ifndef casemap
-#  define casemap(c) (c)
-#endif
-
-#ifndef OPTIONS_VAR
-#  define OPTIONS_VAR "GZIP"
-#endif
-
-#ifndef Z_SUFFIX
-#  define Z_SUFFIX ".gz"
-#endif
-
-#ifdef MAX_EXT_CHARS
-#  define MAX_SUFFIX  MAX_EXT_CHARS
-#else
-#  define MAX_SUFFIX  30
-#endif
-
-#ifndef MAKE_LEGAL_NAME
-#  ifdef NO_MULTIPLE_DOTS
-#    define MAKE_LEGAL_NAME(name)   make_simple_name(name)
-#  else
-#    define MAKE_LEGAL_NAME(name)
-#  endif
-#endif
-
-#ifndef MIN_PART
-#  define MIN_PART 3
-   /* keep at least MIN_PART chars between dots in a file name. */
-#endif
-
-#ifndef EXPAND
-#  define EXPAND(argc,argv)
-#endif
-
-#ifndef RECORD_IO
-#  define RECORD_IO 0
-#endif
-
-#ifndef SET_BINARY_MODE
-#  define SET_BINARY_MODE(fd)
-#endif
-
-#ifndef OPEN
-#  define OPEN(name, flags, mode) open(name, flags, mode)
-#endif
-
-#ifndef get_char
-#  define get_char() get_byte()
-#endif
-
-#ifndef put_char
-#  define put_char(c) put_byte(c)
-#endif
