SNMP agent attached to SPI slave

Dependencies:   mbed

Committer:
lorcansmith
Date:
Mon Aug 13 15:07:40 2012 +0000
Revision:
0:2a53a4c3238c
v1.1 release includes ioAlarm traps

Who changed what in which revision?

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