mppe.h 4.1 KB

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