mppe.h revision 1.4 1 1.4 christos /* $NetBSD: mppe.h,v 1.4 2014/10/25 21:11:37 christos Exp $ */
2 1.2 christos
3 1.1 christos /*
4 1.1 christos * mppe.h - Definitions for MPPE
5 1.1 christos *
6 1.1 christos * Copyright (c) 2008 Paul Mackerras. All rights reserved.
7 1.1 christos *
8 1.1 christos * Redistribution and use in source and binary forms, with or without
9 1.1 christos * modification, are permitted provided that the following conditions
10 1.1 christos * are met:
11 1.1 christos *
12 1.1 christos * 1. Redistributions of source code must retain the above copyright
13 1.1 christos * notice, this list of conditions and the following disclaimer.
14 1.1 christos *
15 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 christos * notice, this list of conditions and the following disclaimer in
17 1.1 christos * the documentation and/or other materials provided with the
18 1.1 christos * distribution.
19 1.1 christos *
20 1.1 christos * 3. The name(s) of the authors of this software must not be used to
21 1.1 christos * endorse or promote products derived from this software without
22 1.1 christos * prior written permission.
23 1.1 christos *
24 1.1 christos * 4. Redistributions of any form whatsoever must retain the following
25 1.1 christos * acknowledgment:
26 1.1 christos * "This product includes software developed by Paul Mackerras
27 1.1 christos * <paulus (at) samba.org>".
28 1.1 christos *
29 1.1 christos * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
30 1.1 christos * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
31 1.1 christos * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
32 1.1 christos * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
33 1.1 christos * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
34 1.1 christos * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
35 1.1 christos * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
36 1.1 christos */
37 1.1 christos
38 1.1 christos #define MPPE_PAD 4 /* MPPE growth per frame */
39 1.1 christos #define MPPE_MAX_KEY_LEN 16 /* largest key length (128-bit) */
40 1.1 christos
41 1.1 christos /* option bits for ccp_options.mppe */
42 1.1 christos #define MPPE_OPT_40 0x01 /* 40 bit */
43 1.1 christos #define MPPE_OPT_128 0x02 /* 128 bit */
44 1.1 christos #define MPPE_OPT_STATEFUL 0x04 /* stateful mode */
45 1.1 christos /* unsupported opts */
46 1.1 christos #define MPPE_OPT_56 0x08 /* 56 bit */
47 1.1 christos #define MPPE_OPT_MPPC 0x10 /* MPPC compression */
48 1.1 christos #define MPPE_OPT_D 0x20 /* Unknown */
49 1.1 christos #define MPPE_OPT_UNSUPPORTED (MPPE_OPT_56|MPPE_OPT_MPPC|MPPE_OPT_D)
50 1.1 christos #define MPPE_OPT_UNKNOWN 0x40 /* Bits !defined in RFC 3078 were set */
51 1.1 christos
52 1.1 christos /*
53 1.1 christos * This is not nice ... the alternative is a bitfield struct though.
54 1.1 christos * And unfortunately, we cannot share the same bits for the option
55 1.1 christos * names above since C and H are the same bit. We could do a u_int32
56 1.1 christos * but then we have to do a htonl() all the time and/or we still need
57 1.1 christos * to know which octet is which.
58 1.1 christos */
59 1.1 christos #define MPPE_C_BIT 0x01 /* MPPC */
60 1.1 christos #define MPPE_D_BIT 0x10 /* Obsolete, usage unknown */
61 1.1 christos #define MPPE_L_BIT 0x20 /* 40-bit */
62 1.1 christos #define MPPE_S_BIT 0x40 /* 128-bit */
63 1.1 christos #define MPPE_M_BIT 0x80 /* 56-bit, not supported */
64 1.1 christos #define MPPE_H_BIT 0x01 /* Stateless (in a different byte) */
65 1.1 christos
66 1.1 christos /* Does not include H bit; used for least significant octet only. */
67 1.1 christos #define MPPE_ALL_BITS (MPPE_D_BIT|MPPE_L_BIT|MPPE_S_BIT|MPPE_M_BIT|MPPE_H_BIT)
68 1.1 christos
69 1.1 christos /* Build a CI from mppe opts (see RFC 3078) */
70 1.1 christos #define MPPE_OPTS_TO_CI(opts, ci) \
71 1.1 christos do { \
72 1.1 christos u_char *ptr = ci; /* u_char[4] */ \
73 1.1 christos \
74 1.1 christos /* H bit */ \
75 1.1 christos if (opts & MPPE_OPT_STATEFUL) \
76 1.1 christos *ptr++ = 0x0; \
77 1.1 christos else \
78 1.1 christos *ptr++ = MPPE_H_BIT; \
79 1.1 christos *ptr++ = 0; \
80 1.1 christos *ptr++ = 0; \
81 1.1 christos \
82 1.1 christos /* S,L bits */ \
83 1.1 christos *ptr = 0; \
84 1.1 christos if (opts & MPPE_OPT_128) \
85 1.1 christos *ptr |= MPPE_S_BIT; \
86 1.1 christos if (opts & MPPE_OPT_40) \
87 1.1 christos *ptr |= MPPE_L_BIT; \
88 1.1 christos /* M,D,C bits not supported */ \
89 1.1 christos } while (/* CONSTCOND */ 0)
90 1.1 christos
91 1.1 christos /* The reverse of the above */
92 1.1 christos #define MPPE_CI_TO_OPTS(ci, opts) \
93 1.1 christos do { \
94 1.1 christos u_char *ptr = ci; /* u_char[4] */ \
95 1.1 christos \
96 1.1 christos opts = 0; \
97 1.1 christos \
98 1.1 christos /* H bit */ \
99 1.1 christos if (!(ptr[0] & MPPE_H_BIT)) \
100 1.1 christos opts |= MPPE_OPT_STATEFUL; \
101 1.1 christos \
102 1.1 christos /* S,L bits */ \
103 1.1 christos if (ptr[3] & MPPE_S_BIT) \
104 1.1 christos opts |= MPPE_OPT_128; \
105 1.1 christos if (ptr[3] & MPPE_L_BIT) \
106 1.1 christos opts |= MPPE_OPT_40; \
107 1.1 christos \
108 1.1 christos /* M,D,C bits */ \
109 1.1 christos if (ptr[3] & MPPE_M_BIT) \
110 1.1 christos opts |= MPPE_OPT_56; \
111 1.1 christos if (ptr[3] & MPPE_D_BIT) \
112 1.1 christos opts |= MPPE_OPT_D; \
113 1.1 christos if (ptr[3] & MPPE_C_BIT) \
114 1.1 christos opts |= MPPE_OPT_MPPC; \
115 1.1 christos \
116 1.1 christos /* Other bits */ \
117 1.1 christos if (ptr[0] & ~MPPE_H_BIT) \
118 1.1 christos opts |= MPPE_OPT_UNKNOWN; \
119 1.1 christos if (ptr[1] || ptr[2]) \
120 1.1 christos opts |= MPPE_OPT_UNKNOWN; \
121 1.1 christos if (ptr[3] & ~MPPE_ALL_BITS) \
122 1.1 christos opts |= MPPE_OPT_UNKNOWN; \
123 1.1 christos } while (/* CONSTCOND */ 0)
124