/* The caller is responsible for freeing the returned buffer.  */
u8* eap_peer_tls_derive_session_id(struct eap_sm *sm, struct eap_ssl_data *data, u8 eap_type, size_t *len)
/* The caller is responsible for freeing the returned buffer.  */
u8* eap_peer_tls_derive_session_id(struct eap_sm *sm, struct eap_ssl_data *data, u8 eap_type, size_t *len)
{
	struct tls_keys keys;
	u8 *out;
	if (tls_connection_get_keys(sm->ssl_ctx, data->conn, &keys))
		return NULL;
	if (keys.client_random == NULL || keys.server_random == NULL ||
	    keys.master_key == NULL)
		return NULL;
	*len = 1 + keys.client_random_len + keys.server_random_len;
	out = os_malloc(*len);
	if (out == NULL)
		return NULL;
	out[0] = eap_type;
	os_memcpy(out + 1, keys.client_random, keys.client_random_len);
	os_memcpy(out + 1 + keys.client_random_len, keys.server_random,
	          keys.server_random_len);
	return out;
}