3 --- pppd/extra_crypto.c Wed Dec 31 16:00:00 1969
4 +++ pppd/extra_crypto.c Thu Jun 24 16:05:42 1999
7 + * Copyright (c) Tim Hockin, Cobalt Networks Inc. and others
9 + * crypto routines used by multiple c files
16 +#include "extra_crypto.h"
23 +/* quick wrapper for easy md4 */
25 +md4(unsigned char *from, int from_len, unsigned char *to)
30 + from_len <<= 3; /* bytes->bits */
34 + MD4Update(&Context, from, from_len);
35 + MD4Final(to, &Context);
39 +/* Microsoft LANMAN Password hashing */
40 +static u_char *MSStdText = (u_char *)"KGS!@#$%"; /* key from rasapi32.dll */
43 +LmPasswordHash(char *password, int len, char *hash)
46 + u_char up_pass[MAX_NT_PASSWORD]; /* max is actually 14 */
48 + /* LANMan password is case insensitive */
49 + BZERO(up_pass, sizeof(up_pass));
50 + for (i = 0; i < len; i++)
51 + up_pass[i] = (u_char)toupper(up_pass[i]);
52 + DesEncrypt(MSStdText, up_pass + 0, hash + 0);
53 + DesEncrypt(MSStdText, up_pass + 7, hash + 8);
57 +NtPasswordHash(char *secret, int secret_len, unsigned char *hash)
60 + u_char unicodePassword[MAX_NT_PASSWORD * 2];
62 + /* Initialize the Unicode version of the secret (== password). */
63 + /* This implicitly supports 8-bit ISO8859/1 characters. */
64 + BZERO(unicodePassword, sizeof(unicodePassword));
65 + for (i = 0; i < secret_len; i++)
66 + unicodePassword[i * 2] = (u_char)secret[i];
68 + /* Unicode is 2 bytes per char */
69 + md4(unicodePassword, secret_len * 2, hash);
73 +static u_char Get7Bits(unsigned char *input, int startBit)
75 + register unsigned int word;
77 + word = (unsigned)input[startBit / 8] << 8;
78 + word |= (unsigned)input[startBit / 8 + 1];
80 + word >>= 15 - (startBit % 8 + 7);
86 +static void MakeKey(unsigned char *key, unsigned char *des_key)
88 + des_key[0] = Get7Bits(key, 0);
89 + des_key[1] = Get7Bits(key, 7);
90 + des_key[2] = Get7Bits(key, 14);
91 + des_key[3] = Get7Bits(key, 21);
92 + des_key[4] = Get7Bits(key, 28);
93 + des_key[5] = Get7Bits(key, 35);
94 + des_key[6] = Get7Bits(key, 42);
95 + des_key[7] = Get7Bits(key, 49);
98 + des_set_odd_parity((des_cblock *)des_key);
104 +/* in == 8-byte string (expanded version of the 56-bit key)
105 + * out == 64-byte string where each byte is either 1 or 0
106 + * Note that the low-order "bit" is always ignored by by setkey()
108 +static void Expand(unsigned char *in, unsigned char *out)
113 + for(i = 0; i < 64; in++){
115 + for(j = 7; j >= 0; j--)
116 + *out++ = (c >> j) & 01;
121 +/* The inverse of Expand
123 +static void Collapse(unsigned char *in, unsigned char *out)
129 + for (i = 0; i < 64; i += 8, out++) {
131 + for (j = 7; j >= 0; j--, in++)
137 +DesEncrypt(unsigned char *clear, unsigned char *key, unsigned char *cipher)
140 + u_char crypt_key[66];
141 + u_char des_input[66];
143 + MakeKey(key, des_key);
145 + Expand(des_key, crypt_key);
148 + Expand(clear, des_input);
149 + encrypt(des_input, 0);
150 + Collapse(des_input, cipher);
152 +#else /* don't USE_CRYPT */
154 +DesEncrypt(unsigned char *clear, unsigned char *key, unsigned char *cipher)
156 + des_cblock des_key;
157 + des_key_schedule key_schedule;
159 + MakeKey(key, des_key);
161 + des_set_key(&des_key, key_schedule);
163 + des_ecb_encrypt((des_cblock *)clear, (des_cblock *)cipher, key_schedule, 1);
165 +#endif /* USE_CRYPT */