1/*- 2 * Copyright (c) 1997 Gabor Kincses <gabor@acm.org> 3 * 1997 - 2001 Brian Somers <brian@Awfulhak.org> 4 * based on work by Eric Rosenquist 5 * Strata Software Limited. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 12 unchanged lines hidden (view full) --- 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * |
29 * $FreeBSD: head/usr.sbin/ppp/chap_ms.c 98243 2002-06-15 08:03:30Z brian $ |
30 */ 31 32#include <ctype.h> 33#ifdef __FreeBSD__ 34#include <openssl/des.h> 35#include <sha.h> 36#else 37#include <sys/types.h> --- 89 unchanged lines hidden (view full) --- 127 128 DesEncrypt(challenge, ZPasswordHash + 0, response + 0); 129 DesEncrypt(challenge, ZPasswordHash + 7, response + 8); 130 DesEncrypt(challenge, ZPasswordHash + 14, response + 16); 131} 132 133void 134NtPasswordHash(char *key, int keylen, char *hash) |
135{ |
136 MD4_CTX MD4context; 137 138 MD4Init(&MD4context); 139 MD4Update(&MD4context, key, keylen); 140 MD4Final(hash, &MD4context); 141} 142 143void 144HashNtPasswordHash(char *hash, char *hashhash) |
145{ |
146 MD4_CTX MD4context; 147 148 MD4Init(&MD4context); 149 MD4Update(&MD4context, hash, 16); 150 MD4Final(hashhash, &MD4context); 151} 152 153void 154ChallengeHash(char *PeerChallenge, char *AuthenticatorChallenge, 155 char *UserName, int UserNameLen, char *Challenge) 156{ 157 SHA_CTX Context; 158 char Digest[SHA_DIGEST_LENGTH]; 159 char *Name; 160 161 Name = strrchr(UserName, '\\'); |
162 if(NULL == Name) |
163 Name = UserName; 164 else 165 Name++; 166 167 SHA1_Init(&Context); 168 |
169 SHA1_Update(&Context, PeerChallenge, 16); |
170 SHA1_Update(&Context, AuthenticatorChallenge, 16); 171 SHA1_Update(&Context, Name, strlen(Name)); 172 173 SHA1_Final(Digest, &Context); 174 memcpy(Challenge, Digest, 8); 175} 176 177void --- 71 unchanged lines hidden (view full) --- 249 */ 250 HashNtPasswordHash(PasswordHash, PasswordHashHash); 251 252 SHA1_Init(&Context); 253 SHA1_Update(&Context, PasswordHashHash, 16); 254 SHA1_Update(&Context, NTResponse, 24); 255 SHA1_Update(&Context, Magic1, 39); 256 SHA1_Final(Digest, &Context); |
257 ChallengeHash(PeerChallenge, AuthenticatorChallenge, UserName, UserNameLen, |
258 Challenge); 259 SHA1_Init(&Context); 260 SHA1_Update(&Context, Digest, 20); 261 SHA1_Update(&Context, Challenge, 8); 262 SHA1_Update(&Context, Magic2, 41); 263 264 /* 265 * Encode the value of 'Digest' as "S=" followed by --- 4 unchanged lines hidden (view full) --- 270 */ 271 AuthenticatorResponse[0] = 'S'; 272 AuthenticatorResponse[1] = '='; 273 SHA1_End(&Context, AuthenticatorResponse + 2); 274 for (i=2; i<42; i++) 275 AuthenticatorResponse[i] = toupper(AuthenticatorResponse[i]); 276 277} |
278 |
279void 280GetMasterKey(char *PasswordHashHash, char *NTResponse, char *MasterKey) 281{ 282 char Digest[SHA_DIGEST_LENGTH]; 283 SHA_CTX Context; 284 static char Magic1[27] = 285 {0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x74, 286 0x68, 0x65, 0x20, 0x4d, 0x50, 0x50, 0x45, 0x20, 0x4d, --- 131 unchanged lines hidden --- |