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