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. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
20 * 3. The name(s) of the authors of this software must not be used to
21 * endorse or promote products derived from this software without
22 * prior written permission.
24 * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
25 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
26 * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
27 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
28 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
29 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
30 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
38 Get7Bits(input
, startBit
)
44 word
= (unsigned)input
[startBit
/ 8] << 8;
45 word
|= (unsigned)input
[startBit
/ 8 + 1];
47 word
>>= 15 - (startBit
% 8 + 7);
54 u_char
*key
; /* IN 56 bit DES key missing parity bits */
55 u_char
*des_key
; /* OUT 64 bit DES key with parity bits added */
57 des_key
[0] = Get7Bits(key
, 0);
58 des_key
[1] = Get7Bits(key
, 7);
59 des_key
[2] = Get7Bits(key
, 14);
60 des_key
[3] = Get7Bits(key
, 21);
61 des_key
[4] = Get7Bits(key
, 28);
62 des_key
[5] = Get7Bits(key
, 35);
63 des_key
[6] = Get7Bits(key
, 42);
64 des_key
[7] = Get7Bits(key
, 49);
67 des_set_odd_parity((des_cblock
*)des_key
);
73 * in == 8-byte string (expanded version of the 56-bit key)
74 * out == 64-byte string where each byte is either 1 or 0
75 * Note that the low-order "bit" is always ignored by by setkey()
85 for (i
= 0; i
< 64; in
++){
87 for (j
= 7; j
>= 0; j
--)
88 *out
++ = (c
>> j
) & 01;
93 /* The inverse of Expand
104 for (i
= 0; i
< 64; i
+= 8, out
++) {
106 for (j
= 7; j
>= 0; j
--, in
++)
117 u_char crypt_key
[66];
119 MakeKey(key
, des_key
);
120 Expand(des_key
, crypt_key
);
122 setkey((const char *)crypt_key
);
129 DesEncrypt(clear
, cipher
)
130 u_char
*clear
; /* IN 8 octets */
131 u_char
*cipher
; /* OUT 8 octets */
133 u_char des_input
[66];
135 Expand(clear
, des_input
);
137 encrypt((char *)des_input
, 0);
140 Collapse(des_input
, cipher
);
145 DesDecrypt(cipher
, clear
)
146 u_char
*cipher
; /* IN 8 octets */
147 u_char
*clear
; /* OUT 8 octets */
149 u_char des_input
[66];
151 Expand(cipher
, des_input
);
153 encrypt((char *)des_input
, 1);
156 Collapse(des_input
, clear
);
160 #else /* USE_CRYPT */
161 static des_key_schedule key_schedule
;
168 MakeKey(key
, des_key
);
169 des_set_key(&des_key
, key_schedule
);
174 DesEncrypt(clear
, key
, cipher
)
175 u_char
*clear
; /* IN 8 octets */
176 u_char
*cipher
; /* OUT 8 octets */
178 des_ecb_encrypt((des_cblock
*)clear
, (des_cblock
*)cipher
,
184 DesDecrypt(cipher
, clear
)
185 u_char
*cipher
; /* IN 8 octets */
186 u_char
*clear
; /* OUT 8 octets */
188 des_ecb_encrypt((des_cblock
*)cipher
, (des_cblock
*)clear
,
193 #endif /* USE_CRYPT */