Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
mppe.h
00001 /* 00002 * mppe.h - Definitions for MPPE 00003 * 00004 * Copyright (c) 2008 Paul Mackerras. All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions 00008 * are met: 00009 * 00010 * 1. Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * 00013 * 2. Redistributions in binary form must reproduce the above copyright 00014 * notice, this list of conditions and the following disclaimer in 00015 * the documentation and/or other materials provided with the 00016 * distribution. 00017 * 00018 * 3. The name(s) of the authors of this software must not be used to 00019 * endorse or promote products derived from this software without 00020 * prior written permission. 00021 * 00022 * 4. Redistributions of any form whatsoever must retain the following 00023 * acknowledgment: 00024 * "This product includes software developed by Paul Mackerras 00025 * <paulus@samba.org>". 00026 * 00027 * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO 00028 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 00029 * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 00030 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 00031 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 00032 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 00033 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 00034 */ 00035 00036 #include "ppp_opts.h" 00037 #if PPP_SUPPORT && MPPE_SUPPORT /* don't build if not configured for use in ppp_opts.h */ 00038 00039 #ifndef MPPE_H 00040 #define MPPE_H 00041 00042 #include "pppcrypt.h" 00043 00044 #ifdef __cplusplus 00045 extern "C" { 00046 #endif 00047 00048 #define MPPE_PAD 4 /* MPPE growth per frame */ 00049 #define MPPE_MAX_KEY_LEN 16 /* largest key length (128-bit) */ 00050 00051 /* option bits for ccp_options.mppe */ 00052 #define MPPE_OPT_40 0x01 /* 40 bit */ 00053 #define MPPE_OPT_128 0x02 /* 128 bit */ 00054 #define MPPE_OPT_STATEFUL 0x04 /* stateful mode */ 00055 /* unsupported opts */ 00056 #define MPPE_OPT_56 0x08 /* 56 bit */ 00057 #define MPPE_OPT_MPPC 0x10 /* MPPC compression */ 00058 #define MPPE_OPT_D 0x20 /* Unknown */ 00059 #define MPPE_OPT_UNSUPPORTED (MPPE_OPT_56|MPPE_OPT_MPPC|MPPE_OPT_D) 00060 #define MPPE_OPT_UNKNOWN 0x40 /* Bits !defined in RFC 3078 were set */ 00061 00062 /* 00063 * This is not nice ... the alternative is a bitfield struct though. 00064 * And unfortunately, we cannot share the same bits for the option 00065 * names above since C and H are the same bit. We could do a u_int32 00066 * but then we have to do a ppp_htonl() all the time and/or we still need 00067 * to know which octet is which. 00068 */ 00069 #define MPPE_C_BIT 0x01 /* MPPC */ 00070 #define MPPE_D_BIT 0x10 /* Obsolete, usage unknown */ 00071 #define MPPE_L_BIT 0x20 /* 40-bit */ 00072 #define MPPE_S_BIT 0x40 /* 128-bit */ 00073 #define MPPE_M_BIT 0x80 /* 56-bit, not supported */ 00074 #define MPPE_H_BIT 0x01 /* Stateless (in a different byte) */ 00075 00076 /* Does not include H bit; used for least significant octet only. */ 00077 #define MPPE_ALL_BITS (MPPE_D_BIT|MPPE_L_BIT|MPPE_S_BIT|MPPE_M_BIT|MPPE_H_BIT) 00078 00079 /* Build a CI from mppe opts (see RFC 3078) */ 00080 #define MPPE_OPTS_TO_CI(opts, ci) \ 00081 do { \ 00082 u_char *ptr = ci; /* u_char[4] */ \ 00083 \ 00084 /* H bit */ \ 00085 if (opts & MPPE_OPT_STATEFUL) \ 00086 *ptr++ = 0x0; \ 00087 else \ 00088 *ptr++ = MPPE_H_BIT; \ 00089 *ptr++ = 0; \ 00090 *ptr++ = 0; \ 00091 \ 00092 /* S,L bits */ \ 00093 *ptr = 0; \ 00094 if (opts & MPPE_OPT_128) \ 00095 *ptr |= MPPE_S_BIT; \ 00096 if (opts & MPPE_OPT_40) \ 00097 *ptr |= MPPE_L_BIT; \ 00098 /* M,D,C bits not supported */ \ 00099 } while (/* CONSTCOND */ 0) 00100 00101 /* The reverse of the above */ 00102 #define MPPE_CI_TO_OPTS(ci, opts) \ 00103 do { \ 00104 const u_char *ptr = ci; /* u_char[4] */ \ 00105 \ 00106 opts = 0; \ 00107 \ 00108 /* H bit */ \ 00109 if (!(ptr[0] & MPPE_H_BIT)) \ 00110 opts |= MPPE_OPT_STATEFUL; \ 00111 \ 00112 /* S,L bits */ \ 00113 if (ptr[3] & MPPE_S_BIT) \ 00114 opts |= MPPE_OPT_128; \ 00115 if (ptr[3] & MPPE_L_BIT) \ 00116 opts |= MPPE_OPT_40; \ 00117 \ 00118 /* M,D,C bits */ \ 00119 if (ptr[3] & MPPE_M_BIT) \ 00120 opts |= MPPE_OPT_56; \ 00121 if (ptr[3] & MPPE_D_BIT) \ 00122 opts |= MPPE_OPT_D; \ 00123 if (ptr[3] & MPPE_C_BIT) \ 00124 opts |= MPPE_OPT_MPPC; \ 00125 \ 00126 /* Other bits */ \ 00127 if (ptr[0] & ~MPPE_H_BIT) \ 00128 opts |= MPPE_OPT_UNKNOWN; \ 00129 if (ptr[1] || ptr[2]) \ 00130 opts |= MPPE_OPT_UNKNOWN; \ 00131 if (ptr[3] & ~MPPE_ALL_BITS) \ 00132 opts |= MPPE_OPT_UNKNOWN; \ 00133 } while (/* CONSTCOND */ 0) 00134 00135 /* Shared MPPE padding between MSCHAP and MPPE */ 00136 #define SHA1_PAD_SIZE 40 00137 00138 static const u8_t mppe_sha1_pad1[SHA1_PAD_SIZE] = { 00139 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00140 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00141 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00142 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 00143 }; 00144 static const u8_t mppe_sha1_pad2[SHA1_PAD_SIZE] = { 00145 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 00146 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 00147 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 00148 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2 00149 }; 00150 00151 /* 00152 * State for an MPPE (de)compressor. 00153 */ 00154 typedef struct ppp_mppe_state { 00155 ppp_arc4_context arc4; 00156 u8_t master_key[MPPE_MAX_KEY_LEN]; 00157 u8_t session_key[MPPE_MAX_KEY_LEN]; 00158 u8_t keylen; /* key length in bytes */ 00159 /* NB: 128-bit == 16, 40-bit == 8! 00160 * If we want to support 56-bit, the unit has to change to bits 00161 */ 00162 u8_t bits; /* MPPE control bits */ 00163 u16_t ccount; /* 12-bit coherency count (seqno) */ 00164 u16_t sanity_errors; /* take down LCP if too many */ 00165 unsigned int stateful :1; /* stateful mode flag */ 00166 unsigned int discard :1; /* stateful mode packet loss flag */ 00167 } ppp_mppe_state; 00168 00169 void mppe_set_key(ppp_pcb *pcb, ppp_mppe_state *state, u8_t *key); 00170 void mppe_init(ppp_pcb *pcb, ppp_mppe_state *state, u8_t options); 00171 void mppe_comp_reset(ppp_pcb *pcb, ppp_mppe_state *state); 00172 err_t mppe_compress(ppp_pcb *pcb, ppp_mppe_state *state, struct pbuf **pb, u16_t protocol); 00173 void mppe_decomp_reset(ppp_pcb *pcb, ppp_mppe_state *state); 00174 err_t mppe_decompress(ppp_pcb *pcb, ppp_mppe_state *state, struct pbuf **pb); 00175 00176 #ifdef __cplusplus 00177 } 00178 #endif 00179 00180 #endif /* MPPE_H */ 00181 #endif /* PPP_SUPPORT && MPPE_SUPPORT */
Generated on Tue Jul 12 2022 13:54:35 by
