2 * pppcrypt.c - PPP/DES linkage for MS-CHAP and EAP SRP-SHA1
4 * Extracted from chap_ms.c by James Carlson.
6 * Copyright (c) 1995 Eric Rosenquist, Strata Software Limited.
7 * http://www.strataware.com/
11 * Redistribution and use in source and binary forms are permitted
12 * provided that the above copyright notice and this paragraph are
13 * duplicated in all such forms and that any documentation,
14 * advertising materials, and other materials related to such
15 * distribution and use acknowledge that the software was developed
16 * by Eric Rosenquist. The name of the author may not be used to
17 * endorse or promote products derived from this software without
18 * specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
22 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30 Get7Bits(input, startBit)
36 word = (unsigned)input[startBit / 8] << 8;
37 word |= (unsigned)input[startBit / 8 + 1];
39 word >>= 15 - (startBit % 8 + 7);
46 u_char *key; /* IN 56 bit DES key missing parity bits */
47 u_char *des_key; /* OUT 64 bit DES key with parity bits added */
49 des_key[0] = Get7Bits(key, 0);
50 des_key[1] = Get7Bits(key, 7);
51 des_key[2] = Get7Bits(key, 14);
52 des_key[3] = Get7Bits(key, 21);
53 des_key[4] = Get7Bits(key, 28);
54 des_key[5] = Get7Bits(key, 35);
55 des_key[6] = Get7Bits(key, 42);
56 des_key[7] = Get7Bits(key, 49);
59 des_set_odd_parity((des_cblock *)des_key);
65 * in == 8-byte string (expanded version of the 56-bit key)
66 * out == 64-byte string where each byte is either 1 or 0
67 * Note that the low-order "bit" is always ignored by by setkey()
77 for (i = 0; i < 64; in++){
79 for (j = 7; j >= 0; j--)
80 *out++ = (c >> j) & 01;
85 /* The inverse of Expand
96 for (i = 0; i < 64; i += 8, out++) {
98 for (j = 7; j >= 0; j--, in++)
109 u_char crypt_key[66];
111 MakeKey(key, des_key);
112 Expand(des_key, crypt_key);
114 setkey((const char *)crypt_key);
121 DesEncrypt(clear, cipher)
122 u_char *clear; /* IN 8 octets */
123 u_char *cipher; /* OUT 8 octets */
125 u_char des_input[66];
127 Expand(clear, des_input);
129 encrypt((char *)des_input, 0);
132 Collapse(des_input, cipher);
137 DesDecrypt(cipher, clear)
138 u_char *cipher; /* IN 8 octets */
139 u_char *clear; /* OUT 8 octets */
141 u_char des_input[66];
143 Expand(cipher, des_input);
145 encrypt((char *)des_input, 1);
148 Collapse(des_input, clear);
152 #else /* USE_CRYPT */
153 static des_key_schedule key_schedule;
160 MakeKey(key, des_key);
161 des_set_key(&des_key, key_schedule);
166 DesEncrypt(clear, key, cipher)
167 u_char *clear; /* IN 8 octets */
168 u_char *cipher; /* OUT 8 octets */
170 des_ecb_encrypt((des_cblock *)clear, (des_cblock *)cipher,
176 DesDecrypt(cipher, clear)
177 u_char *cipher; /* IN 8 octets */
178 u_char *clear; /* OUT 8 octets */
180 des_ecb_encrypt((des_cblock *)cipher, (des_cblock *)clear,
185 #endif /* USE_CRYPT */