static int resume_by_volume_key(struct crypt_device *cd,
		struct volume_key *vk,
		const char *name)
{
	int digest, r;
	struct volume_key *zerokey = NULL;

	if (crypt_is_cipher_null(crypt_get_cipher_spec(cd))) {
		zerokey = crypt_alloc_volume_key(0, NULL);
		if (!zerokey)
			return -ENOMEM;
		vk = zerokey;
	} else if (crypt_use_keyring_for_vk(cd)) {
		/* LUKS2 path only */
		digest = LUKS2_digest_by_segment(&cd->u.luks2.hdr, CRYPT_DEFAULT_SEGMENT);
		if (digest < 0)
			return -EINVAL;
		r = LUKS2_volume_key_load_in_keyring_by_digest(cd,
					&cd->u.luks2.hdr, vk, digest);
		if (r < 0)
			return r;
	}

	r = dm_resume_and_reinstate_key(cd, name, vk);

	if (r == -ENOTSUP)
		log_err(cd, _("Resume is not supported for device %s."), name);
	else if (r)
		log_err(cd, _("Error during resuming device %s."), name);

	if (r < 0)
		crypt_drop_keyring_key(cd, vk);

	crypt_free_volume_key(zerokey);

	return r;
}
static int resume_by_volume_key(struct crypt_device *cd,
		struct volume_key *vk,
		const char *name)
{
	int digest, r;
	struct volume_key *zerokey = NULL;

	if (crypt_is_cipher_null(crypt_get_cipher_spec(cd))) {
		zerokey = crypt_alloc_volume_key(0, NULL);
		if (!zerokey)
			return -ENOMEM;
		vk = zerokey;
	} else if (crypt_use_keyring_for_vk(cd)) {
		 
		digest = LUKS2_digest_by_segment(&cd->u.luks2.hdr, CRYPT_DEFAULT_SEGMENT);
		if (digest < 0)
			return -EINVAL;
		r = LUKS2_volume_key_load_in_keyring_by_digest(cd,
					&cd->u.luks2.hdr, vk, digest);
		if (r < 0)
			return r;
	}

	r = dm_resume_and_reinstate_key(cd, name, vk);

	if (r == -ENOTSUP)
		log_err(cd, _("Resume is not supported for device %s."), name);
	else if (r)
		log_err(cd, _("Error during resuming device %s."), name);

	if (r < 0)
		crypt_drop_keyring_key(cd, vk);

	crypt_free_volume_key(zerokey);

	return r;
}