Dependents:   TimeZoneDemo EthernetJackTestCode MMEx_Challenge ntp_mem ... more

Committer:
segundo
Date:
Tue Nov 09 20:54:15 2010 +0000
Revision:
0:ac1725ba162c

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
segundo 0:ac1725ba162c 1 /*** WARNING - THIS CODE HAS NOT BEEN FINISHED! ***/
segundo 0:ac1725ba162c 2 /*** The original PPPD code is written in a way to require either the UNIX DES
segundo 0:ac1725ba162c 3 encryption functions encrypt(3) and setkey(3) or the DES library libdes.
segundo 0:ac1725ba162c 4 Since both is not included in lwIP, MSCHAP currently does not work! */
segundo 0:ac1725ba162c 5 /*****************************************************************************
segundo 0:ac1725ba162c 6 * chpms.c - Network MicroSoft Challenge Handshake Authentication Protocol program file.
segundo 0:ac1725ba162c 7 *
segundo 0:ac1725ba162c 8 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
segundo 0:ac1725ba162c 9 * Copyright (c) 1997 by Global Election Systems Inc. All rights reserved.
segundo 0:ac1725ba162c 10 *
segundo 0:ac1725ba162c 11 * The authors hereby grant permission to use, copy, modify, distribute,
segundo 0:ac1725ba162c 12 * and license this software and its documentation for any purpose, provided
segundo 0:ac1725ba162c 13 * that existing copyright notices are retained in all copies and that this
segundo 0:ac1725ba162c 14 * notice and the following disclaimer are included verbatim in any
segundo 0:ac1725ba162c 15 * distributions. No written agreement, license, or royalty fee is required
segundo 0:ac1725ba162c 16 * for any of the authorized uses.
segundo 0:ac1725ba162c 17 *
segundo 0:ac1725ba162c 18 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
segundo 0:ac1725ba162c 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
segundo 0:ac1725ba162c 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
segundo 0:ac1725ba162c 21 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
segundo 0:ac1725ba162c 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
segundo 0:ac1725ba162c 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
segundo 0:ac1725ba162c 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
segundo 0:ac1725ba162c 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
segundo 0:ac1725ba162c 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
segundo 0:ac1725ba162c 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
segundo 0:ac1725ba162c 28 *
segundo 0:ac1725ba162c 29 ******************************************************************************
segundo 0:ac1725ba162c 30 * REVISION HISTORY
segundo 0:ac1725ba162c 31 *
segundo 0:ac1725ba162c 32 * 03-01-01 Marc Boucher <marc@mbsi.ca>
segundo 0:ac1725ba162c 33 * Ported to lwIP.
segundo 0:ac1725ba162c 34 * 97-12-08 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
segundo 0:ac1725ba162c 35 * Original based on BSD chap_ms.c.
segundo 0:ac1725ba162c 36 *****************************************************************************/
segundo 0:ac1725ba162c 37 /*
segundo 0:ac1725ba162c 38 * chap_ms.c - Microsoft MS-CHAP compatible implementation.
segundo 0:ac1725ba162c 39 *
segundo 0:ac1725ba162c 40 * Copyright (c) 1995 Eric Rosenquist, Strata Software Limited.
segundo 0:ac1725ba162c 41 * http://www.strataware.com/
segundo 0:ac1725ba162c 42 *
segundo 0:ac1725ba162c 43 * All rights reserved.
segundo 0:ac1725ba162c 44 *
segundo 0:ac1725ba162c 45 * Redistribution and use in source and binary forms are permitted
segundo 0:ac1725ba162c 46 * provided that the above copyright notice and this paragraph are
segundo 0:ac1725ba162c 47 * duplicated in all such forms and that any documentation,
segundo 0:ac1725ba162c 48 * advertising materials, and other materials related to such
segundo 0:ac1725ba162c 49 * distribution and use acknowledge that the software was developed
segundo 0:ac1725ba162c 50 * by Eric Rosenquist. The name of the author may not be used to
segundo 0:ac1725ba162c 51 * endorse or promote products derived from this software without
segundo 0:ac1725ba162c 52 * specific prior written permission.
segundo 0:ac1725ba162c 53 *
segundo 0:ac1725ba162c 54 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
segundo 0:ac1725ba162c 55 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
segundo 0:ac1725ba162c 56 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
segundo 0:ac1725ba162c 57 */
segundo 0:ac1725ba162c 58
segundo 0:ac1725ba162c 59 /*
segundo 0:ac1725ba162c 60 * Modifications by Lauri Pesonen / lpesonen@clinet.fi, april 1997
segundo 0:ac1725ba162c 61 *
segundo 0:ac1725ba162c 62 * Implemented LANManager type password response to MS-CHAP challenges.
segundo 0:ac1725ba162c 63 * Now pppd provides both NT style and LANMan style blocks, and the
segundo 0:ac1725ba162c 64 * prefered is set by option "ms-lanman". Default is to use NT.
segundo 0:ac1725ba162c 65 * The hash text (StdText) was taken from Win95 RASAPI32.DLL.
segundo 0:ac1725ba162c 66 *
segundo 0:ac1725ba162c 67 * You should also use DOMAIN\\USERNAME as described in README.MSCHAP80
segundo 0:ac1725ba162c 68 */
segundo 0:ac1725ba162c 69
segundo 0:ac1725ba162c 70 #define USE_CRYPT
segundo 0:ac1725ba162c 71
segundo 0:ac1725ba162c 72 #include "lwip/opt.h"
segundo 0:ac1725ba162c 73
segundo 0:ac1725ba162c 74 #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
segundo 0:ac1725ba162c 75
segundo 0:ac1725ba162c 76 #if MSCHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */
segundo 0:ac1725ba162c 77
segundo 0:ac1725ba162c 78 #include "ppp.h"
segundo 0:ac1725ba162c 79 #include "pppdebug.h"
segundo 0:ac1725ba162c 80
segundo 0:ac1725ba162c 81 #include "md4.h"
segundo 0:ac1725ba162c 82 #ifndef USE_CRYPT
segundo 0:ac1725ba162c 83 #include "des.h"
segundo 0:ac1725ba162c 84 #endif
segundo 0:ac1725ba162c 85 #include "chap.h"
segundo 0:ac1725ba162c 86 #include "chpms.h"
segundo 0:ac1725ba162c 87
segundo 0:ac1725ba162c 88 #include <string.h>
segundo 0:ac1725ba162c 89
segundo 0:ac1725ba162c 90
segundo 0:ac1725ba162c 91 /*************************/
segundo 0:ac1725ba162c 92 /*** LOCAL DEFINITIONS ***/
segundo 0:ac1725ba162c 93 /*************************/
segundo 0:ac1725ba162c 94
segundo 0:ac1725ba162c 95
segundo 0:ac1725ba162c 96 /************************/
segundo 0:ac1725ba162c 97 /*** LOCAL DATA TYPES ***/
segundo 0:ac1725ba162c 98 /************************/
segundo 0:ac1725ba162c 99 typedef struct {
segundo 0:ac1725ba162c 100 u_char LANManResp[24];
segundo 0:ac1725ba162c 101 u_char NTResp[24];
segundo 0:ac1725ba162c 102 u_char UseNT; /* If 1, ignore the LANMan response field */
segundo 0:ac1725ba162c 103 } MS_ChapResponse;
segundo 0:ac1725ba162c 104 /* We use MS_CHAP_RESPONSE_LEN, rather than sizeof(MS_ChapResponse),
segundo 0:ac1725ba162c 105 in case this struct gets padded. */
segundo 0:ac1725ba162c 106
segundo 0:ac1725ba162c 107
segundo 0:ac1725ba162c 108
segundo 0:ac1725ba162c 109 /***********************************/
segundo 0:ac1725ba162c 110 /*** LOCAL FUNCTION DECLARATIONS ***/
segundo 0:ac1725ba162c 111 /***********************************/
segundo 0:ac1725ba162c 112
segundo 0:ac1725ba162c 113 /* XXX Don't know what to do with these. */
segundo 0:ac1725ba162c 114 extern void setkey(const char *);
segundo 0:ac1725ba162c 115 extern void encrypt(char *, int);
segundo 0:ac1725ba162c 116
segundo 0:ac1725ba162c 117 static void DesEncrypt (u_char *, u_char *, u_char *);
segundo 0:ac1725ba162c 118 static void MakeKey (u_char *, u_char *);
segundo 0:ac1725ba162c 119
segundo 0:ac1725ba162c 120 #ifdef USE_CRYPT
segundo 0:ac1725ba162c 121 static void Expand (u_char *, u_char *);
segundo 0:ac1725ba162c 122 static void Collapse (u_char *, u_char *);
segundo 0:ac1725ba162c 123 #endif
segundo 0:ac1725ba162c 124
segundo 0:ac1725ba162c 125 static void ChallengeResponse(
segundo 0:ac1725ba162c 126 u_char *challenge, /* IN 8 octets */
segundo 0:ac1725ba162c 127 u_char *pwHash, /* IN 16 octets */
segundo 0:ac1725ba162c 128 u_char *response /* OUT 24 octets */
segundo 0:ac1725ba162c 129 );
segundo 0:ac1725ba162c 130 static void ChapMS_NT(
segundo 0:ac1725ba162c 131 char *rchallenge,
segundo 0:ac1725ba162c 132 int rchallenge_len,
segundo 0:ac1725ba162c 133 char *secret,
segundo 0:ac1725ba162c 134 int secret_len,
segundo 0:ac1725ba162c 135 MS_ChapResponse *response
segundo 0:ac1725ba162c 136 );
segundo 0:ac1725ba162c 137 static u_char Get7Bits(
segundo 0:ac1725ba162c 138 u_char *input,
segundo 0:ac1725ba162c 139 int startBit
segundo 0:ac1725ba162c 140 );
segundo 0:ac1725ba162c 141
segundo 0:ac1725ba162c 142 static void
segundo 0:ac1725ba162c 143 ChallengeResponse( u_char *challenge, /* IN 8 octets */
segundo 0:ac1725ba162c 144 u_char *pwHash, /* IN 16 octets */
segundo 0:ac1725ba162c 145 u_char *response /* OUT 24 octets */)
segundo 0:ac1725ba162c 146 {
segundo 0:ac1725ba162c 147 u_char ZPasswordHash[21];
segundo 0:ac1725ba162c 148
segundo 0:ac1725ba162c 149 BZERO(ZPasswordHash, sizeof(ZPasswordHash));
segundo 0:ac1725ba162c 150 BCOPY(pwHash, ZPasswordHash, 16);
segundo 0:ac1725ba162c 151
segundo 0:ac1725ba162c 152 #if 0
segundo 0:ac1725ba162c 153 log_packet(ZPasswordHash, sizeof(ZPasswordHash), "ChallengeResponse - ZPasswordHash", LOG_DEBUG);
segundo 0:ac1725ba162c 154 #endif
segundo 0:ac1725ba162c 155
segundo 0:ac1725ba162c 156 DesEncrypt(challenge, ZPasswordHash + 0, response + 0);
segundo 0:ac1725ba162c 157 DesEncrypt(challenge, ZPasswordHash + 7, response + 8);
segundo 0:ac1725ba162c 158 DesEncrypt(challenge, ZPasswordHash + 14, response + 16);
segundo 0:ac1725ba162c 159
segundo 0:ac1725ba162c 160 #if 0
segundo 0:ac1725ba162c 161 log_packet(response, 24, "ChallengeResponse - response", LOG_DEBUG);
segundo 0:ac1725ba162c 162 #endif
segundo 0:ac1725ba162c 163 }
segundo 0:ac1725ba162c 164
segundo 0:ac1725ba162c 165
segundo 0:ac1725ba162c 166 #ifdef USE_CRYPT
segundo 0:ac1725ba162c 167 static void
segundo 0:ac1725ba162c 168 DesEncrypt( u_char *clear, /* IN 8 octets */
segundo 0:ac1725ba162c 169 u_char *key, /* IN 7 octets */
segundo 0:ac1725ba162c 170 u_char *cipher /* OUT 8 octets */)
segundo 0:ac1725ba162c 171 {
segundo 0:ac1725ba162c 172 u_char des_key[8];
segundo 0:ac1725ba162c 173 u_char crypt_key[66];
segundo 0:ac1725ba162c 174 u_char des_input[66];
segundo 0:ac1725ba162c 175
segundo 0:ac1725ba162c 176 MakeKey(key, des_key);
segundo 0:ac1725ba162c 177
segundo 0:ac1725ba162c 178 Expand(des_key, crypt_key);
segundo 0:ac1725ba162c 179 setkey((char*)crypt_key);
segundo 0:ac1725ba162c 180
segundo 0:ac1725ba162c 181 #if 0
segundo 0:ac1725ba162c 182 CHAPDEBUG(LOG_INFO, ("DesEncrypt: 8 octet input : %02X%02X%02X%02X%02X%02X%02X%02X\n",
segundo 0:ac1725ba162c 183 clear[0], clear[1], clear[2], clear[3], clear[4], clear[5], clear[6], clear[7]));
segundo 0:ac1725ba162c 184 #endif
segundo 0:ac1725ba162c 185
segundo 0:ac1725ba162c 186 Expand(clear, des_input);
segundo 0:ac1725ba162c 187 encrypt((char*)des_input, 0);
segundo 0:ac1725ba162c 188 Collapse(des_input, cipher);
segundo 0:ac1725ba162c 189
segundo 0:ac1725ba162c 190 #if 0
segundo 0:ac1725ba162c 191 CHAPDEBUG(LOG_INFO, ("DesEncrypt: 8 octet output: %02X%02X%02X%02X%02X%02X%02X%02X\n",
segundo 0:ac1725ba162c 192 cipher[0], cipher[1], cipher[2], cipher[3], cipher[4], cipher[5], cipher[6], cipher[7]));
segundo 0:ac1725ba162c 193 #endif
segundo 0:ac1725ba162c 194 }
segundo 0:ac1725ba162c 195
segundo 0:ac1725ba162c 196 #else /* USE_CRYPT */
segundo 0:ac1725ba162c 197
segundo 0:ac1725ba162c 198 static void
segundo 0:ac1725ba162c 199 DesEncrypt( u_char *clear, /* IN 8 octets */
segundo 0:ac1725ba162c 200 u_char *key, /* IN 7 octets */
segundo 0:ac1725ba162c 201 u_char *cipher /* OUT 8 octets */)
segundo 0:ac1725ba162c 202 {
segundo 0:ac1725ba162c 203 des_cblock des_key;
segundo 0:ac1725ba162c 204 des_key_schedule key_schedule;
segundo 0:ac1725ba162c 205
segundo 0:ac1725ba162c 206 MakeKey(key, des_key);
segundo 0:ac1725ba162c 207
segundo 0:ac1725ba162c 208 des_set_key(&des_key, key_schedule);
segundo 0:ac1725ba162c 209
segundo 0:ac1725ba162c 210 #if 0
segundo 0:ac1725ba162c 211 CHAPDEBUG(LOG_INFO, ("DesEncrypt: 8 octet input : %02X%02X%02X%02X%02X%02X%02X%02X\n",
segundo 0:ac1725ba162c 212 clear[0], clear[1], clear[2], clear[3], clear[4], clear[5], clear[6], clear[7]));
segundo 0:ac1725ba162c 213 #endif
segundo 0:ac1725ba162c 214
segundo 0:ac1725ba162c 215 des_ecb_encrypt((des_cblock *)clear, (des_cblock *)cipher, key_schedule, 1);
segundo 0:ac1725ba162c 216
segundo 0:ac1725ba162c 217 #if 0
segundo 0:ac1725ba162c 218 CHAPDEBUG(LOG_INFO, ("DesEncrypt: 8 octet output: %02X%02X%02X%02X%02X%02X%02X%02X\n",
segundo 0:ac1725ba162c 219 cipher[0], cipher[1], cipher[2], cipher[3], cipher[4], cipher[5], cipher[6], cipher[7]));
segundo 0:ac1725ba162c 220 #endif
segundo 0:ac1725ba162c 221 }
segundo 0:ac1725ba162c 222
segundo 0:ac1725ba162c 223 #endif /* USE_CRYPT */
segundo 0:ac1725ba162c 224
segundo 0:ac1725ba162c 225
segundo 0:ac1725ba162c 226 static u_char
segundo 0:ac1725ba162c 227 Get7Bits( u_char *input, int startBit)
segundo 0:ac1725ba162c 228 {
segundo 0:ac1725ba162c 229 register unsigned int word;
segundo 0:ac1725ba162c 230
segundo 0:ac1725ba162c 231 word = (unsigned)input[startBit / 8] << 8;
segundo 0:ac1725ba162c 232 word |= (unsigned)input[startBit / 8 + 1];
segundo 0:ac1725ba162c 233
segundo 0:ac1725ba162c 234 word >>= 15 - (startBit % 8 + 7);
segundo 0:ac1725ba162c 235
segundo 0:ac1725ba162c 236 return word & 0xFE;
segundo 0:ac1725ba162c 237 }
segundo 0:ac1725ba162c 238
segundo 0:ac1725ba162c 239 #ifdef USE_CRYPT
segundo 0:ac1725ba162c 240
segundo 0:ac1725ba162c 241 /* in == 8-byte string (expanded version of the 56-bit key)
segundo 0:ac1725ba162c 242 * out == 64-byte string where each byte is either 1 or 0
segundo 0:ac1725ba162c 243 * Note that the low-order "bit" is always ignored by by setkey()
segundo 0:ac1725ba162c 244 */
segundo 0:ac1725ba162c 245 static void
segundo 0:ac1725ba162c 246 Expand(u_char *in, u_char *out)
segundo 0:ac1725ba162c 247 {
segundo 0:ac1725ba162c 248 int j, c;
segundo 0:ac1725ba162c 249 int i;
segundo 0:ac1725ba162c 250
segundo 0:ac1725ba162c 251 for(i = 0; i < 64; in++){
segundo 0:ac1725ba162c 252 c = *in;
segundo 0:ac1725ba162c 253 for(j = 7; j >= 0; j--) {
segundo 0:ac1725ba162c 254 *out++ = (c >> j) & 01;
segundo 0:ac1725ba162c 255 }
segundo 0:ac1725ba162c 256 i += 8;
segundo 0:ac1725ba162c 257 }
segundo 0:ac1725ba162c 258 }
segundo 0:ac1725ba162c 259
segundo 0:ac1725ba162c 260 /* The inverse of Expand
segundo 0:ac1725ba162c 261 */
segundo 0:ac1725ba162c 262 static void
segundo 0:ac1725ba162c 263 Collapse(u_char *in, u_char *out)
segundo 0:ac1725ba162c 264 {
segundo 0:ac1725ba162c 265 int j;
segundo 0:ac1725ba162c 266 int i;
segundo 0:ac1725ba162c 267 unsigned int c;
segundo 0:ac1725ba162c 268
segundo 0:ac1725ba162c 269 for (i = 0; i < 64; i += 8, out++) {
segundo 0:ac1725ba162c 270 c = 0;
segundo 0:ac1725ba162c 271 for (j = 7; j >= 0; j--, in++) {
segundo 0:ac1725ba162c 272 c |= *in << j;
segundo 0:ac1725ba162c 273 }
segundo 0:ac1725ba162c 274 *out = c & 0xff;
segundo 0:ac1725ba162c 275 }
segundo 0:ac1725ba162c 276 }
segundo 0:ac1725ba162c 277 #endif
segundo 0:ac1725ba162c 278
segundo 0:ac1725ba162c 279 static void
segundo 0:ac1725ba162c 280 MakeKey( u_char *key, /* IN 56 bit DES key missing parity bits */
segundo 0:ac1725ba162c 281 u_char *des_key /* OUT 64 bit DES key with parity bits added */)
segundo 0:ac1725ba162c 282 {
segundo 0:ac1725ba162c 283 des_key[0] = Get7Bits(key, 0);
segundo 0:ac1725ba162c 284 des_key[1] = Get7Bits(key, 7);
segundo 0:ac1725ba162c 285 des_key[2] = Get7Bits(key, 14);
segundo 0:ac1725ba162c 286 des_key[3] = Get7Bits(key, 21);
segundo 0:ac1725ba162c 287 des_key[4] = Get7Bits(key, 28);
segundo 0:ac1725ba162c 288 des_key[5] = Get7Bits(key, 35);
segundo 0:ac1725ba162c 289 des_key[6] = Get7Bits(key, 42);
segundo 0:ac1725ba162c 290 des_key[7] = Get7Bits(key, 49);
segundo 0:ac1725ba162c 291
segundo 0:ac1725ba162c 292 #ifndef USE_CRYPT
segundo 0:ac1725ba162c 293 des_set_odd_parity((des_cblock *)des_key);
segundo 0:ac1725ba162c 294 #endif
segundo 0:ac1725ba162c 295
segundo 0:ac1725ba162c 296 #if 0
segundo 0:ac1725ba162c 297 CHAPDEBUG(LOG_INFO, ("MakeKey: 56-bit input : %02X%02X%02X%02X%02X%02X%02X\n",
segundo 0:ac1725ba162c 298 key[0], key[1], key[2], key[3], key[4], key[5], key[6]));
segundo 0:ac1725ba162c 299 CHAPDEBUG(LOG_INFO, ("MakeKey: 64-bit output: %02X%02X%02X%02X%02X%02X%02X%02X\n",
segundo 0:ac1725ba162c 300 des_key[0], des_key[1], des_key[2], des_key[3], des_key[4], des_key[5], des_key[6], des_key[7]));
segundo 0:ac1725ba162c 301 #endif
segundo 0:ac1725ba162c 302 }
segundo 0:ac1725ba162c 303
segundo 0:ac1725ba162c 304 static void
segundo 0:ac1725ba162c 305 ChapMS_NT( char *rchallenge,
segundo 0:ac1725ba162c 306 int rchallenge_len,
segundo 0:ac1725ba162c 307 char *secret,
segundo 0:ac1725ba162c 308 int secret_len,
segundo 0:ac1725ba162c 309 MS_ChapResponse *response)
segundo 0:ac1725ba162c 310 {
segundo 0:ac1725ba162c 311 int i;
segundo 0:ac1725ba162c 312 MDstruct md4Context;
segundo 0:ac1725ba162c 313 u_char unicodePassword[MAX_NT_PASSWORD * 2];
segundo 0:ac1725ba162c 314 static int low_byte_first = -1;
segundo 0:ac1725ba162c 315
segundo 0:ac1725ba162c 316 LWIP_UNUSED_ARG(rchallenge_len);
segundo 0:ac1725ba162c 317
segundo 0:ac1725ba162c 318 /* Initialize the Unicode version of the secret (== password). */
segundo 0:ac1725ba162c 319 /* This implicitly supports 8-bit ISO8859/1 characters. */
segundo 0:ac1725ba162c 320 BZERO(unicodePassword, sizeof(unicodePassword));
segundo 0:ac1725ba162c 321 for (i = 0; i < secret_len; i++) {
segundo 0:ac1725ba162c 322 unicodePassword[i * 2] = (u_char)secret[i];
segundo 0:ac1725ba162c 323 }
segundo 0:ac1725ba162c 324 MDbegin(&md4Context);
segundo 0:ac1725ba162c 325 MDupdate(&md4Context, unicodePassword, secret_len * 2 * 8); /* Unicode is 2 bytes/char, *8 for bit count */
segundo 0:ac1725ba162c 326
segundo 0:ac1725ba162c 327 if (low_byte_first == -1) {
segundo 0:ac1725ba162c 328 low_byte_first = (PP_HTONS((unsigned short int)1) != 1);
segundo 0:ac1725ba162c 329 }
segundo 0:ac1725ba162c 330 if (low_byte_first == 0) {
segundo 0:ac1725ba162c 331 /* @todo: arg type - u_long* or u_int* ? */
segundo 0:ac1725ba162c 332 MDreverse((unsigned int*)&md4Context); /* sfb 961105 */
segundo 0:ac1725ba162c 333 }
segundo 0:ac1725ba162c 334
segundo 0:ac1725ba162c 335 MDupdate(&md4Context, NULL, 0); /* Tell MD4 we're done */
segundo 0:ac1725ba162c 336
segundo 0:ac1725ba162c 337 ChallengeResponse((u_char*)rchallenge, (u_char*)md4Context.buffer, response->NTResp);
segundo 0:ac1725ba162c 338 }
segundo 0:ac1725ba162c 339
segundo 0:ac1725ba162c 340 #ifdef MSLANMAN
segundo 0:ac1725ba162c 341 static u_char *StdText = (u_char *)"KGS!@#$%"; /* key from rasapi32.dll */
segundo 0:ac1725ba162c 342
segundo 0:ac1725ba162c 343 static void
segundo 0:ac1725ba162c 344 ChapMS_LANMan( char *rchallenge,
segundo 0:ac1725ba162c 345 int rchallenge_len,
segundo 0:ac1725ba162c 346 char *secret,
segundo 0:ac1725ba162c 347 int secret_len,
segundo 0:ac1725ba162c 348 MS_ChapResponse *response)
segundo 0:ac1725ba162c 349 {
segundo 0:ac1725ba162c 350 int i;
segundo 0:ac1725ba162c 351 u_char UcasePassword[MAX_NT_PASSWORD]; /* max is actually 14 */
segundo 0:ac1725ba162c 352 u_char PasswordHash[16];
segundo 0:ac1725ba162c 353
segundo 0:ac1725ba162c 354 /* LANMan password is case insensitive */
segundo 0:ac1725ba162c 355 BZERO(UcasePassword, sizeof(UcasePassword));
segundo 0:ac1725ba162c 356 for (i = 0; i < secret_len; i++) {
segundo 0:ac1725ba162c 357 UcasePassword[i] = (u_char)toupper(secret[i]);
segundo 0:ac1725ba162c 358 }
segundo 0:ac1725ba162c 359 DesEncrypt( StdText, UcasePassword + 0, PasswordHash + 0 );
segundo 0:ac1725ba162c 360 DesEncrypt( StdText, UcasePassword + 7, PasswordHash + 8 );
segundo 0:ac1725ba162c 361 ChallengeResponse(rchallenge, PasswordHash, response->LANManResp);
segundo 0:ac1725ba162c 362 }
segundo 0:ac1725ba162c 363 #endif
segundo 0:ac1725ba162c 364
segundo 0:ac1725ba162c 365 void
segundo 0:ac1725ba162c 366 ChapMS( chap_state *cstate, char *rchallenge, int rchallenge_len, char *secret, int secret_len)
segundo 0:ac1725ba162c 367 {
segundo 0:ac1725ba162c 368 MS_ChapResponse response;
segundo 0:ac1725ba162c 369 #ifdef MSLANMAN
segundo 0:ac1725ba162c 370 extern int ms_lanman;
segundo 0:ac1725ba162c 371 #endif
segundo 0:ac1725ba162c 372
segundo 0:ac1725ba162c 373 #if 0
segundo 0:ac1725ba162c 374 CHAPDEBUG(LOG_INFO, ("ChapMS: secret is '%.*s'\n", secret_len, secret));
segundo 0:ac1725ba162c 375 #endif
segundo 0:ac1725ba162c 376 BZERO(&response, sizeof(response));
segundo 0:ac1725ba162c 377
segundo 0:ac1725ba162c 378 /* Calculate both always */
segundo 0:ac1725ba162c 379 ChapMS_NT(rchallenge, rchallenge_len, secret, secret_len, &response);
segundo 0:ac1725ba162c 380
segundo 0:ac1725ba162c 381 #ifdef MSLANMAN
segundo 0:ac1725ba162c 382 ChapMS_LANMan(rchallenge, rchallenge_len, secret, secret_len, &response);
segundo 0:ac1725ba162c 383
segundo 0:ac1725ba162c 384 /* prefered method is set by option */
segundo 0:ac1725ba162c 385 response.UseNT = !ms_lanman;
segundo 0:ac1725ba162c 386 #else
segundo 0:ac1725ba162c 387 response.UseNT = 1;
segundo 0:ac1725ba162c 388 #endif
segundo 0:ac1725ba162c 389
segundo 0:ac1725ba162c 390 BCOPY(&response, cstate->response, MS_CHAP_RESPONSE_LEN);
segundo 0:ac1725ba162c 391 cstate->resp_length = MS_CHAP_RESPONSE_LEN;
segundo 0:ac1725ba162c 392 }
segundo 0:ac1725ba162c 393
segundo 0:ac1725ba162c 394 #endif /* MSCHAP_SUPPORT */
segundo 0:ac1725ba162c 395
segundo 0:ac1725ba162c 396 #endif /* PPP_SUPPORT */