xref: /freebsd/contrib/wpa/src/eap_common/eap_pwd_common.h (revision 7648bc9fee8dec6cb3c4941e0165a930fbe8dcb0)
1f05cddf9SRui Paulo /*
2f05cddf9SRui Paulo  * EAP server/peer: EAP-pwd shared definitions
3f05cddf9SRui Paulo  * Copyright (c) 2009, Dan Harkins <dharkins@lounge.org>
4f05cddf9SRui Paulo  *
5f05cddf9SRui Paulo  * This software may be distributed under the terms of the BSD license.
6f05cddf9SRui Paulo  * See README for more details.
7f05cddf9SRui Paulo  */
8f05cddf9SRui Paulo 
9f05cddf9SRui Paulo #ifndef EAP_PWD_COMMON_H
10f05cddf9SRui Paulo #define EAP_PWD_COMMON_H
11f05cddf9SRui Paulo 
12f05cddf9SRui Paulo /*
13f05cddf9SRui Paulo  * definition of a finite cyclic group
14f05cddf9SRui Paulo  * TODO: support one based on a prime field
15f05cddf9SRui Paulo  */
16f05cddf9SRui Paulo typedef struct group_definition_ {
17f05cddf9SRui Paulo 	u16 group_num;
1885732ac8SCy Schubert 	struct crypto_ec *group;
1985732ac8SCy Schubert 	struct crypto_ec_point *pwe;
20f05cddf9SRui Paulo } EAP_PWD_group;
21f05cddf9SRui Paulo 
22f05cddf9SRui Paulo /*
23f05cddf9SRui Paulo  * EAP-pwd header, included on all payloads
24f05cddf9SRui Paulo  * L(1 bit) | M(1 bit) | exch(6 bits) | total_length(if L is set)
25f05cddf9SRui Paulo  */
26f05cddf9SRui Paulo #define EAP_PWD_HDR_SIZE                1
27f05cddf9SRui Paulo 
28f05cddf9SRui Paulo #define EAP_PWD_OPCODE_ID_EXCH          1
29f05cddf9SRui Paulo #define EAP_PWD_OPCODE_COMMIT_EXCH      2
30f05cddf9SRui Paulo #define EAP_PWD_OPCODE_CONFIRM_EXCH     3
31f05cddf9SRui Paulo #define EAP_PWD_GET_LENGTH_BIT(x)       ((x) & 0x80)
32f05cddf9SRui Paulo #define EAP_PWD_SET_LENGTH_BIT(x)       ((x) |= 0x80)
33f05cddf9SRui Paulo #define EAP_PWD_GET_MORE_BIT(x)         ((x) & 0x40)
34f05cddf9SRui Paulo #define EAP_PWD_SET_MORE_BIT(x)         ((x) |= 0x40)
35f05cddf9SRui Paulo #define EAP_PWD_GET_EXCHANGE(x)         ((x) & 0x3f)
36f05cddf9SRui Paulo #define EAP_PWD_SET_EXCHANGE(x,y)       ((x) |= (y))
37f05cddf9SRui Paulo 
38f05cddf9SRui Paulo /* EAP-pwd-ID payload */
39f05cddf9SRui Paulo struct eap_pwd_id {
40f05cddf9SRui Paulo 	be16 group_num;
41f05cddf9SRui Paulo 	u8 random_function;
42f05cddf9SRui Paulo #define EAP_PWD_DEFAULT_RAND_FUNC       1
43f05cddf9SRui Paulo 	u8 prf;
44f05cddf9SRui Paulo #define EAP_PWD_DEFAULT_PRF             1
45f05cddf9SRui Paulo 	u8 token[4];
46f05cddf9SRui Paulo 	u8 prep;
47f05cddf9SRui Paulo #define EAP_PWD_PREP_NONE               0
48f05cddf9SRui Paulo #define EAP_PWD_PREP_MS                 1
4985732ac8SCy Schubert #define EAP_PWD_PREP_SSHA1              3
5085732ac8SCy Schubert #define EAP_PWD_PREP_SSHA256            4
5185732ac8SCy Schubert #define EAP_PWD_PREP_SSHA512            5
52f05cddf9SRui Paulo 	u8 identity[0];     /* length inferred from payload */
53f05cddf9SRui Paulo } STRUCT_PACKED;
54f05cddf9SRui Paulo 
55f05cddf9SRui Paulo /* common routines */
5685732ac8SCy Schubert EAP_PWD_group * get_eap_pwd_group(u16 num);
57325151a3SRui Paulo int compute_password_element(EAP_PWD_group *grp, u16 num,
58325151a3SRui Paulo 			     const u8 *password, size_t password_len,
59325151a3SRui Paulo 			     const u8 *id_server, size_t id_server_len,
60325151a3SRui Paulo 			     const u8 *id_peer, size_t id_peer_len,
61325151a3SRui Paulo 			     const u8 *token);
6285732ac8SCy Schubert int compute_keys(EAP_PWD_group *grp, const struct crypto_bignum *k,
6385732ac8SCy Schubert 		 const struct crypto_bignum *peer_scalar,
6485732ac8SCy Schubert 		 const struct crypto_bignum  *server_scalar,
65325151a3SRui Paulo 		 const u8 *confirm_peer, const u8 *confirm_server,
66325151a3SRui Paulo 		 const u32 *ciphersuite, u8 *msk, u8 *emsk, u8 *session_id);
67f05cddf9SRui Paulo struct crypto_hash * eap_pwd_h_init(void);
68f05cddf9SRui Paulo void eap_pwd_h_update(struct crypto_hash *hash, const u8 *data, size_t len);
69f05cddf9SRui Paulo void eap_pwd_h_final(struct crypto_hash *hash, u8 *digest);
70*4bc52338SCy Schubert struct crypto_ec_point * eap_pwd_get_element(EAP_PWD_group *group,
71*4bc52338SCy Schubert 					     const u8 *buf);
72*4bc52338SCy Schubert struct crypto_bignum * eap_pwd_get_scalar(EAP_PWD_group *group, const u8 *buf);
73*4bc52338SCy Schubert int eap_pwd_get_rand_mask(EAP_PWD_group *group, struct crypto_bignum *_rand,
74*4bc52338SCy Schubert 			  struct crypto_bignum *_mask,
75*4bc52338SCy Schubert 			  struct crypto_bignum *scalar);
76f05cddf9SRui Paulo 
77f05cddf9SRui Paulo #endif  /* EAP_PWD_COMMON_H */
78