static int LUKS2_keyslot_open_by_digest(struct crypt_device *cd,
	struct luks2_hdr *hdr,
	int keyslot,
	int digest,
	const char *password,
	size_t password_len,
	struct volume_key **vk)
{
	int r_prio, r = -EINVAL;

	if (digest < 0)
		return r;

	if (keyslot == CRYPT_ANY_SLOT) {
		r_prio = LUKS2_keyslot_open_priority_digest(cd, hdr, CRYPT_SLOT_PRIORITY_PREFER,
			password, password_len, digest, vk);
		if (r_prio >= 0)
			r = r_prio;
		else if (r_prio != -EPERM && r_prio != -ENOENT)
			r = r_prio;
		else
			r = LUKS2_keyslot_open_priority_digest(cd, hdr, CRYPT_SLOT_PRIORITY_NORMAL,
				password, password_len, digest, vk);
		/* Prefer password wrong to no entry from priority slot */
		if (r_prio == -EPERM && r == -ENOENT)
			r = r_prio;
	} else
		r = LUKS2_open_and_verify_by_digest(cd, hdr, keyslot, digest, password, password_len, vk);

	return r;
}
static int LUKS2_keyslot_open_by_digest(struct crypt_device *cd,
	struct luks2_hdr *hdr,
	int keyslot,
	int digest,
	const char *password,
	size_t password_len,
	struct volume_key **vk)
{
	int r_prio, r = -EINVAL;

	if (digest < 0)
		return r;

	if (keyslot == CRYPT_ANY_SLOT) {
		r_prio = LUKS2_keyslot_open_priority_digest(cd, hdr, CRYPT_SLOT_PRIORITY_PREFER,
			password, password_len, digest, vk);
		if (r_prio >= 0)
			r = r_prio;
		else if (r_prio != -EPERM && r_prio != -ENOENT)
			r = r_prio;
		else
			r = LUKS2_keyslot_open_priority_digest(cd, hdr, CRYPT_SLOT_PRIORITY_NORMAL,
				password, password_len, digest, vk);
		 
		if (r_prio == -EPERM && r == -ENOENT)
			r = r_prio;
	} else
		r = LUKS2_open_and_verify_by_digest(cd, hdr, keyslot, digest, password, password_len, vk);

	return r;
}