dev

Dependents:   EthernetInterface

Fork of lwip by mbed official

Committer:
mbed_official
Date:
Fri Jun 22 09:25:39 2012 +0000
Revision:
0:51ac1d130fd4
Initial import from lwip-1.4.0: http://download.savannah.gnu.org/releases/lwip/lwip-1.4.0.zip

Who changed what in which revision?

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