13ff40c12SJohn Marino /*
23ff40c12SJohn Marino  * EAP server/peer: EAP-pwd shared definitions
33ff40c12SJohn Marino  * Copyright (c) 2009, Dan Harkins <dharkins@lounge.org>
43ff40c12SJohn Marino  *
53ff40c12SJohn Marino  * This software may be distributed under the terms of the BSD license.
63ff40c12SJohn Marino  * See README for more details.
73ff40c12SJohn Marino  */
83ff40c12SJohn Marino 
93ff40c12SJohn Marino #ifndef EAP_PWD_COMMON_H
103ff40c12SJohn Marino #define EAP_PWD_COMMON_H
113ff40c12SJohn Marino 
123ff40c12SJohn Marino /*
133ff40c12SJohn Marino  * definition of a finite cyclic group
143ff40c12SJohn Marino  * TODO: support one based on a prime field
153ff40c12SJohn Marino  */
163ff40c12SJohn Marino typedef struct group_definition_ {
173ff40c12SJohn Marino 	u16 group_num;
18*a1157835SDaniel Fojt 	struct crypto_ec *group;
19*a1157835SDaniel Fojt 	struct crypto_ec_point *pwe;
203ff40c12SJohn Marino } EAP_PWD_group;
213ff40c12SJohn Marino 
223ff40c12SJohn Marino /*
233ff40c12SJohn Marino  * EAP-pwd header, included on all payloads
243ff40c12SJohn Marino  * L(1 bit) | M(1 bit) | exch(6 bits) | total_length(if L is set)
253ff40c12SJohn Marino  */
263ff40c12SJohn Marino #define EAP_PWD_HDR_SIZE                1
273ff40c12SJohn Marino 
283ff40c12SJohn Marino #define EAP_PWD_OPCODE_ID_EXCH          1
293ff40c12SJohn Marino #define EAP_PWD_OPCODE_COMMIT_EXCH      2
303ff40c12SJohn Marino #define EAP_PWD_OPCODE_CONFIRM_EXCH     3
313ff40c12SJohn Marino #define EAP_PWD_GET_LENGTH_BIT(x)       ((x) & 0x80)
323ff40c12SJohn Marino #define EAP_PWD_SET_LENGTH_BIT(x)       ((x) |= 0x80)
333ff40c12SJohn Marino #define EAP_PWD_GET_MORE_BIT(x)         ((x) & 0x40)
343ff40c12SJohn Marino #define EAP_PWD_SET_MORE_BIT(x)         ((x) |= 0x40)
353ff40c12SJohn Marino #define EAP_PWD_GET_EXCHANGE(x)         ((x) & 0x3f)
363ff40c12SJohn Marino #define EAP_PWD_SET_EXCHANGE(x,y)       ((x) |= (y))
373ff40c12SJohn Marino 
383ff40c12SJohn Marino /* EAP-pwd-ID payload */
393ff40c12SJohn Marino struct eap_pwd_id {
403ff40c12SJohn Marino 	be16 group_num;
413ff40c12SJohn Marino 	u8 random_function;
423ff40c12SJohn Marino #define EAP_PWD_DEFAULT_RAND_FUNC       1
433ff40c12SJohn Marino 	u8 prf;
443ff40c12SJohn Marino #define EAP_PWD_DEFAULT_PRF             1
453ff40c12SJohn Marino 	u8 token[4];
463ff40c12SJohn Marino 	u8 prep;
473ff40c12SJohn Marino #define EAP_PWD_PREP_NONE               0
483ff40c12SJohn Marino #define EAP_PWD_PREP_MS                 1
49*a1157835SDaniel Fojt #define EAP_PWD_PREP_SSHA1              3
50*a1157835SDaniel Fojt #define EAP_PWD_PREP_SSHA256            4
51*a1157835SDaniel Fojt #define EAP_PWD_PREP_SSHA512            5
523ff40c12SJohn Marino 	u8 identity[0];     /* length inferred from payload */
533ff40c12SJohn Marino } STRUCT_PACKED;
543ff40c12SJohn Marino 
553ff40c12SJohn Marino /* common routines */
56*a1157835SDaniel Fojt EAP_PWD_group * get_eap_pwd_group(u16 num);
57*a1157835SDaniel Fojt int compute_password_element(EAP_PWD_group *grp, u16 num,
58*a1157835SDaniel Fojt 			     const u8 *password, size_t password_len,
59*a1157835SDaniel Fojt 			     const u8 *id_server, size_t id_server_len,
60*a1157835SDaniel Fojt 			     const u8 *id_peer, size_t id_peer_len,
61*a1157835SDaniel Fojt 			     const u8 *token);
62*a1157835SDaniel Fojt int compute_keys(EAP_PWD_group *grp, const struct crypto_bignum *k,
63*a1157835SDaniel Fojt 		 const struct crypto_bignum *peer_scalar,
64*a1157835SDaniel Fojt 		 const struct crypto_bignum  *server_scalar,
65*a1157835SDaniel Fojt 		 const u8 *confirm_peer, const u8 *confirm_server,
66*a1157835SDaniel Fojt 		 const u32 *ciphersuite, u8 *msk, u8 *emsk, u8 *session_id);
673ff40c12SJohn Marino struct crypto_hash * eap_pwd_h_init(void);
683ff40c12SJohn Marino void eap_pwd_h_update(struct crypto_hash *hash, const u8 *data, size_t len);
693ff40c12SJohn Marino void eap_pwd_h_final(struct crypto_hash *hash, u8 *digest);
70*a1157835SDaniel Fojt struct crypto_ec_point * eap_pwd_get_element(EAP_PWD_group *group,
71*a1157835SDaniel Fojt 					     const u8 *buf);
72*a1157835SDaniel Fojt struct crypto_bignum * eap_pwd_get_scalar(EAP_PWD_group *group, const u8 *buf);
73*a1157835SDaniel Fojt int eap_pwd_get_rand_mask(EAP_PWD_group *group, struct crypto_bignum *_rand,
74*a1157835SDaniel Fojt 			  struct crypto_bignum *_mask,
75*a1157835SDaniel Fojt 			  struct crypto_bignum *scalar);
763ff40c12SJohn Marino 
773ff40c12SJohn Marino #endif  /* EAP_PWD_COMMON_H */
78