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