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