1195972f6Sopenharmony_ci/*
2195972f6Sopenharmony_ci * pppcrypt.c - PPP/DES linkage for MS-CHAP and EAP SRP-SHA1
3195972f6Sopenharmony_ci *
4195972f6Sopenharmony_ci * Extracted from chap_ms.c by James Carlson.
5195972f6Sopenharmony_ci *
6195972f6Sopenharmony_ci * Copyright (c) 1995 Eric Rosenquist.  All rights reserved.
7195972f6Sopenharmony_ci *
8195972f6Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
9195972f6Sopenharmony_ci * modification, are permitted provided that the following conditions
10195972f6Sopenharmony_ci * are met:
11195972f6Sopenharmony_ci *
12195972f6Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright
13195972f6Sopenharmony_ci *    notice, this list of conditions and the following disclaimer.
14195972f6Sopenharmony_ci *
15195972f6Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright
16195972f6Sopenharmony_ci *    notice, this list of conditions and the following disclaimer in
17195972f6Sopenharmony_ci *    the documentation and/or other materials provided with the
18195972f6Sopenharmony_ci *    distribution.
19195972f6Sopenharmony_ci *
20195972f6Sopenharmony_ci * 3. The name(s) of the authors of this software must not be used to
21195972f6Sopenharmony_ci *    endorse or promote products derived from this software without
22195972f6Sopenharmony_ci *    prior written permission.
23195972f6Sopenharmony_ci *
24195972f6Sopenharmony_ci * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
25195972f6Sopenharmony_ci * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
26195972f6Sopenharmony_ci * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
27195972f6Sopenharmony_ci * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
28195972f6Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
29195972f6Sopenharmony_ci * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
30195972f6Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
31195972f6Sopenharmony_ci */
32195972f6Sopenharmony_ci
33195972f6Sopenharmony_ci#include "netif/ppp/ppp_opts.h"
34195972f6Sopenharmony_ci#if PPP_SUPPORT && MSCHAP_SUPPORT /* don't build if not necessary */
35195972f6Sopenharmony_ci
36195972f6Sopenharmony_ci#include "netif/ppp/ppp_impl.h"
37195972f6Sopenharmony_ci
38195972f6Sopenharmony_ci#include "netif/ppp/pppcrypt.h"
39195972f6Sopenharmony_ci
40195972f6Sopenharmony_ci
41195972f6Sopenharmony_cistatic u_char pppcrypt_get_7bits(u_char *input, int startBit) {
42195972f6Sopenharmony_ci	unsigned int word;
43195972f6Sopenharmony_ci
44195972f6Sopenharmony_ci	word  = (unsigned)input[startBit / 8] << 8;
45195972f6Sopenharmony_ci	word |= (unsigned)input[startBit / 8 + 1];
46195972f6Sopenharmony_ci
47195972f6Sopenharmony_ci	word >>= 15 - (startBit % 8 + 7);
48195972f6Sopenharmony_ci
49195972f6Sopenharmony_ci	return word & 0xFE;
50195972f6Sopenharmony_ci}
51195972f6Sopenharmony_ci
52195972f6Sopenharmony_ci/* IN  56 bit DES key missing parity bits
53195972f6Sopenharmony_ci * OUT 64 bit DES key with parity bits added
54195972f6Sopenharmony_ci */
55195972f6Sopenharmony_civoid pppcrypt_56_to_64_bit_key(u_char *key, u_char * des_key) {
56195972f6Sopenharmony_ci	des_key[0] = pppcrypt_get_7bits(key,  0);
57195972f6Sopenharmony_ci	des_key[1] = pppcrypt_get_7bits(key,  7);
58195972f6Sopenharmony_ci	des_key[2] = pppcrypt_get_7bits(key, 14);
59195972f6Sopenharmony_ci	des_key[3] = pppcrypt_get_7bits(key, 21);
60195972f6Sopenharmony_ci	des_key[4] = pppcrypt_get_7bits(key, 28);
61195972f6Sopenharmony_ci	des_key[5] = pppcrypt_get_7bits(key, 35);
62195972f6Sopenharmony_ci	des_key[6] = pppcrypt_get_7bits(key, 42);
63195972f6Sopenharmony_ci	des_key[7] = pppcrypt_get_7bits(key, 49);
64195972f6Sopenharmony_ci}
65195972f6Sopenharmony_ci
66195972f6Sopenharmony_ci#endif /* PPP_SUPPORT && MSCHAP_SUPPORT */
67