huangcm
2025-07-01 676035278781360996553c427a12bf358249ebf7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
 * EAP server/peer: EAP-EKE shared routines
 * Copyright (c) 2011-2013, Jouni Malinen <j@w1.fi>
 *
 * This software may be distributed under the terms of the BSD license.
 * See README for more details.
 */
 
#ifndef EAP_EKE_COMMON_H
#define EAP_EKE_COMMON_H
 
/* EKE Exchange */
#define EAP_EKE_ID 1
#define EAP_EKE_COMMIT 2
#define EAP_EKE_CONFIRM 3
#define EAP_EKE_FAILURE 4
 
/* Diffie-Hellman Group Registry */
#define EAP_EKE_DHGROUP_EKE_2 1
#define EAP_EKE_DHGROUP_EKE_5 2
#define EAP_EKE_DHGROUP_EKE_14 3 /* mandatory to implement */
#define EAP_EKE_DHGROUP_EKE_15 4
#define EAP_EKE_DHGROUP_EKE_16 5
 
/* Encryption Algorithm Registry */
#define EAP_EKE_ENCR_AES128_CBC 1 /* mandatory to implement */
 
/* Pseudo Random Function Registry */
#define EAP_EKE_PRF_HMAC_SHA1 1 /* mandatory to implement */
#define EAP_EKE_PRF_HMAC_SHA2_256 2
 
/* Keyed Message Digest (MAC) Registry */
#define EAP_EKE_MAC_HMAC_SHA1 1 /* mandatory to implement */
#define EAP_EKE_MAC_HMAC_SHA2_256 2
 
/* Identity Type Registry */
#define EAP_EKE_ID_OPAQUE 1
#define EAP_EKE_ID_NAI 2
#define EAP_EKE_ID_IPv4 3
#define EAP_EKE_ID_IPv6 4
#define EAP_EKE_ID_FQDN 5
#define EAP_EKE_ID_DN 6
 
/* Failure-Code */
#define EAP_EKE_FAIL_NO_ERROR 1
#define EAP_EKE_FAIL_PROTO_ERROR 2
#define EAP_EKE_FAIL_PASSWD_NOT_FOUND 3
#define EAP_EKE_FAIL_AUTHENTICATION_FAIL 4
#define EAP_EKE_FAIL_AUTHORIZATION_FAIL 5
#define EAP_EKE_FAIL_NO_PROPOSAL_CHOSEN 6
#define EAP_EKE_FAIL_PRIVATE_INTERNAL_ERROR 0xffffffff
 
#define EAP_EKE_MAX_DH_LEN 512
#define EAP_EKE_MAX_HASH_LEN 32
#define EAP_EKE_MAX_KEY_LEN 16
#define EAP_EKE_MAX_KE_LEN 16
#define EAP_EKE_MAX_KI_LEN 32
#define EAP_EKE_MAX_KA_LEN 32
#define EAP_EKE_MAX_NONCE_LEN 16
 
struct eap_eke_session {
   /* Selected proposal */
   u8 dhgroup;
   u8 encr;
   u8 prf;
   u8 mac;
 
   u8 shared_secret[EAP_EKE_MAX_HASH_LEN];
   u8 ke[EAP_EKE_MAX_KE_LEN];
   u8 ki[EAP_EKE_MAX_KI_LEN];
   u8 ka[EAP_EKE_MAX_KA_LEN];
 
   int prf_len;
   int nonce_len;
   int auth_len;
   int dhcomp_len;
   int pnonce_len;
   int pnonce_ps_len;
};
 
int eap_eke_session_init(struct eap_eke_session *sess, u8 dhgroup, u8 encr,
            u8 prf, u8 mac);
void eap_eke_session_clean(struct eap_eke_session *sess);
int eap_eke_dh_init(u8 group, u8 *ret_priv, u8 *ret_pub);
int eap_eke_derive_key(struct eap_eke_session *sess,
              const u8 *password, size_t password_len,
              const u8 *id_s, size_t id_s_len, const u8 *id_p,
              size_t id_p_len, u8 *key);
int eap_eke_dhcomp(struct eap_eke_session *sess, const u8 *key, const u8 *dhpub,
          u8 *ret_dhcomp);
int eap_eke_shared_secret(struct eap_eke_session *sess, const u8 *key,
             const u8 *dhpriv, const u8 *peer_dhcomp);
int eap_eke_derive_ke_ki(struct eap_eke_session *sess,
            const u8 *id_s, size_t id_s_len,
            const u8 *id_p, size_t id_p_len);
int eap_eke_derive_ka(struct eap_eke_session *sess,
             const u8 *id_s, size_t id_s_len,
             const u8 *id_p, size_t id_p_len,
             const u8 *nonce_p, const u8 *nonce_s);
int eap_eke_derive_msk(struct eap_eke_session *sess,
              const u8 *id_s, size_t id_s_len,
              const u8 *id_p, size_t id_p_len,
              const u8 *nonce_p, const u8 *nonce_s,
              u8 *msk, u8 *emsk);
int eap_eke_prot(struct eap_eke_session *sess,
        const u8 *data, size_t data_len,
        u8 *prot, size_t *prot_len);
int eap_eke_decrypt_prot(struct eap_eke_session *sess,
            const u8 *prot, size_t prot_len,
            u8 *data, size_t *data_len);
int eap_eke_auth(struct eap_eke_session *sess, const char *label,
        const struct wpabuf *msgs, u8 *auth);
 
#endif /* EAP_EKE_COMMON_H */