Lines Matching refs:dk

155 static void free_direct_key(struct fscrypt_direct_key *dk)  in free_direct_key()  argument
157 if (dk) { in free_direct_key()
158 fscrypt_destroy_prepared_key(dk->dk_sb, &dk->dk_key); in free_direct_key()
159 kfree_sensitive(dk); in free_direct_key()
163 void fscrypt_put_direct_key(struct fscrypt_direct_key *dk) in fscrypt_put_direct_key() argument
165 if (!refcount_dec_and_lock(&dk->dk_refcount, &fscrypt_direct_keys_lock)) in fscrypt_put_direct_key()
167 hash_del(&dk->dk_node); in fscrypt_put_direct_key()
170 free_direct_key(dk); in fscrypt_put_direct_key()
184 struct fscrypt_direct_key *dk; in find_or_insert_direct_key() local
197 hash_for_each_possible(fscrypt_direct_keys, dk, dk_node, hash_key) { in find_or_insert_direct_key()
199 dk->dk_descriptor, FSCRYPT_KEY_DESCRIPTOR_SIZE) != 0) in find_or_insert_direct_key()
201 if (ci->ci_mode != dk->dk_mode) in find_or_insert_direct_key()
203 if (!fscrypt_is_key_prepared(&dk->dk_key, ci)) in find_or_insert_direct_key()
205 if (crypto_memneq(raw_key, dk->dk_raw, ci->ci_mode->keysize)) in find_or_insert_direct_key()
208 refcount_inc(&dk->dk_refcount); in find_or_insert_direct_key()
211 return dk; in find_or_insert_direct_key()
223 struct fscrypt_direct_key *dk; in fscrypt_get_direct_key() local
227 dk = find_or_insert_direct_key(NULL, raw_key, ci); in fscrypt_get_direct_key()
228 if (dk) in fscrypt_get_direct_key()
229 return dk; in fscrypt_get_direct_key()
232 dk = kzalloc(sizeof(*dk), GFP_KERNEL); in fscrypt_get_direct_key()
233 if (!dk) in fscrypt_get_direct_key()
235 dk->dk_sb = ci->ci_inode->i_sb; in fscrypt_get_direct_key()
236 refcount_set(&dk->dk_refcount, 1); in fscrypt_get_direct_key()
237 dk->dk_mode = ci->ci_mode; in fscrypt_get_direct_key()
238 err = fscrypt_prepare_key(&dk->dk_key, raw_key, ci); in fscrypt_get_direct_key()
241 memcpy(dk->dk_descriptor, ci->ci_policy.v1.master_key_descriptor, in fscrypt_get_direct_key()
243 memcpy(dk->dk_raw, raw_key, ci->ci_mode->keysize); in fscrypt_get_direct_key()
245 return find_or_insert_direct_key(dk, raw_key, ci); in fscrypt_get_direct_key()
248 free_direct_key(dk); in fscrypt_get_direct_key()
256 struct fscrypt_direct_key *dk; in setup_v1_file_key_direct() local
258 dk = fscrypt_get_direct_key(ci, raw_master_key); in setup_v1_file_key_direct()
259 if (IS_ERR(dk)) in setup_v1_file_key_direct()
260 return PTR_ERR(dk); in setup_v1_file_key_direct()
261 ci->ci_direct_key = dk; in setup_v1_file_key_direct()
262 ci->ci_enc_key = dk->dk_key; in setup_v1_file_key_direct()