static int reencrypt_load_clean(struct crypt_device *cd,
	struct luks2_hdr *hdr,
	uint64_t device_size,
	struct luks2_reencrypt **rh,
	const struct crypt_params_reencrypt *params)
{
	int r;
	const struct crypt_params_reencrypt hdr_reenc_params = {
		.resilience = reencrypt_resilience_type(hdr),
		.hash = reencrypt_resilience_hash(hdr),
		.device_size = params ? params->device_size : 0
	};
	struct luks2_reencrypt *tmp = crypt_zalloc(sizeof (*tmp));

	if (!tmp)
		return -ENOMEM;

	r = -EINVAL;
	if (!hdr_reenc_params.resilience)
		goto err;

	/* skip context update if data shift is detected in header */
	if (!strcmp(hdr_reenc_params.resilience, "datashift"))
		params = NULL;

	log_dbg(cd, "Initializing reencryption context (%s).", params ? "update" : "load");

	if (!params || !params->resilience)
		params = &hdr_reenc_params;

	r = reencrypt_context_init(cd, hdr, tmp, device_size, params);
	if (r)
		goto err;

	if (posix_memalign(&tmp->reenc_buffer, device_alignment(crypt_data_device(cd)),
			   reencrypt_buffer_length(tmp))) {
		r = -ENOMEM;
		goto err;
	}

	*rh = tmp;

	return 0;
err:
	LUKS2_reencrypt_free(cd, tmp);

	return r;
}
static int reencrypt_load_clean(struct crypt_device *cd,
	struct luks2_hdr *hdr,
	uint64_t device_size,
	struct luks2_reencrypt **rh,
	const struct crypt_params_reencrypt *params)
{
	int r;
	const struct crypt_params_reencrypt hdr_reenc_params = {
		.resilience = reencrypt_resilience_type(hdr),
		.hash = reencrypt_resilience_hash(hdr),
		.device_size = params ? params->device_size : 0
	};
	struct luks2_reencrypt *tmp = crypt_zalloc(sizeof (*tmp));

	if (!tmp)
		return -ENOMEM;

	r = -EINVAL;
	if (!hdr_reenc_params.resilience)
		goto err;

	 
	if (!strcmp(hdr_reenc_params.resilience, "datashift"))
		params = NULL;

	log_dbg(cd, "Initializing reencryption context (%s).", params ? "update" : "load");

	if (!params || !params->resilience)
		params = &hdr_reenc_params;

	r = reencrypt_context_init(cd, hdr, tmp, device_size, params);
	if (r)
		goto err;

	if (posix_memalign(&tmp->reenc_buffer, device_alignment(crypt_data_device(cd)),
			   reencrypt_buffer_length(tmp))) {
		r = -ENOMEM;
		goto err;
	}

	*rh = tmp;

	return 0;
err:
	LUKS2_reencrypt_free(cd, tmp);

	return r;
}