Updated through tag hostap_2_5 from git://w1.fi/hostap.git
[mech_eap.git] / libeap / 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 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/ec.h>
14 #include <openssl/evp.h>
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 /*
21  * definition of a finite cyclic group
22  * TODO: support one based on a prime field
23  */
24 typedef struct group_definition_ {
25         u16 group_num;
26         EC_GROUP *group;
27         EC_POINT *pwe;
28         BIGNUM *order;
29         BIGNUM *prime;
30 } EAP_PWD_group;
31
32 /*
33  * EAP-pwd header, included on all payloads
34  * L(1 bit) | M(1 bit) | exch(6 bits) | total_length(if L is set)
35  */
36 #define EAP_PWD_HDR_SIZE                1
37
38 #define EAP_PWD_OPCODE_ID_EXCH          1
39 #define EAP_PWD_OPCODE_COMMIT_EXCH      2
40 #define EAP_PWD_OPCODE_CONFIRM_EXCH     3
41 #define EAP_PWD_GET_LENGTH_BIT(x)       ((x) & 0x80)
42 #define EAP_PWD_SET_LENGTH_BIT(x)       ((x) |= 0x80)
43 #define EAP_PWD_GET_MORE_BIT(x)         ((x) & 0x40)
44 #define EAP_PWD_SET_MORE_BIT(x)         ((x) |= 0x40)
45 #define EAP_PWD_GET_EXCHANGE(x)         ((x) & 0x3f)
46 #define EAP_PWD_SET_EXCHANGE(x,y)       ((x) |= (y))
47
48 /* EAP-pwd-ID payload */
49 struct eap_pwd_id {
50         be16 group_num;
51         u8 random_function;
52 #define EAP_PWD_DEFAULT_RAND_FUNC       1
53         u8 prf;
54 #define EAP_PWD_DEFAULT_PRF             1
55         u8 token[4];
56         u8 prep;
57 #define EAP_PWD_PREP_NONE               0
58 #define EAP_PWD_PREP_MS                 1
59         u8 identity[0];     /* length inferred from payload */
60 } STRUCT_PACKED;
61
62 /* common routines */
63 int compute_password_element(EAP_PWD_group *grp, u16 num,
64                              const u8 *password, size_t password_len,
65                              const u8 *id_server, size_t id_server_len,
66                              const u8 *id_peer, size_t id_peer_len,
67                              const u8 *token);
68 int compute_keys(EAP_PWD_group *grp, BN_CTX *bnctx, const BIGNUM *k,
69                  const BIGNUM *peer_scalar, const BIGNUM *server_scalar,
70                  const u8 *confirm_peer, const u8 *confirm_server,
71                  const u32 *ciphersuite, u8 *msk, u8 *emsk, u8 *session_id);
72 struct crypto_hash * eap_pwd_h_init(void);
73 void eap_pwd_h_update(struct crypto_hash *hash, const u8 *data, size_t len);
74 void eap_pwd_h_final(struct crypto_hash *hash, u8 *digest);
75
76 #ifdef __cplusplus
77 }
78 #endif
79
80 #endif  /* EAP_PWD_COMMON_H */