LwIP with PPP & Ethernet integration

Dependents:   NetworkingCoreLib

This is the mbed port of the LwIP stack: http://savannah.nongnu.org/projects/lwip/

It includes contributed content from NXP's port for LPCxxxx devices: http://www.lpcware.com/content/project/lightweight-ip-lwip-networking-stack

Licence

LwIP is licenced under the BSD licence:

Copyright (c) 2001-2004 Swedish Institute of Computer Science. 
All rights reserved. 
Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met: 
1. Redistributions of source code must retain the above copyright notice, 
this list of conditions and the following disclaimer. 
2. Redistributions in binary form must reproduce the above copyright notice, 
this list of conditions and the following disclaimer in the documentation 
and/or other materials provided with the distribution. 
3. The name of the author may not be used to endorse or promote products 
derived from this software without specific prior written permission. 
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
OF SUCH DAMAGE.
Committer:
donatien
Date:
Thu May 24 15:53:48 2012 +0000
Revision:
0:8e01dca41002
Merge with Emilio's LwIp

Who changed what in which revision?

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