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