ppp_mppe.h 4.0 KB

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