136d97821Schristos /* 236d97821Schristos * Simultaneous authentication of equals 336d97821Schristos * Copyright (c) 2012-2013, Jouni Malinen <j@w1.fi> 436d97821Schristos * 536d97821Schristos * This software may be distributed under the terms of the BSD license. 636d97821Schristos * See README for more details. 736d97821Schristos */ 836d97821Schristos 936d97821Schristos #ifndef SAE_H 1036d97821Schristos #define SAE_H 1136d97821Schristos 1236d97821Schristos #define SAE_KCK_LEN 32 1336d97821Schristos #define SAE_PMK_LEN 32 1436d97821Schristos #define SAE_PMKID_LEN 16 1536d97821Schristos #define SAE_KEYSEED_KEY_LEN 32 1636d97821Schristos #define SAE_MAX_PRIME_LEN 512 1736d97821Schristos #define SAE_MAX_ECC_PRIME_LEN 66 1836d97821Schristos #define SAE_COMMIT_MAX_LEN (2 + 3 * SAE_MAX_PRIME_LEN) 1936d97821Schristos #define SAE_CONFIRM_MAX_LEN (2 + SAE_MAX_PRIME_LEN) 2036d97821Schristos 21928750b6Schristos /* Special value returned by sae_parse_commit() */ 22928750b6Schristos #define SAE_SILENTLY_DISCARD 65535 23928750b6Schristos 2436d97821Schristos struct sae_temporary_data { 2536d97821Schristos u8 kck[SAE_KCK_LEN]; 2636d97821Schristos struct crypto_bignum *own_commit_scalar; 2736d97821Schristos struct crypto_bignum *own_commit_element_ffc; 2836d97821Schristos struct crypto_ec_point *own_commit_element_ecc; 2936d97821Schristos struct crypto_bignum *peer_commit_element_ffc; 3036d97821Schristos struct crypto_ec_point *peer_commit_element_ecc; 3136d97821Schristos struct crypto_ec_point *pwe_ecc; 3236d97821Schristos struct crypto_bignum *pwe_ffc; 3336d97821Schristos struct crypto_bignum *sae_rand; 3436d97821Schristos struct crypto_ec *ec; 3536d97821Schristos int prime_len; 36*0d69f216Schristos int order_len; 3736d97821Schristos const struct dh_group *dh; 3836d97821Schristos const struct crypto_bignum *prime; 3936d97821Schristos const struct crypto_bignum *order; 4036d97821Schristos struct crypto_bignum *prime_buf; 4136d97821Schristos struct crypto_bignum *order_buf; 429a53cbbeSchristos struct wpabuf *anti_clogging_token; 43ebb5671cSchristos char *pw_id; 44*0d69f216Schristos int vlan_id; 45*0d69f216Schristos u8 bssid[ETH_ALEN]; 46ebb5671cSchristos }; 47ebb5671cSchristos 48ebb5671cSchristos enum sae_state { 49ebb5671cSchristos SAE_NOTHING, SAE_COMMITTED, SAE_CONFIRMED, SAE_ACCEPTED 5036d97821Schristos }; 5136d97821Schristos 5236d97821Schristos struct sae_data { 53ebb5671cSchristos enum sae_state state; 5436d97821Schristos u16 send_confirm; 5536d97821Schristos u8 pmk[SAE_PMK_LEN]; 56928750b6Schristos u8 pmkid[SAE_PMKID_LEN]; 5736d97821Schristos struct crypto_bignum *peer_commit_scalar; 5836d97821Schristos int group; 59ebb5671cSchristos unsigned int sync; /* protocol instance variable: Sync */ 60ebb5671cSchristos u16 rc; /* protocol instance variable: Rc (received send-confirm) */ 6136d97821Schristos struct sae_temporary_data *tmp; 6236d97821Schristos }; 6336d97821Schristos 6436d97821Schristos int sae_set_group(struct sae_data *sae, int group); 6536d97821Schristos void sae_clear_temp_data(struct sae_data *sae); 6636d97821Schristos void sae_clear_data(struct sae_data *sae); 6736d97821Schristos 6836d97821Schristos int sae_prepare_commit(const u8 *addr1, const u8 *addr2, 6936d97821Schristos const u8 *password, size_t password_len, 70ebb5671cSchristos const char *identifier, struct sae_data *sae); 7136d97821Schristos int sae_process_commit(struct sae_data *sae); 7236d97821Schristos void sae_write_commit(struct sae_data *sae, struct wpabuf *buf, 73ebb5671cSchristos const struct wpabuf *token, const char *identifier); 7436d97821Schristos u16 sae_parse_commit(struct sae_data *sae, const u8 *data, size_t len, 7536d97821Schristos const u8 **token, size_t *token_len, int *allowed_groups); 7636d97821Schristos void sae_write_confirm(struct sae_data *sae, struct wpabuf *buf); 7736d97821Schristos int sae_check_confirm(struct sae_data *sae, const u8 *data, size_t len); 789a53cbbeSchristos u16 sae_group_allowed(struct sae_data *sae, int *allowed_groups, u16 group); 79ebb5671cSchristos const char * sae_state_txt(enum sae_state state); 8036d97821Schristos 8136d97821Schristos #endif /* SAE_H */ 82