int LUKS2_keyslot_find_empty(struct crypt_device *cd, struct luks2_hdr *hdr, size_t keylength)
{
	int i;

	for (i = 0; i < LUKS2_KEYSLOTS_MAX; i++)
		if (!LUKS2_get_keyslot_jobj(hdr, i))
			break;

	if (i == LUKS2_KEYSLOTS_MAX)
		return -EINVAL;

	/* Check also there is a space for the key in keyslots area */
	if (keylength && LUKS2_find_area_gap(cd, hdr, keylength, NULL, NULL) < 0)
		return -ENOSPC;

	return i;
}
int LUKS2_keyslot_find_empty(struct crypt_device *cd, struct luks2_hdr *hdr, size_t keylength)
{
	int i;

	for (i = 0; i < LUKS2_KEYSLOTS_MAX; i++)
		if (!LUKS2_get_keyslot_jobj(hdr, i))
			break;

	if (i == LUKS2_KEYSLOTS_MAX)
		return -EINVAL;

	 
	if (keylength && LUKS2_find_area_gap(cd, hdr, keylength, NULL, NULL) < 0)
		return -ENOSPC;

	return i;
}