This short program illustrates how to use the DS130x_I2C library. My objective is to share the same RTC with Microchip 18F MCU.

Dependencies:   mbed DebugLibrary

Committer:
Yann
Date:
Fri Feb 11 10:17:20 2011 +0000
Revision:
1:995212d326ca
Parent:
0:f30e2135b0db
V0.0.0.2

Who changed what in which revision?

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