Lines Matching +full:byte +full:- +full:len

2  * EAP server/peer: EAP-SAKE shared routines
3 * Copyright (c) 2006-2019, Jouni Malinen <j@w1.fi>
19 u8 attr_id, u8 len, const u8 *data)
25 wpa_printf(MSG_DEBUG, "EAP-SAKE: Parse: AT_RAND_S");
26 if (len != EAP_SAKE_RAND_LEN) {
27 wpa_printf(MSG_DEBUG, "EAP-SAKE: AT_RAND_S with "
28 "invalid payload length %d", len);
29 return -1;
31 attr->rand_s = data;
34 wpa_printf(MSG_DEBUG, "EAP-SAKE: Parse: AT_RAND_P");
35 if (len != EAP_SAKE_RAND_LEN) {
36 wpa_printf(MSG_DEBUG, "EAP-SAKE: AT_RAND_P with "
37 "invalid payload length %d", len);
38 return -1;
40 attr->rand_p = data;
43 wpa_printf(MSG_DEBUG, "EAP-SAKE: Parse: AT_MIC_S");
44 if (len != EAP_SAKE_MIC_LEN) {
45 wpa_printf(MSG_DEBUG, "EAP-SAKE: AT_MIC_S with "
46 "invalid payload length %d", len);
47 return -1;
49 attr->mic_s = data;
52 wpa_printf(MSG_DEBUG, "EAP-SAKE: Parse: AT_MIC_P");
53 if (len != EAP_SAKE_MIC_LEN) {
54 wpa_printf(MSG_DEBUG, "EAP-SAKE: AT_MIC_P with "
55 "invalid payload length %d", len);
56 return -1;
58 attr->mic_p = data;
61 wpa_printf(MSG_DEBUG, "EAP-SAKE: Parse: AT_SERVERID");
62 attr->serverid = data;
63 attr->serverid_len = len;
66 wpa_printf(MSG_DEBUG, "EAP-SAKE: Parse: AT_PEERID");
67 attr->peerid = data;
68 attr->peerid_len = len;
71 wpa_printf(MSG_DEBUG, "EAP-SAKE: Parse: AT_SPI_S");
72 attr->spi_s = data;
73 attr->spi_s_len = len;
76 wpa_printf(MSG_DEBUG, "EAP-SAKE: Parse: AT_SPI_P");
77 attr->spi_p = data;
78 attr->spi_p_len = len;
81 wpa_printf(MSG_DEBUG, "EAP-SAKE: Parse: AT_ANY_ID_REQ");
82 if (len != 2) {
83 wpa_printf(MSG_DEBUG, "EAP-SAKE: Invalid AT_ANY_ID_REQ"
84 " payload length %d", len);
85 return -1;
87 attr->any_id_req = data;
90 wpa_printf(MSG_DEBUG, "EAP-SAKE: Parse: AT_PERM_ID_REQ");
91 if (len != 2) {
92 wpa_printf(MSG_DEBUG, "EAP-SAKE: Invalid "
93 "AT_PERM_ID_REQ payload length %d", len);
94 return -1;
96 attr->perm_id_req = data;
99 wpa_printf(MSG_DEBUG, "EAP-SAKE: Parse: AT_ENCR_DATA");
100 attr->encr_data = data;
101 attr->encr_data_len = len;
104 wpa_printf(MSG_DEBUG, "EAP-SAKE: Parse: AT_IV");
105 attr->iv = data;
106 attr->iv_len = len;
109 wpa_printf(MSG_DEBUG, "EAP-SAKE: Parse: AT_PADDING");
110 for (i = 0; i < len; i++) {
112 wpa_printf(MSG_DEBUG, "EAP-SAKE: AT_PADDING "
113 "with non-zero pad byte");
114 return -1;
119 wpa_printf(MSG_DEBUG, "EAP-SAKE: Parse: AT_NEXT_TMPID");
120 attr->next_tmpid = data;
121 attr->next_tmpid_len = len;
124 wpa_printf(MSG_DEBUG, "EAP-SAKE: Parse: AT_MSK_LIFE");
125 if (len != 4) {
126 wpa_printf(MSG_DEBUG, "EAP-SAKE: Invalid "
127 "AT_MSK_LIFE payload length %d", len);
128 return -1;
130 attr->msk_life = data;
134 wpa_printf(MSG_DEBUG, "EAP-SAKE: Unknown non-skippable"
136 return -1;
138 wpa_printf(MSG_DEBUG, "EAP-SAKE: Ignoring unknown skippable "
143 if (attr->iv && !attr->encr_data) {
144 wpa_printf(MSG_DEBUG, "EAP-SAKE: AT_IV included without "
146 return -1;
154 * eap_sake_parse_attributes - Parse EAP-SAKE attributes
156 * @len: Payload length
158 * Returns: 0 on success or -1 on failure
160 int eap_sake_parse_attributes(const u8 *buf, size_t len,
163 const u8 *pos = buf, *end = buf + len;
169 if (end - pos < 2) {
170 wpa_printf(MSG_DEBUG, "EAP-SAKE: Too short attribute");
171 return -1;
179 "EAP-SAKE: Invalid attribute length (%d)",
181 return -1;
183 attr_len -= 2;
185 if (attr_len > end - pos) {
186 wpa_printf(MSG_DEBUG, "EAP-SAKE: Attribute underflow");
187 return -1;
191 return -1;
201 * eap_sake_kdf - EAP-SAKE Key Derivation Function (KDF)
209 * @buf: Buffer for the generated pseudo-random key
211 * Returns: 0 on success or -1 on failure
226 size_t len[4];
229 len[0] = label_len;
231 len[1] = data_len;
233 len[2] = data2_len;
235 len[3] = 1;
239 plen = buf_len - pos;
241 if (hmac_sha1_vector(key, key_len, 4, addr, len,
243 return -1;
246 if (hmac_sha1_vector(key, key_len, 4, addr, len,
248 return -1;
260 * eap_sake_derive_keys - Derive EAP-SAKE keys
261 * @root_secret_a: 16-byte Root-Secret-A
262 * @root_secret_b: 16-byte Root-Secret-B
263 * @rand_s: 16-byte RAND_S
264 * @rand_p: 16-byte RAND_P
265 * @tek: Buffer for Temporary EAK Keys (TEK-Auth[16] | TEK-Cipher[16])
266 * @msk: Buffer for 64-byte MSK
267 * @emsk: Buffer for 64-byte EMSK
268 * Returns: 0 on success or -1 on failure
270 * This function derives EAP-SAKE keys as defined in RFC 4763, section 3.2.6.
280 wpa_printf(MSG_DEBUG, "EAP-SAKE: Deriving keys");
282 wpa_hexdump_key(MSG_DEBUG, "EAP-SAKE: Root-Secret-A",
288 return -1;
289 wpa_hexdump_key(MSG_DEBUG, "EAP-SAKE: SMS-A", sms_a, EAP_SAKE_SMS_LEN);
293 return -1;
294 wpa_hexdump_key(MSG_DEBUG, "EAP-SAKE: TEK-Auth",
296 wpa_hexdump_key(MSG_DEBUG, "EAP-SAKE: TEK-Cipher",
299 wpa_hexdump_key(MSG_DEBUG, "EAP-SAKE: Root-Secret-B",
305 return -1;
306 wpa_hexdump_key(MSG_DEBUG, "EAP-SAKE: SMS-B", sms_b, EAP_SAKE_SMS_LEN);
310 return -1;
313 wpa_hexdump_key(MSG_DEBUG, "EAP-SAKE: MSK", msk, EAP_MSK_LEN);
314 wpa_hexdump_key(MSG_DEBUG, "EAP-SAKE: EMSK", emsk, EAP_EMSK_LEN);
320 * eap_sake_compute_mic - Compute EAP-SAKE MIC for an EAP packet
321 * @tek_auth: 16-byte TEK-Auth
322 * @rand_s: 16-byte RAND_S
323 * @rand_p: 16-byte RAND_P
332 * @mic: Buffer for the computed 16-byte MIC
333 * Returns: 0 on success or -1 on failure
350 return -1;
385 os_memset(pos + (mic_pos - eap), 0, EAP_SAKE_MIC_LEN);
399 size_t len)
402 wpabuf_put_u8(buf, 2 + len); /* Length; including attr header */
404 wpabuf_put_data(buf, data, len);
406 os_memset(wpabuf_put(buf, len), 0, len);