eap_pwd_common.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * EAP server/peer: EAP-pwd shared definitions
  3. * Copyright (c) 2009, Dan Harkins <dharkins@lounge.org>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #ifndef EAP_PWD_COMMON_H
  9. #define EAP_PWD_COMMON_H
  10. #include <openssl/bn.h>
  11. #include <openssl/sha.h>
  12. #include <openssl/ec.h>
  13. #include <openssl/evp.h>
  14. #include <openssl/hmac.h>
  15. /*
  16. * definition of a finite cyclic group
  17. * TODO: support one based on a prime field
  18. */
  19. typedef struct group_definition_ {
  20. u16 group_num;
  21. EC_GROUP *group;
  22. EC_POINT *pwe;
  23. BIGNUM *order;
  24. BIGNUM *prime;
  25. } EAP_PWD_group;
  26. /*
  27. * EAP-pwd header, included on all payloads
  28. * L(1 bit) | M(1 bit) | exch(6 bits) | total_length(if L is set)
  29. */
  30. #define EAP_PWD_HDR_SIZE 1
  31. #define EAP_PWD_OPCODE_ID_EXCH 1
  32. #define EAP_PWD_OPCODE_COMMIT_EXCH 2
  33. #define EAP_PWD_OPCODE_CONFIRM_EXCH 3
  34. #define EAP_PWD_GET_LENGTH_BIT(x) ((x) & 0x80)
  35. #define EAP_PWD_SET_LENGTH_BIT(x) ((x) |= 0x80)
  36. #define EAP_PWD_GET_MORE_BIT(x) ((x) & 0x40)
  37. #define EAP_PWD_SET_MORE_BIT(x) ((x) |= 0x40)
  38. #define EAP_PWD_GET_EXCHANGE(x) ((x) & 0x3f)
  39. #define EAP_PWD_SET_EXCHANGE(x,y) ((x) |= (y))
  40. /* EAP-pwd-ID payload */
  41. struct eap_pwd_id {
  42. be16 group_num;
  43. u8 random_function;
  44. #define EAP_PWD_DEFAULT_RAND_FUNC 1
  45. u8 prf;
  46. #define EAP_PWD_DEFAULT_PRF 1
  47. u8 token[4];
  48. u8 prep;
  49. #define EAP_PWD_PREP_NONE 0
  50. #define EAP_PWD_PREP_MS 1
  51. u8 identity[0]; /* length inferred from payload */
  52. } STRUCT_PACKED;
  53. /* common routines */
  54. int compute_password_element(EAP_PWD_group *, u16, u8 *, int, u8 *, int, u8 *,
  55. int, u8 *);
  56. int compute_keys(EAP_PWD_group *, BN_CTX *, BIGNUM *, BIGNUM *, BIGNUM *,
  57. u8 *, u8 *, u32 *, u8 *, u8 *);
  58. void H_Init(HMAC_CTX *);
  59. void H_Update(HMAC_CTX *, const u8 *, int);
  60. void H_Final(HMAC_CTX *, u8 *);
  61. #endif /* EAP_PWD_COMMON_H */