mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-18 08:35:08 +08:00
fscrypt: factor out fscrypt_policy_to_key_spec()
Factor out a function that builds the fscrypt_key_specifier for an fscrypt_policy. Before this was only needed when finding the key for a file, but now it will also be needed for test_dummy_encryption support. Signed-off-by: Eric Biggers <ebiggers@google.com> Link: https://lore.kernel.org/r/20220501050857.538984-4-ebiggers@kernel.org
This commit is contained in:
parent
a7a5bc5fe8
commit
bfb9700bdf
@ -623,6 +623,8 @@ int fscrypt_setup_v1_file_key_via_subscribed_keyrings(struct fscrypt_info *ci);
|
|||||||
|
|
||||||
bool fscrypt_policies_equal(const union fscrypt_policy *policy1,
|
bool fscrypt_policies_equal(const union fscrypt_policy *policy1,
|
||||||
const union fscrypt_policy *policy2);
|
const union fscrypt_policy *policy2);
|
||||||
|
int fscrypt_policy_to_key_spec(const union fscrypt_policy *policy,
|
||||||
|
struct fscrypt_key_specifier *key_spec);
|
||||||
bool fscrypt_supported_policy(const union fscrypt_policy *policy_u,
|
bool fscrypt_supported_policy(const union fscrypt_policy *policy_u,
|
||||||
const struct inode *inode);
|
const struct inode *inode);
|
||||||
int fscrypt_policy_from_context(union fscrypt_policy *policy_u,
|
int fscrypt_policy_from_context(union fscrypt_policy *policy_u,
|
||||||
|
@ -425,23 +425,9 @@ static int setup_file_encryption_key(struct fscrypt_info *ci,
|
|||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
switch (ci->ci_policy.version) {
|
err = fscrypt_policy_to_key_spec(&ci->ci_policy, &mk_spec);
|
||||||
case FSCRYPT_POLICY_V1:
|
if (err)
|
||||||
mk_spec.type = FSCRYPT_KEY_SPEC_TYPE_DESCRIPTOR;
|
return err;
|
||||||
memcpy(mk_spec.u.descriptor,
|
|
||||||
ci->ci_policy.v1.master_key_descriptor,
|
|
||||||
FSCRYPT_KEY_DESCRIPTOR_SIZE);
|
|
||||||
break;
|
|
||||||
case FSCRYPT_POLICY_V2:
|
|
||||||
mk_spec.type = FSCRYPT_KEY_SPEC_TYPE_IDENTIFIER;
|
|
||||||
memcpy(mk_spec.u.identifier,
|
|
||||||
ci->ci_policy.v2.master_key_identifier,
|
|
||||||
FSCRYPT_KEY_IDENTIFIER_SIZE);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
WARN_ON(1);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
key = fscrypt_find_master_key(ci->ci_inode->i_sb, &mk_spec);
|
key = fscrypt_find_master_key(ci->ci_inode->i_sb, &mk_spec);
|
||||||
if (IS_ERR(key)) {
|
if (IS_ERR(key)) {
|
||||||
|
@ -32,6 +32,26 @@ bool fscrypt_policies_equal(const union fscrypt_policy *policy1,
|
|||||||
return !memcmp(policy1, policy2, fscrypt_policy_size(policy1));
|
return !memcmp(policy1, policy2, fscrypt_policy_size(policy1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int fscrypt_policy_to_key_spec(const union fscrypt_policy *policy,
|
||||||
|
struct fscrypt_key_specifier *key_spec)
|
||||||
|
{
|
||||||
|
switch (policy->version) {
|
||||||
|
case FSCRYPT_POLICY_V1:
|
||||||
|
key_spec->type = FSCRYPT_KEY_SPEC_TYPE_DESCRIPTOR;
|
||||||
|
memcpy(key_spec->u.descriptor, policy->v1.master_key_descriptor,
|
||||||
|
FSCRYPT_KEY_DESCRIPTOR_SIZE);
|
||||||
|
return 0;
|
||||||
|
case FSCRYPT_POLICY_V2:
|
||||||
|
key_spec->type = FSCRYPT_KEY_SPEC_TYPE_IDENTIFIER;
|
||||||
|
memcpy(key_spec->u.identifier, policy->v2.master_key_identifier,
|
||||||
|
FSCRYPT_KEY_IDENTIFIER_SIZE);
|
||||||
|
return 0;
|
||||||
|
default:
|
||||||
|
WARN_ON(1);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static const union fscrypt_policy *
|
static const union fscrypt_policy *
|
||||||
fscrypt_get_dummy_policy(struct super_block *sb)
|
fscrypt_get_dummy_policy(struct super_block *sb)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user