18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#define MPPE_PAD 4 /* MPPE growth per frame */ 38c2ecf20Sopenharmony_ci#define MPPE_MAX_KEY_LEN 16 /* largest key length (128-bit) */ 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci/* option bits for ccp_options.mppe */ 68c2ecf20Sopenharmony_ci#define MPPE_OPT_40 0x01 /* 40 bit */ 78c2ecf20Sopenharmony_ci#define MPPE_OPT_128 0x02 /* 128 bit */ 88c2ecf20Sopenharmony_ci#define MPPE_OPT_STATEFUL 0x04 /* stateful mode */ 98c2ecf20Sopenharmony_ci/* unsupported opts */ 108c2ecf20Sopenharmony_ci#define MPPE_OPT_56 0x08 /* 56 bit */ 118c2ecf20Sopenharmony_ci#define MPPE_OPT_MPPC 0x10 /* MPPC compression */ 128c2ecf20Sopenharmony_ci#define MPPE_OPT_D 0x20 /* Unknown */ 138c2ecf20Sopenharmony_ci#define MPPE_OPT_UNSUPPORTED (MPPE_OPT_56|MPPE_OPT_MPPC|MPPE_OPT_D) 148c2ecf20Sopenharmony_ci#define MPPE_OPT_UNKNOWN 0x40 /* Bits !defined in RFC 3078 were set */ 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci/* 178c2ecf20Sopenharmony_ci * This is not nice ... the alternative is a bitfield struct though. 188c2ecf20Sopenharmony_ci * And unfortunately, we cannot share the same bits for the option 198c2ecf20Sopenharmony_ci * names above since C and H are the same bit. We could do a u_int32 208c2ecf20Sopenharmony_ci * but then we have to do a htonl() all the time and/or we still need 218c2ecf20Sopenharmony_ci * to know which octet is which. 228c2ecf20Sopenharmony_ci */ 238c2ecf20Sopenharmony_ci#define MPPE_C_BIT 0x01 /* MPPC */ 248c2ecf20Sopenharmony_ci#define MPPE_D_BIT 0x10 /* Obsolete, usage unknown */ 258c2ecf20Sopenharmony_ci#define MPPE_L_BIT 0x20 /* 40-bit */ 268c2ecf20Sopenharmony_ci#define MPPE_S_BIT 0x40 /* 128-bit */ 278c2ecf20Sopenharmony_ci#define MPPE_M_BIT 0x80 /* 56-bit, not supported */ 288c2ecf20Sopenharmony_ci#define MPPE_H_BIT 0x01 /* Stateless (in a different byte) */ 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci/* Does not include H bit; used for least significant octet only. */ 318c2ecf20Sopenharmony_ci#define MPPE_ALL_BITS (MPPE_D_BIT|MPPE_L_BIT|MPPE_S_BIT|MPPE_M_BIT|MPPE_H_BIT) 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci/* Build a CI from mppe opts (see RFC 3078) */ 348c2ecf20Sopenharmony_ci#define MPPE_OPTS_TO_CI(opts, ci) \ 358c2ecf20Sopenharmony_ci do { \ 368c2ecf20Sopenharmony_ci u_char *ptr = ci; /* u_char[4] */ \ 378c2ecf20Sopenharmony_ci \ 388c2ecf20Sopenharmony_ci /* H bit */ \ 398c2ecf20Sopenharmony_ci if (opts & MPPE_OPT_STATEFUL) \ 408c2ecf20Sopenharmony_ci *ptr++ = 0x0; \ 418c2ecf20Sopenharmony_ci else \ 428c2ecf20Sopenharmony_ci *ptr++ = MPPE_H_BIT; \ 438c2ecf20Sopenharmony_ci *ptr++ = 0; \ 448c2ecf20Sopenharmony_ci *ptr++ = 0; \ 458c2ecf20Sopenharmony_ci \ 468c2ecf20Sopenharmony_ci /* S,L bits */ \ 478c2ecf20Sopenharmony_ci *ptr = 0; \ 488c2ecf20Sopenharmony_ci if (opts & MPPE_OPT_128) \ 498c2ecf20Sopenharmony_ci *ptr |= MPPE_S_BIT; \ 508c2ecf20Sopenharmony_ci if (opts & MPPE_OPT_40) \ 518c2ecf20Sopenharmony_ci *ptr |= MPPE_L_BIT; \ 528c2ecf20Sopenharmony_ci /* M,D,C bits not supported */ \ 538c2ecf20Sopenharmony_ci } while (/* CONSTCOND */ 0) 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci/* The reverse of the above */ 568c2ecf20Sopenharmony_ci#define MPPE_CI_TO_OPTS(ci, opts) \ 578c2ecf20Sopenharmony_ci do { \ 588c2ecf20Sopenharmony_ci u_char *ptr = ci; /* u_char[4] */ \ 598c2ecf20Sopenharmony_ci \ 608c2ecf20Sopenharmony_ci opts = 0; \ 618c2ecf20Sopenharmony_ci \ 628c2ecf20Sopenharmony_ci /* H bit */ \ 638c2ecf20Sopenharmony_ci if (!(ptr[0] & MPPE_H_BIT)) \ 648c2ecf20Sopenharmony_ci opts |= MPPE_OPT_STATEFUL; \ 658c2ecf20Sopenharmony_ci \ 668c2ecf20Sopenharmony_ci /* S,L bits */ \ 678c2ecf20Sopenharmony_ci if (ptr[3] & MPPE_S_BIT) \ 688c2ecf20Sopenharmony_ci opts |= MPPE_OPT_128; \ 698c2ecf20Sopenharmony_ci if (ptr[3] & MPPE_L_BIT) \ 708c2ecf20Sopenharmony_ci opts |= MPPE_OPT_40; \ 718c2ecf20Sopenharmony_ci \ 728c2ecf20Sopenharmony_ci /* M,D,C bits */ \ 738c2ecf20Sopenharmony_ci if (ptr[3] & MPPE_M_BIT) \ 748c2ecf20Sopenharmony_ci opts |= MPPE_OPT_56; \ 758c2ecf20Sopenharmony_ci if (ptr[3] & MPPE_D_BIT) \ 768c2ecf20Sopenharmony_ci opts |= MPPE_OPT_D; \ 778c2ecf20Sopenharmony_ci if (ptr[3] & MPPE_C_BIT) \ 788c2ecf20Sopenharmony_ci opts |= MPPE_OPT_MPPC; \ 798c2ecf20Sopenharmony_ci \ 808c2ecf20Sopenharmony_ci /* Other bits */ \ 818c2ecf20Sopenharmony_ci if (ptr[0] & ~MPPE_H_BIT) \ 828c2ecf20Sopenharmony_ci opts |= MPPE_OPT_UNKNOWN; \ 838c2ecf20Sopenharmony_ci if (ptr[1] || ptr[2]) \ 848c2ecf20Sopenharmony_ci opts |= MPPE_OPT_UNKNOWN; \ 858c2ecf20Sopenharmony_ci if (ptr[3] & ~MPPE_ALL_BITS) \ 868c2ecf20Sopenharmony_ci opts |= MPPE_OPT_UNKNOWN; \ 878c2ecf20Sopenharmony_ci } while (/* CONSTCOND */ 0) 88