int crypt_activate_by_keyfile_device_offset(struct crypt_device *cd,
	const char *name,
	int keyslot,
	const char *keyfile,
	size_t keyfile_size,
	uint64_t keyfile_offset,
	uint32_t flags)
{
	char *passphrase_read = NULL;
	size_t passphrase_size_read;
	int r;

	if (!cd || !keyfile ||
	    ((flags & CRYPT_ACTIVATE_KEYRING_KEY) && !crypt_use_keyring_for_vk(cd)))
		return -EINVAL;

	log_dbg(cd, "%s volume %s [keyslot %d] using keyfile %s.",
		name ? "Activating" : "Checking", name ?: "passphrase", keyslot, keyfile);

	r = _activate_check_status(cd, name, flags & CRYPT_ACTIVATE_REFRESH);
	if (r < 0)
		return r;

	r = crypt_keyfile_device_read(cd, keyfile,
				&passphrase_read, &passphrase_size_read,
				keyfile_offset, keyfile_size, 0);
	if (r < 0)
		goto out;

	if (isLOOPAES(cd->type))
		r = _activate_loopaes(cd, name, passphrase_read, passphrase_size_read, flags);
	else
		r = _activate_by_passphrase(cd, name, keyslot, passphrase_read, passphrase_size_read, flags);

out:
	crypt_safe_free(passphrase_read);
	return r;
}
int crypt_activate_by_keyfile_device_offset(struct crypt_device *cd,
	const char *name,
	int keyslot,
	const char *keyfile,
	size_t keyfile_size,
	uint64_t keyfile_offset,
	uint32_t flags)
{
	char *passphrase_read = NULL;
	size_t passphrase_size_read;
	int r;

	if (!cd || !keyfile ||
	    ((flags & CRYPT_ACTIVATE_KEYRING_KEY) && !crypt_use_keyring_for_vk(cd)))
		return -EINVAL;

	log_dbg(cd, "%s volume %s [keyslot %d] using keyfile %s.",
		name ? "Activating" : "Checking", name ?: "passphrase", keyslot, keyfile);

	r = _activate_check_status(cd, name, flags & CRYPT_ACTIVATE_REFRESH);
	if (r < 0)
		return r;

	r = crypt_keyfile_device_read(cd, keyfile,
				&passphrase_read, &passphrase_size_read,
				keyfile_offset, keyfile_size, 0);
	if (r < 0)
		goto out;

	if (isLOOPAES(cd->type))
		r = _activate_loopaes(cd, name, passphrase_read, passphrase_size_read, flags);
	else
		r = _activate_by_passphrase(cd, name, keyslot, passphrase_read, passphrase_size_read, flags);

out:
	crypt_safe_free(passphrase_read);
	return r;
}