]> git.ozlabs.org Git - ppp.git/blob - pppd/mppe.h
CI: Updated the 'checkout' actions that were using Node.js 16 to Node.js 20. (#489)
[ppp.git] / pppd / mppe.h
1 /*
2  * mppe.h - Definitions for MPPE
3  *
4  * Copyright (c) 2008 Paul Mackerras. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  *
18  * 3. The name(s) of the authors of this software must not be used to
19  *    endorse or promote products derived from this software without
20  *    prior written permission.
21  *
22  * 4. Redistributions of any form whatsoever must retain the following
23  *    acknowledgment:
24  *    "This product includes software developed by Paul Mackerras
25  *     <paulus@samba.org>".
26  *
27  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
28  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
29  * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
30  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
31  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
32  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
33  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
34  */
35 #ifndef PPP_MPPE_H
36 #define PPP_MPPE_H
37
38 #include "pppdconf.h"
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44
45 #define MPPE_PAD                4       /* MPPE growth per frame */
46 #define MPPE_MAX_KEY_SIZE       32      /* Largest key length */
47 #define MPPE_MAX_KEY_LEN       16      /* Largest key size accepted by the kernel */
48
49 /* option bits for ccp_options.mppe */
50 #define MPPE_OPT_40             0x01    /* 40 bit */
51 #define MPPE_OPT_128            0x02    /* 128 bit */
52 #define MPPE_OPT_STATEFUL       0x04    /* stateful mode */
53 /* unsupported opts */
54 #define MPPE_OPT_56             0x08    /* 56 bit */
55 #define MPPE_OPT_MPPC           0x10    /* MPPC compression */
56 #define MPPE_OPT_D              0x20    /* Unknown */
57 #define MPPE_OPT_UNSUPPORTED (MPPE_OPT_56|MPPE_OPT_MPPC|MPPE_OPT_D)
58 #define MPPE_OPT_UNKNOWN        0x40    /* Bits !defined in RFC 3078 were set */
59
60 /*
61  * This is not nice ... the alternative is a bitfield struct though.
62  * And unfortunately, we cannot share the same bits for the option
63  * names above since C and H are the same bit.  We could do a u_int32
64  * but then we have to do a htonl() all the time and/or we still need
65  * to know which octet is which.
66  */
67 #define MPPE_C_BIT              0x01    /* MPPC */
68 #define MPPE_D_BIT              0x10    /* Obsolete, usage unknown */
69 #define MPPE_L_BIT              0x20    /* 40-bit */
70 #define MPPE_S_BIT              0x40    /* 128-bit */
71 #define MPPE_M_BIT              0x80    /* 56-bit, not supported */
72 #define MPPE_H_BIT              0x01    /* Stateless (in a different byte) */
73
74 /* Does not include H bit; used for least significant octet only. */
75 #define MPPE_ALL_BITS (MPPE_D_BIT|MPPE_L_BIT|MPPE_S_BIT|MPPE_M_BIT|MPPE_H_BIT)
76
77 /* Build a CI from mppe opts (see RFC 3078) */
78 #define MPPE_OPTS_TO_CI(opts, ci)               \
79     do {                                        \
80         unsigned char *ptr = ci; /* unsigned char[4] */ \
81                                                 \
82         /* H bit */                             \
83         if (opts & MPPE_OPT_STATEFUL)           \
84             *ptr++ = 0x0;                       \
85         else                                    \
86             *ptr++ = MPPE_H_BIT;                \
87         *ptr++ = 0;                             \
88         *ptr++ = 0;                             \
89                                                 \
90         /* S,L bits */                          \
91         *ptr = 0;                               \
92         if (opts & MPPE_OPT_128)                \
93             *ptr |= MPPE_S_BIT;                 \
94         if (opts & MPPE_OPT_40)                 \
95             *ptr |= MPPE_L_BIT;                 \
96         /* M,D,C bits not supported */          \
97     } while (/* CONSTCOND */ 0)
98
99 /* The reverse of the above */
100 #define MPPE_CI_TO_OPTS(ci, opts)               \
101     do {                                        \
102         unsigned char *ptr = ci; /* unsigned char[4] */ \
103                                                 \
104         opts = 0;                               \
105                                                 \
106         /* H bit */                             \
107         if (!(ptr[0] & MPPE_H_BIT))             \
108             opts |= MPPE_OPT_STATEFUL;          \
109                                                 \
110         /* S,L bits */                          \
111         if (ptr[3] & MPPE_S_BIT)                \
112             opts |= MPPE_OPT_128;               \
113         if (ptr[3] & MPPE_L_BIT)                \
114             opts |= MPPE_OPT_40;                \
115                                                 \
116         /* M,D,C bits */                        \
117         if (ptr[3] & MPPE_M_BIT)                \
118             opts |= MPPE_OPT_56;                \
119         if (ptr[3] & MPPE_D_BIT)                \
120             opts |= MPPE_OPT_D;                 \
121         if (ptr[3] & MPPE_C_BIT)                \
122             opts |= MPPE_OPT_MPPC;              \
123                                                 \
124         /* Other bits */                        \
125         if (ptr[0] & ~MPPE_H_BIT)               \
126             opts |= MPPE_OPT_UNKNOWN;           \
127         if (ptr[1] || ptr[2])                   \
128             opts |= MPPE_OPT_UNKNOWN;           \
129         if (ptr[3] & ~MPPE_ALL_BITS)            \
130             opts |= MPPE_OPT_UNKNOWN;           \
131     } while (/* CONSTCOND */ 0)
132
133
134 #if PPP_WITH_MPPE
135
136 /* These values are the RADIUS attribute values--see RFC 2548. */
137 #define MPPE_ENC_POL_ENC_ALLOWED 1
138 #define MPPE_ENC_POL_ENC_REQUIRED 2
139 #define MPPE_ENC_TYPES_RC4_40 2
140 #define MPPE_ENC_TYPES_RC4_128 4
141
142 /* used by plugins (using above values) */
143 void mppe_set_enc_types (int policy, int types);
144
145 /*
146  * Set the MPPE send and recv keys. NULL values for keys are ignored
147  *   and input values are cleared to avoid leaving them on the stack
148  */
149 void mppe_set_keys(unsigned char *send_key, unsigned char *recv_key, int keylen);
150
151 /*
152  * Get the MPPE recv key
153  */
154 int mppe_get_recv_key(unsigned char *recv_key, int length);
155
156 /*
157  * Get the MPPE send key
158  */
159 int mppe_get_send_key(unsigned char *send_key, int length);
160
161 /*
162  * Clear the MPPE keys
163  */
164 void mppe_clear_keys(void);
165
166 /*
167  * Check if the MPPE keys are set
168  */
169 bool mppe_keys_isset(void);
170
171 /*
172  * Set mppe_xxxx_key from NT Password Hash Hash (MSCHAPv1), see RFC3079
173  */
174 void mppe_set_chapv1(unsigned char *rchallenge, unsigned char *PasswordHashHash);
175
176 /*
177  * Set the mppe_xxxx_key from MS-CHAP-v2 credentials, see RFC3079
178  */
179 void mppe_set_chapv2(unsigned char *PasswordHashHash,
180                     unsigned char *NTResponse, int IsServer);
181
182 #endif  // #ifdef PPP_WITH_MPPE
183
184 #ifdef __cplusplus
185 }
186 #endif
187
188 #endif  // #ifdef PPP_MPPE_H