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