int crypt_keyslot_set_encryption(struct crypt_device *cd,
	const char *cipher,
	size_t key_size)
{
	char *tmp;

	if (!cd || !cipher || !key_size || !isLUKS2(cd->type))
		return -EINVAL;

	if (LUKS2_keyslot_cipher_incompatible(cd, cipher))
		return -EINVAL;

	if (!(tmp = strdup(cipher)))
		return -ENOMEM;

	free(cd->u.luks2.keyslot_cipher);
	cd->u.luks2.keyslot_cipher = tmp;
	cd->u.luks2.keyslot_key_size = key_size;

	return 0;
}
int crypt_keyslot_set_encryption(struct crypt_device *cd,
	const char *cipher,
	size_t key_size)
{
	char *tmp;

	if (!cd || !cipher || !key_size || !isLUKS2(cd->type))
		return -EINVAL;

	if (LUKS2_keyslot_cipher_incompatible(cd, cipher))
		return -EINVAL;

	if (!(tmp = strdup(cipher)))
		return -ENOMEM;

	free(cd->u.luks2.keyslot_cipher);
	cd->u.luks2.keyslot_cipher = tmp;
	cd->u.luks2.keyslot_key_size = key_size;

	return 0;
}