automake build system
[mech_eap.orig] / src / eap_common / eap_pwd_common.h
1 /*
2  * EAP server/peer: EAP-pwd shared definitions
3  * Copyright (c) 2009, Dan Harkins <dharkins@lounge.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the BSD license.
7  *
8  * Alternatively, this software may be distributed under the terms of the
9  * GNU General Public License version 2 as published by the Free Software
10  * Foundation.
11  *
12  * See README and COPYING for more details.
13  */
14
15 #ifndef EAP_PWD_COMMON_H
16 #define EAP_PWD_COMMON_H
17
18 #include <openssl/bn.h>
19 #include <openssl/sha.h>
20 #include <openssl/ec.h>
21 #include <openssl/evp.h>
22 #include <openssl/hmac.h>
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 /*
29  * definition of a finite cyclic group
30  * TODO: support one based on a prime field
31  */
32 typedef struct group_definition_ {
33         u16 group_num;
34         EC_GROUP *group;
35         EC_POINT *pwe;
36         BIGNUM *order;
37         BIGNUM *prime;
38 } EAP_PWD_group;
39
40 /*
41  * EAP-pwd header, included on all payloads
42  */
43 struct eap_pwd_hdr {
44         u8 l_bit:1;
45         u8 m_bit:1;
46         u8 exch:6;
47         u8 total_length[0];         /* included when l_bit is set */
48 } STRUCT_PACKED;
49
50 #define EAP_PWD_OPCODE_ID_EXCH          1
51 #define EAP_PWD_OPCODE_COMMIT_EXCH      2
52 #define EAP_PWD_OPCODE_CONFIRM_EXCH     3
53 #define EAP_PWD_GET_LENGTH_BIT(x)       ((x)->lm_exch & 0x80)
54 #define EAP_PWD_SET_LENGTH_BIT(x)       ((x)->lm_exch |= 0x80)
55 #define EAP_PWD_GET_MORE_BIT(x)         ((x)->lm_exch & 0x40)
56 #define EAP_PWD_SET_MORE_BIT(x)         ((x)->lm_exch |= 0x40)
57 #define EAP_PWD_GET_EXCHANGE(x)         ((x)->lm_exch & 0x3f)
58 #define EAP_PWD_SET_EXCHANGE(x,y)       ((x)->lm_exch |= (y))
59
60 /* EAP-pwd-ID payload */
61 struct eap_pwd_id {
62         be16 group_num;
63         u8 random_function;
64 #define EAP_PWD_DEFAULT_RAND_FUNC       1
65         u8 prf;
66 #define EAP_PWD_DEFAULT_PRF             1
67         u8 token[4];
68         u8 prep;
69 #define EAP_PWD_PREP_NONE               0
70 #define EAP_PWD_PREP_MS                 1
71         u8 identity[0];     /* length inferred from payload */
72 } STRUCT_PACKED;
73
74 /* common routines */
75 int compute_password_element(EAP_PWD_group *, u16, u8 *, int, u8 *, int, u8 *,
76                              int, u8 *);
77 int compute_keys(EAP_PWD_group *, BN_CTX *, BIGNUM *, EC_POINT *, EC_POINT *,
78                  BIGNUM *, BIGNUM *, u32 *, u8 *, u8 *);
79 void H_Init(HMAC_CTX *);
80 void H_Update(HMAC_CTX *, const u8 *, int);
81 void H_Final(HMAC_CTX *, u8 *);
82
83 #ifdef __cplusplus
84 }
85 #endif
86
87 #endif  /* EAP_PWD_COMMON_H */