ppp_mppe.h 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #define MPPE_PAD 4 /* MPPE growth per frame */
  3. #define MPPE_MAX_KEY_LEN 16 /* largest key length (128-bit) */
  4. /* option bits for ccp_options.mppe */
  5. #define MPPE_OPT_40 0x01 /* 40 bit */
  6. #define MPPE_OPT_128 0x02 /* 128 bit */
  7. #define MPPE_OPT_STATEFUL 0x04 /* stateful mode */
  8. /* unsupported opts */
  9. #define MPPE_OPT_56 0x08 /* 56 bit */
  10. #define MPPE_OPT_MPPC 0x10 /* MPPC compression */
  11. #define MPPE_OPT_D 0x20 /* Unknown */
  12. #define MPPE_OPT_UNSUPPORTED (MPPE_OPT_56|MPPE_OPT_MPPC|MPPE_OPT_D)
  13. #define MPPE_OPT_UNKNOWN 0x40 /* Bits !defined in RFC 3078 were set */
  14. /*
  15. * This is not nice ... the alternative is a bitfield struct though.
  16. * And unfortunately, we cannot share the same bits for the option
  17. * names above since C and H are the same bit. We could do a u_int32
  18. * but then we have to do a htonl() all the time and/or we still need
  19. * to know which octet is which.
  20. */
  21. #define MPPE_C_BIT 0x01 /* MPPC */
  22. #define MPPE_D_BIT 0x10 /* Obsolete, usage unknown */
  23. #define MPPE_L_BIT 0x20 /* 40-bit */
  24. #define MPPE_S_BIT 0x40 /* 128-bit */
  25. #define MPPE_M_BIT 0x80 /* 56-bit, not supported */
  26. #define MPPE_H_BIT 0x01 /* Stateless (in a different byte) */
  27. /* Does not include H bit; used for least significant octet only. */
  28. #define MPPE_ALL_BITS (MPPE_D_BIT|MPPE_L_BIT|MPPE_S_BIT|MPPE_M_BIT|MPPE_H_BIT)
  29. /* Build a CI from mppe opts (see RFC 3078) */
  30. #define MPPE_OPTS_TO_CI(opts, ci) \
  31. do { \
  32. u_char *ptr = ci; /* u_char[4] */ \
  33. \
  34. /* H bit */ \
  35. if (opts & MPPE_OPT_STATEFUL) \
  36. *ptr++ = 0x0; \
  37. else \
  38. *ptr++ = MPPE_H_BIT; \
  39. *ptr++ = 0; \
  40. *ptr++ = 0; \
  41. \
  42. /* S,L bits */ \
  43. *ptr = 0; \
  44. if (opts & MPPE_OPT_128) \
  45. *ptr |= MPPE_S_BIT; \
  46. if (opts & MPPE_OPT_40) \
  47. *ptr |= MPPE_L_BIT; \
  48. /* M,D,C bits not supported */ \
  49. } while (/* CONSTCOND */ 0)
  50. /* The reverse of the above */
  51. #define MPPE_CI_TO_OPTS(ci, opts) \
  52. do { \
  53. u_char *ptr = ci; /* u_char[4] */ \
  54. \
  55. opts = 0; \
  56. \
  57. /* H bit */ \
  58. if (!(ptr[0] & MPPE_H_BIT)) \
  59. opts |= MPPE_OPT_STATEFUL; \
  60. \
  61. /* S,L bits */ \
  62. if (ptr[3] & MPPE_S_BIT) \
  63. opts |= MPPE_OPT_128; \
  64. if (ptr[3] & MPPE_L_BIT) \
  65. opts |= MPPE_OPT_40; \
  66. \
  67. /* M,D,C bits */ \
  68. if (ptr[3] & MPPE_M_BIT) \
  69. opts |= MPPE_OPT_56; \
  70. if (ptr[3] & MPPE_D_BIT) \
  71. opts |= MPPE_OPT_D; \
  72. if (ptr[3] & MPPE_C_BIT) \
  73. opts |= MPPE_OPT_MPPC; \
  74. \
  75. /* Other bits */ \
  76. if (ptr[0] & ~MPPE_H_BIT) \
  77. opts |= MPPE_OPT_UNKNOWN; \
  78. if (ptr[1] || ptr[2]) \
  79. opts |= MPPE_OPT_UNKNOWN; \
  80. if (ptr[3] & ~MPPE_ALL_BITS) \
  81. opts |= MPPE_OPT_UNKNOWN; \
  82. } while (/* CONSTCOND */ 0)