]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/chap_ms.c
MD4Update takes bytes not bits! Now the regression test of the README.MSCHAP80
[ppp.git] / pppd / chap_ms.c
index c46ca13f7022eb0f4d3871284286eaa9fd2a7de5..114b951a40d936161cacde8904fcc0392a6db961 100644 (file)
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: chap_ms.c,v 1.5 1997/11/27 06:08:10 paulus Exp $";
+static char rcsid[] = "$Id: chap_ms.c,v 1.11 1998/11/24 19:30:38 christos Exp $";
 #endif
 
 #ifdef CHAPMS
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
 #include <sys/types.h>
 #include <sys/time.h>
 #include <syslog.h>
 #include <unistd.h>
+#ifdef HAVE_CRYPT_H
+#include <crypt.h>
+#endif
 
 #include "pppd.h"
 #include "chap.h"
@@ -77,6 +81,11 @@ static void  Expand __P((u_char *, u_char *));
 static void    Collapse __P((u_char *, u_char *));
 #endif
 
+#ifdef MSLANMAN
+bool   ms_lanman = 0;          /* Use LanMan password instead of NT */
+                               /* Has meaning only with MS-CHAP challenges */
+#endif
+
 static void
 ChallengeResponse(challenge, pwHash, response)
     u_char *challenge; /* IN   8 octets */
@@ -253,9 +262,8 @@ ChapMS_NT(rchallenge, rchallenge_len, secret, secret_len, response)
 {
     int                        i;
     MD4_CTX            md4Context;
-    u_short            hash[MD4_SIGNATURE_SIZE/sizeof(u_short)];
+    u_char             hash[MD4_SIGNATURE_SIZE];
     u_char             unicodePassword[MAX_NT_PASSWORD * 2];
-    static int         low_byte_first = -1;
 
     /* Initialize the Unicode version of the secret (== password). */
     /* This implicitly supports 8-bit ISO8859/1 characters. */
@@ -264,18 +272,11 @@ ChapMS_NT(rchallenge, rchallenge_len, secret, secret_len, response)
        unicodePassword[i * 2] = (u_char)secret[i];
 
     MD4Init(&md4Context);
-    MD4Update(&md4Context, unicodePassword, secret_len * 2 * 8);       /* Unicode is 2 bytes/char, *8 for bit count */
+    MD4Update(&md4Context, unicodePassword, secret_len * 2);
 
-    MD4Final((u_char *) hash, &md4Context);    /* Tell MD4 we're done */
+    MD4Final(hash, &md4Context);       /* Tell MD4 we're done */
 
-    if (low_byte_first == -1)
-       low_byte_first = (htons((unsigned short int)1) != 1);
-    if (low_byte_first == 0) {
-       for (i = 0; i < MD4_SIGNATURE_SIZE; i += sizeof(u_short))
-               hash[i] = htons(hash[i]);
-    }
-
-    ChallengeResponse(rchallenge, (u_char *)hash, response->NTResp);
+    ChallengeResponse(rchallenge, hash, response->NTResp);
 }
 
 #ifdef MSLANMAN
@@ -312,9 +313,6 @@ ChapMS(cstate, rchallenge, rchallenge_len, secret, secret_len)
     int secret_len;
 {
     MS_ChapResponse    response;
-#ifdef MSLANMAN
-    extern int ms_lanman;
-#endif
 
 #if 0
     CHAPDEBUG((LOG_INFO, "ChapMS: secret is '%.*s'", secret_len, secret));