eap_pwd_common.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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/ec.h>
  12. #include <openssl/evp.h>
  13. /*
  14. * definition of a finite cyclic group
  15. * TODO: support one based on a prime field
  16. */
  17. typedef struct group_definition_ {
  18. u16 group_num;
  19. EC_GROUP *group;
  20. EC_POINT *pwe;
  21. BIGNUM *order;
  22. BIGNUM *prime;
  23. } EAP_PWD_group;
  24. /*
  25. * EAP-pwd header, included on all payloads
  26. * L(1 bit) | M(1 bit) | exch(6 bits) | total_length(if L is set)
  27. */
  28. #define EAP_PWD_HDR_SIZE 1
  29. #define EAP_PWD_OPCODE_ID_EXCH 1
  30. #define EAP_PWD_OPCODE_COMMIT_EXCH 2
  31. #define EAP_PWD_OPCODE_CONFIRM_EXCH 3
  32. #define EAP_PWD_GET_LENGTH_BIT(x) ((x) & 0x80)
  33. #define EAP_PWD_SET_LENGTH_BIT(x) ((x) |= 0x80)
  34. #define EAP_PWD_GET_MORE_BIT(x) ((x) & 0x40)
  35. #define EAP_PWD_SET_MORE_BIT(x) ((x) |= 0x40)
  36. #define EAP_PWD_GET_EXCHANGE(x) ((x) & 0x3f)
  37. #define EAP_PWD_SET_EXCHANGE(x,y) ((x) |= (y))
  38. /* EAP-pwd-ID payload */
  39. struct eap_pwd_id {
  40. be16 group_num;
  41. u8 random_function;
  42. #define EAP_PWD_DEFAULT_RAND_FUNC 1
  43. u8 prf;
  44. #define EAP_PWD_DEFAULT_PRF 1
  45. u8 token[4];
  46. u8 prep;
  47. #define EAP_PWD_PREP_NONE 0
  48. #define EAP_PWD_PREP_MS 1
  49. u8 identity[0]; /* length inferred from payload */
  50. } STRUCT_PACKED;
  51. /* common routines */
  52. int compute_password_element(EAP_PWD_group *, u16, u8 *, int, u8 *, int, u8 *,
  53. int, u8 *);
  54. int compute_keys(EAP_PWD_group *, BN_CTX *, BIGNUM *, BIGNUM *, BIGNUM *,
  55. u8 *, u8 *, u32 *, u8 *, u8 *, u8 *);
  56. struct crypto_hash * eap_pwd_h_init(void);
  57. void eap_pwd_h_update(struct crypto_hash *hash, const u8 *data, size_t len);
  58. void eap_pwd_h_final(struct crypto_hash *hash, u8 *digest);
  59. #endif /* EAP_PWD_COMMON_H */