$NetBSD: patch-bu,v 1.1.1.1 1999/10/08 04:34:43 dbj Exp $

--- /dev/null	Sat Sep 25 16:45:44 1999
+++ netbsd-1.4/getkey.c	Sat Sep 25 17:06:23 1999
@@ -0,0 +1,51 @@
+/*
+ * Microsoft's Get_Key() per mppe draft by mag <mag@bunuel.tii.matav.hu>
+ */
+#include <sys/param.h>
+#include <sys/systm.h>
+#include "sha.h"
+
+   /*
+    * Pads used in key derivation
+    */
+static unsigned char  SHAPad1[40] =
+        {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+static unsigned char  SHAPad2[40] =
+        {0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2,
+         0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2,
+         0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2,
+         0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2};
+
+   /*
+    * SHAInit(), SHAUpdate() and SHAFinal() functions are an
+    * implementation of Secure Hash Algorithm (SHA-1) [7]. These are
+    * available in public domain or can be licensed from
+    * RSA Data Security, Inc.
+    *
+    * 1) H is 8 bytes long for 40 bit session keys.
+    * 2) H is 16 bytes long for 128 bit session keys.
+    * 3) H' is same as H when this routine is called for the first time
+    *    for the session.
+    * 4) The generated key is returned in H'. This is the "current" key.
+    */
+void
+GetNewKeyFromSHA(StartKey, SessionKey, SessionKeyLength, InterimKey)
+    unsigned char *StartKey;
+    unsigned char *SessionKey;
+    unsigned long SessionKeyLength;
+    unsigned char *InterimKey;
+{
+    SHA_CTX Context;
+    unsigned char Digest[SHA_DIGEST_LENGTH];
+
+    SHA1_Init(&Context);
+    SHA1_Update(&Context, StartKey, SessionKeyLength);
+    SHA1_Update(&Context, SHAPad1, 40);
+    SHA1_Update(&Context, SessionKey, SessionKeyLength);
+    SHA1_Update(&Context, SHAPad2, 40);
+    SHA1_Final(Digest,&Context);
+    memcpy(InterimKey, Digest, SessionKeyLength);
+}
