Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * fscrypt_private.h
0004  *
0005  * Copyright (C) 2015, Google, Inc.
0006  *
0007  * Originally written by Michael Halcrow, Ildar Muslukhov, and Uday Savagaonkar.
0008  * Heavily modified since then.
0009  */
0010 
0011 #ifndef _FSCRYPT_PRIVATE_H
0012 #define _FSCRYPT_PRIVATE_H
0013 
0014 #include <linux/fscrypt.h>
0015 #include <linux/siphash.h>
0016 #include <crypto/hash.h>
0017 #include <linux/blk-crypto.h>
0018 
0019 #define CONST_STRLEN(str)   (sizeof(str) - 1)
0020 
0021 #define FSCRYPT_FILE_NONCE_SIZE 16
0022 
0023 /*
0024  * Minimum size of an fscrypt master key.  Note: a longer key will be required
0025  * if ciphers with a 256-bit security strength are used.  This is just the
0026  * absolute minimum, which applies when only 128-bit encryption is used.
0027  */
0028 #define FSCRYPT_MIN_KEY_SIZE    16
0029 
0030 #define FSCRYPT_CONTEXT_V1  1
0031 #define FSCRYPT_CONTEXT_V2  2
0032 
0033 /* Keep this in sync with include/uapi/linux/fscrypt.h */
0034 #define FSCRYPT_MODE_MAX    FSCRYPT_MODE_AES_256_HCTR2
0035 
0036 struct fscrypt_context_v1 {
0037     u8 version; /* FSCRYPT_CONTEXT_V1 */
0038     u8 contents_encryption_mode;
0039     u8 filenames_encryption_mode;
0040     u8 flags;
0041     u8 master_key_descriptor[FSCRYPT_KEY_DESCRIPTOR_SIZE];
0042     u8 nonce[FSCRYPT_FILE_NONCE_SIZE];
0043 };
0044 
0045 struct fscrypt_context_v2 {
0046     u8 version; /* FSCRYPT_CONTEXT_V2 */
0047     u8 contents_encryption_mode;
0048     u8 filenames_encryption_mode;
0049     u8 flags;
0050     u8 __reserved[4];
0051     u8 master_key_identifier[FSCRYPT_KEY_IDENTIFIER_SIZE];
0052     u8 nonce[FSCRYPT_FILE_NONCE_SIZE];
0053 };
0054 
0055 /*
0056  * fscrypt_context - the encryption context of an inode
0057  *
0058  * This is the on-disk equivalent of an fscrypt_policy, stored alongside each
0059  * encrypted file usually in a hidden extended attribute.  It contains the
0060  * fields from the fscrypt_policy, in order to identify the encryption algorithm
0061  * and key with which the file is encrypted.  It also contains a nonce that was
0062  * randomly generated by fscrypt itself; this is used as KDF input or as a tweak
0063  * to cause different files to be encrypted differently.
0064  */
0065 union fscrypt_context {
0066     u8 version;
0067     struct fscrypt_context_v1 v1;
0068     struct fscrypt_context_v2 v2;
0069 };
0070 
0071 /*
0072  * Return the size expected for the given fscrypt_context based on its version
0073  * number, or 0 if the context version is unrecognized.
0074  */
0075 static inline int fscrypt_context_size(const union fscrypt_context *ctx)
0076 {
0077     switch (ctx->version) {
0078     case FSCRYPT_CONTEXT_V1:
0079         BUILD_BUG_ON(sizeof(ctx->v1) != 28);
0080         return sizeof(ctx->v1);
0081     case FSCRYPT_CONTEXT_V2:
0082         BUILD_BUG_ON(sizeof(ctx->v2) != 40);
0083         return sizeof(ctx->v2);
0084     }
0085     return 0;
0086 }
0087 
0088 /* Check whether an fscrypt_context has a recognized version number and size */
0089 static inline bool fscrypt_context_is_valid(const union fscrypt_context *ctx,
0090                         int ctx_size)
0091 {
0092     return ctx_size >= 1 && ctx_size == fscrypt_context_size(ctx);
0093 }
0094 
0095 /* Retrieve the context's nonce, assuming the context was already validated */
0096 static inline const u8 *fscrypt_context_nonce(const union fscrypt_context *ctx)
0097 {
0098     switch (ctx->version) {
0099     case FSCRYPT_CONTEXT_V1:
0100         return ctx->v1.nonce;
0101     case FSCRYPT_CONTEXT_V2:
0102         return ctx->v2.nonce;
0103     }
0104     WARN_ON(1);
0105     return NULL;
0106 }
0107 
0108 union fscrypt_policy {
0109     u8 version;
0110     struct fscrypt_policy_v1 v1;
0111     struct fscrypt_policy_v2 v2;
0112 };
0113 
0114 /*
0115  * Return the size expected for the given fscrypt_policy based on its version
0116  * number, or 0 if the policy version is unrecognized.
0117  */
0118 static inline int fscrypt_policy_size(const union fscrypt_policy *policy)
0119 {
0120     switch (policy->version) {
0121     case FSCRYPT_POLICY_V1:
0122         return sizeof(policy->v1);
0123     case FSCRYPT_POLICY_V2:
0124         return sizeof(policy->v2);
0125     }
0126     return 0;
0127 }
0128 
0129 /* Return the contents encryption mode of a valid encryption policy */
0130 static inline u8
0131 fscrypt_policy_contents_mode(const union fscrypt_policy *policy)
0132 {
0133     switch (policy->version) {
0134     case FSCRYPT_POLICY_V1:
0135         return policy->v1.contents_encryption_mode;
0136     case FSCRYPT_POLICY_V2:
0137         return policy->v2.contents_encryption_mode;
0138     }
0139     BUG();
0140 }
0141 
0142 /* Return the filenames encryption mode of a valid encryption policy */
0143 static inline u8
0144 fscrypt_policy_fnames_mode(const union fscrypt_policy *policy)
0145 {
0146     switch (policy->version) {
0147     case FSCRYPT_POLICY_V1:
0148         return policy->v1.filenames_encryption_mode;
0149     case FSCRYPT_POLICY_V2:
0150         return policy->v2.filenames_encryption_mode;
0151     }
0152     BUG();
0153 }
0154 
0155 /* Return the flags (FSCRYPT_POLICY_FLAG*) of a valid encryption policy */
0156 static inline u8
0157 fscrypt_policy_flags(const union fscrypt_policy *policy)
0158 {
0159     switch (policy->version) {
0160     case FSCRYPT_POLICY_V1:
0161         return policy->v1.flags;
0162     case FSCRYPT_POLICY_V2:
0163         return policy->v2.flags;
0164     }
0165     BUG();
0166 }
0167 
0168 /*
0169  * For encrypted symlinks, the ciphertext length is stored at the beginning
0170  * of the string in little-endian format.
0171  */
0172 struct fscrypt_symlink_data {
0173     __le16 len;
0174     char encrypted_path[1];
0175 } __packed;
0176 
0177 /**
0178  * struct fscrypt_prepared_key - a key prepared for actual encryption/decryption
0179  * @tfm: crypto API transform object
0180  * @blk_key: key for blk-crypto
0181  *
0182  * Normally only one of the fields will be non-NULL.
0183  */
0184 struct fscrypt_prepared_key {
0185     struct crypto_skcipher *tfm;
0186 #ifdef CONFIG_FS_ENCRYPTION_INLINE_CRYPT
0187     struct fscrypt_blk_crypto_key *blk_key;
0188 #endif
0189 };
0190 
0191 /*
0192  * fscrypt_info - the "encryption key" for an inode
0193  *
0194  * When an encrypted file's key is made available, an instance of this struct is
0195  * allocated and stored in ->i_crypt_info.  Once created, it remains until the
0196  * inode is evicted.
0197  */
0198 struct fscrypt_info {
0199 
0200     /* The key in a form prepared for actual encryption/decryption */
0201     struct fscrypt_prepared_key ci_enc_key;
0202 
0203     /* True if ci_enc_key should be freed when this fscrypt_info is freed */
0204     bool ci_owns_key;
0205 
0206 #ifdef CONFIG_FS_ENCRYPTION_INLINE_CRYPT
0207     /*
0208      * True if this inode will use inline encryption (blk-crypto) instead of
0209      * the traditional filesystem-layer encryption.
0210      */
0211     bool ci_inlinecrypt;
0212 #endif
0213 
0214     /*
0215      * Encryption mode used for this inode.  It corresponds to either the
0216      * contents or filenames encryption mode, depending on the inode type.
0217      */
0218     struct fscrypt_mode *ci_mode;
0219 
0220     /* Back-pointer to the inode */
0221     struct inode *ci_inode;
0222 
0223     /*
0224      * The master key with which this inode was unlocked (decrypted).  This
0225      * will be NULL if the master key was found in a process-subscribed
0226      * keyring rather than in the filesystem-level keyring.
0227      */
0228     struct key *ci_master_key;
0229 
0230     /*
0231      * Link in list of inodes that were unlocked with the master key.
0232      * Only used when ->ci_master_key is set.
0233      */
0234     struct list_head ci_master_key_link;
0235 
0236     /*
0237      * If non-NULL, then encryption is done using the master key directly
0238      * and ci_enc_key will equal ci_direct_key->dk_key.
0239      */
0240     struct fscrypt_direct_key *ci_direct_key;
0241 
0242     /*
0243      * This inode's hash key for filenames.  This is a 128-bit SipHash-2-4
0244      * key.  This is only set for directories that use a keyed dirhash over
0245      * the plaintext filenames -- currently just casefolded directories.
0246      */
0247     siphash_key_t ci_dirhash_key;
0248     bool ci_dirhash_key_initialized;
0249 
0250     /* The encryption policy used by this inode */
0251     union fscrypt_policy ci_policy;
0252 
0253     /* This inode's nonce, copied from the fscrypt_context */
0254     u8 ci_nonce[FSCRYPT_FILE_NONCE_SIZE];
0255 
0256     /* Hashed inode number.  Only set for IV_INO_LBLK_32 */
0257     u32 ci_hashed_ino;
0258 };
0259 
0260 typedef enum {
0261     FS_DECRYPT = 0,
0262     FS_ENCRYPT,
0263 } fscrypt_direction_t;
0264 
0265 /* crypto.c */
0266 extern struct kmem_cache *fscrypt_info_cachep;
0267 int fscrypt_initialize(unsigned int cop_flags);
0268 int fscrypt_crypt_block(const struct inode *inode, fscrypt_direction_t rw,
0269             u64 lblk_num, struct page *src_page,
0270             struct page *dest_page, unsigned int len,
0271             unsigned int offs, gfp_t gfp_flags);
0272 struct page *fscrypt_alloc_bounce_page(gfp_t gfp_flags);
0273 
0274 void __printf(3, 4) __cold
0275 fscrypt_msg(const struct inode *inode, const char *level, const char *fmt, ...);
0276 
0277 #define fscrypt_warn(inode, fmt, ...)       \
0278     fscrypt_msg((inode), KERN_WARNING, fmt, ##__VA_ARGS__)
0279 #define fscrypt_err(inode, fmt, ...)        \
0280     fscrypt_msg((inode), KERN_ERR, fmt, ##__VA_ARGS__)
0281 
0282 #define FSCRYPT_MAX_IV_SIZE 32
0283 
0284 union fscrypt_iv {
0285     struct {
0286         /* logical block number within the file */
0287         __le64 lblk_num;
0288 
0289         /* per-file nonce; only set in DIRECT_KEY mode */
0290         u8 nonce[FSCRYPT_FILE_NONCE_SIZE];
0291     };
0292     u8 raw[FSCRYPT_MAX_IV_SIZE];
0293     __le64 dun[FSCRYPT_MAX_IV_SIZE / sizeof(__le64)];
0294 };
0295 
0296 void fscrypt_generate_iv(union fscrypt_iv *iv, u64 lblk_num,
0297              const struct fscrypt_info *ci);
0298 
0299 /* fname.c */
0300 bool __fscrypt_fname_encrypted_size(const union fscrypt_policy *policy,
0301                     u32 orig_len, u32 max_len,
0302                     u32 *encrypted_len_ret);
0303 
0304 /* hkdf.c */
0305 struct fscrypt_hkdf {
0306     struct crypto_shash *hmac_tfm;
0307 };
0308 
0309 int fscrypt_init_hkdf(struct fscrypt_hkdf *hkdf, const u8 *master_key,
0310               unsigned int master_key_size);
0311 
0312 /*
0313  * The list of contexts in which fscrypt uses HKDF.  These values are used as
0314  * the first byte of the HKDF application-specific info string to guarantee that
0315  * info strings are never repeated between contexts.  This ensures that all HKDF
0316  * outputs are unique and cryptographically isolated, i.e. knowledge of one
0317  * output doesn't reveal another.
0318  */
0319 #define HKDF_CONTEXT_KEY_IDENTIFIER 1 /* info=<empty>       */
0320 #define HKDF_CONTEXT_PER_FILE_ENC_KEY   2 /* info=file_nonce        */
0321 #define HKDF_CONTEXT_DIRECT_KEY     3 /* info=mode_num      */
0322 #define HKDF_CONTEXT_IV_INO_LBLK_64_KEY 4 /* info=mode_num||fs_uuid */
0323 #define HKDF_CONTEXT_DIRHASH_KEY    5 /* info=file_nonce        */
0324 #define HKDF_CONTEXT_IV_INO_LBLK_32_KEY 6 /* info=mode_num||fs_uuid */
0325 #define HKDF_CONTEXT_INODE_HASH_KEY 7 /* info=<empty>       */
0326 
0327 int fscrypt_hkdf_expand(const struct fscrypt_hkdf *hkdf, u8 context,
0328             const u8 *info, unsigned int infolen,
0329             u8 *okm, unsigned int okmlen);
0330 
0331 void fscrypt_destroy_hkdf(struct fscrypt_hkdf *hkdf);
0332 
0333 /* inline_crypt.c */
0334 #ifdef CONFIG_FS_ENCRYPTION_INLINE_CRYPT
0335 int fscrypt_select_encryption_impl(struct fscrypt_info *ci);
0336 
0337 static inline bool
0338 fscrypt_using_inline_encryption(const struct fscrypt_info *ci)
0339 {
0340     return ci->ci_inlinecrypt;
0341 }
0342 
0343 int fscrypt_prepare_inline_crypt_key(struct fscrypt_prepared_key *prep_key,
0344                      const u8 *raw_key,
0345                      const struct fscrypt_info *ci);
0346 
0347 void fscrypt_destroy_inline_crypt_key(struct fscrypt_prepared_key *prep_key);
0348 
0349 /*
0350  * Check whether the crypto transform or blk-crypto key has been allocated in
0351  * @prep_key, depending on which encryption implementation the file will use.
0352  */
0353 static inline bool
0354 fscrypt_is_key_prepared(struct fscrypt_prepared_key *prep_key,
0355             const struct fscrypt_info *ci)
0356 {
0357     /*
0358      * The two smp_load_acquire()'s here pair with the smp_store_release()'s
0359      * in fscrypt_prepare_inline_crypt_key() and fscrypt_prepare_key().
0360      * I.e., in some cases (namely, if this prep_key is a per-mode
0361      * encryption key) another task can publish blk_key or tfm concurrently,
0362      * executing a RELEASE barrier.  We need to use smp_load_acquire() here
0363      * to safely ACQUIRE the memory the other task published.
0364      */
0365     if (fscrypt_using_inline_encryption(ci))
0366         return smp_load_acquire(&prep_key->blk_key) != NULL;
0367     return smp_load_acquire(&prep_key->tfm) != NULL;
0368 }
0369 
0370 #else /* CONFIG_FS_ENCRYPTION_INLINE_CRYPT */
0371 
0372 static inline int fscrypt_select_encryption_impl(struct fscrypt_info *ci)
0373 {
0374     return 0;
0375 }
0376 
0377 static inline bool
0378 fscrypt_using_inline_encryption(const struct fscrypt_info *ci)
0379 {
0380     return false;
0381 }
0382 
0383 static inline int
0384 fscrypt_prepare_inline_crypt_key(struct fscrypt_prepared_key *prep_key,
0385                  const u8 *raw_key,
0386                  const struct fscrypt_info *ci)
0387 {
0388     WARN_ON(1);
0389     return -EOPNOTSUPP;
0390 }
0391 
0392 static inline void
0393 fscrypt_destroy_inline_crypt_key(struct fscrypt_prepared_key *prep_key)
0394 {
0395 }
0396 
0397 static inline bool
0398 fscrypt_is_key_prepared(struct fscrypt_prepared_key *prep_key,
0399             const struct fscrypt_info *ci)
0400 {
0401     return smp_load_acquire(&prep_key->tfm) != NULL;
0402 }
0403 #endif /* !CONFIG_FS_ENCRYPTION_INLINE_CRYPT */
0404 
0405 /* keyring.c */
0406 
0407 /*
0408  * fscrypt_master_key_secret - secret key material of an in-use master key
0409  */
0410 struct fscrypt_master_key_secret {
0411 
0412     /*
0413      * For v2 policy keys: HKDF context keyed by this master key.
0414      * For v1 policy keys: not set (hkdf.hmac_tfm == NULL).
0415      */
0416     struct fscrypt_hkdf hkdf;
0417 
0418     /*
0419      * Size of the raw key in bytes.  This remains set even if ->raw was
0420      * zeroized due to no longer being needed.  I.e. we still remember the
0421      * size of the key even if we don't need to remember the key itself.
0422      */
0423     u32         size;
0424 
0425     /* For v1 policy keys: the raw key.  Wiped for v2 policy keys. */
0426     u8          raw[FSCRYPT_MAX_KEY_SIZE];
0427 
0428 } __randomize_layout;
0429 
0430 /*
0431  * fscrypt_master_key - an in-use master key
0432  *
0433  * This represents a master encryption key which has been added to the
0434  * filesystem and can be used to "unlock" the encrypted files which were
0435  * encrypted with it.
0436  */
0437 struct fscrypt_master_key {
0438 
0439     /*
0440      * The secret key material.  After FS_IOC_REMOVE_ENCRYPTION_KEY is
0441      * executed, this is wiped and no new inodes can be unlocked with this
0442      * key; however, there may still be inodes in ->mk_decrypted_inodes
0443      * which could not be evicted.  As long as some inodes still remain,
0444      * FS_IOC_REMOVE_ENCRYPTION_KEY can be retried, or
0445      * FS_IOC_ADD_ENCRYPTION_KEY can add the secret again.
0446      *
0447      * Locking: protected by this master key's key->sem.
0448      */
0449     struct fscrypt_master_key_secret    mk_secret;
0450 
0451     /*
0452      * For v1 policy keys: an arbitrary key descriptor which was assigned by
0453      * userspace (->descriptor).
0454      *
0455      * For v2 policy keys: a cryptographic hash of this key (->identifier).
0456      */
0457     struct fscrypt_key_specifier        mk_spec;
0458 
0459     /*
0460      * Keyring which contains a key of type 'key_type_fscrypt_user' for each
0461      * user who has added this key.  Normally each key will be added by just
0462      * one user, but it's possible that multiple users share a key, and in
0463      * that case we need to keep track of those users so that one user can't
0464      * remove the key before the others want it removed too.
0465      *
0466      * This is NULL for v1 policy keys; those can only be added by root.
0467      *
0468      * Locking: in addition to this keyring's own semaphore, this is
0469      * protected by this master key's key->sem, so we can do atomic
0470      * search+insert.  It can also be searched without taking any locks, but
0471      * in that case the returned key may have already been removed.
0472      */
0473     struct key      *mk_users;
0474 
0475     /*
0476      * Length of ->mk_decrypted_inodes, plus one if mk_secret is present.
0477      * Once this goes to 0, the master key is removed from ->s_master_keys.
0478      * The 'struct fscrypt_master_key' will continue to live as long as the
0479      * 'struct key' whose payload it is, but we won't let this reference
0480      * count rise again.
0481      */
0482     refcount_t      mk_refcount;
0483 
0484     /*
0485      * List of inodes that were unlocked using this key.  This allows the
0486      * inodes to be evicted efficiently if the key is removed.
0487      */
0488     struct list_head    mk_decrypted_inodes;
0489     spinlock_t      mk_decrypted_inodes_lock;
0490 
0491     /*
0492      * Per-mode encryption keys for the various types of encryption policies
0493      * that use them.  Allocated and derived on-demand.
0494      */
0495     struct fscrypt_prepared_key mk_direct_keys[FSCRYPT_MODE_MAX + 1];
0496     struct fscrypt_prepared_key mk_iv_ino_lblk_64_keys[FSCRYPT_MODE_MAX + 1];
0497     struct fscrypt_prepared_key mk_iv_ino_lblk_32_keys[FSCRYPT_MODE_MAX + 1];
0498 
0499     /* Hash key for inode numbers.  Initialized only when needed. */
0500     siphash_key_t       mk_ino_hash_key;
0501     bool            mk_ino_hash_key_initialized;
0502 
0503 } __randomize_layout;
0504 
0505 static inline bool
0506 is_master_key_secret_present(const struct fscrypt_master_key_secret *secret)
0507 {
0508     /*
0509      * The READ_ONCE() is only necessary for fscrypt_drop_inode() and
0510      * fscrypt_key_describe().  These run in atomic context, so they can't
0511      * take the key semaphore and thus 'secret' can change concurrently
0512      * which would be a data race.  But they only need to know whether the
0513      * secret *was* present at the time of check, so READ_ONCE() suffices.
0514      */
0515     return READ_ONCE(secret->size) != 0;
0516 }
0517 
0518 static inline const char *master_key_spec_type(
0519                 const struct fscrypt_key_specifier *spec)
0520 {
0521     switch (spec->type) {
0522     case FSCRYPT_KEY_SPEC_TYPE_DESCRIPTOR:
0523         return "descriptor";
0524     case FSCRYPT_KEY_SPEC_TYPE_IDENTIFIER:
0525         return "identifier";
0526     }
0527     return "[unknown]";
0528 }
0529 
0530 static inline int master_key_spec_len(const struct fscrypt_key_specifier *spec)
0531 {
0532     switch (spec->type) {
0533     case FSCRYPT_KEY_SPEC_TYPE_DESCRIPTOR:
0534         return FSCRYPT_KEY_DESCRIPTOR_SIZE;
0535     case FSCRYPT_KEY_SPEC_TYPE_IDENTIFIER:
0536         return FSCRYPT_KEY_IDENTIFIER_SIZE;
0537     }
0538     return 0;
0539 }
0540 
0541 struct key *
0542 fscrypt_find_master_key(struct super_block *sb,
0543             const struct fscrypt_key_specifier *mk_spec);
0544 
0545 int fscrypt_get_test_dummy_key_identifier(
0546               u8 key_identifier[FSCRYPT_KEY_IDENTIFIER_SIZE]);
0547 
0548 int fscrypt_verify_key_added(struct super_block *sb,
0549                  const u8 identifier[FSCRYPT_KEY_IDENTIFIER_SIZE]);
0550 
0551 int __init fscrypt_init_keyring(void);
0552 
0553 /* keysetup.c */
0554 
0555 struct fscrypt_mode {
0556     const char *friendly_name;
0557     const char *cipher_str;
0558     int keysize;        /* key size in bytes */
0559     int security_strength;  /* security strength in bytes */
0560     int ivsize;     /* IV size in bytes */
0561     int logged_cryptoapi_impl;
0562     int logged_blk_crypto_native;
0563     int logged_blk_crypto_fallback;
0564     enum blk_crypto_mode_num blk_crypto_mode;
0565 };
0566 
0567 extern struct fscrypt_mode fscrypt_modes[];
0568 
0569 int fscrypt_prepare_key(struct fscrypt_prepared_key *prep_key,
0570             const u8 *raw_key, const struct fscrypt_info *ci);
0571 
0572 void fscrypt_destroy_prepared_key(struct fscrypt_prepared_key *prep_key);
0573 
0574 int fscrypt_set_per_file_enc_key(struct fscrypt_info *ci, const u8 *raw_key);
0575 
0576 int fscrypt_derive_dirhash_key(struct fscrypt_info *ci,
0577                    const struct fscrypt_master_key *mk);
0578 
0579 void fscrypt_hash_inode_number(struct fscrypt_info *ci,
0580                    const struct fscrypt_master_key *mk);
0581 
0582 int fscrypt_get_encryption_info(struct inode *inode, bool allow_unsupported);
0583 
0584 /**
0585  * fscrypt_require_key() - require an inode's encryption key
0586  * @inode: the inode we need the key for
0587  *
0588  * If the inode is encrypted, set up its encryption key if not already done.
0589  * Then require that the key be present and return -ENOKEY otherwise.
0590  *
0591  * No locks are needed, and the key will live as long as the struct inode --- so
0592  * it won't go away from under you.
0593  *
0594  * Return: 0 on success, -ENOKEY if the key is missing, or another -errno code
0595  * if a problem occurred while setting up the encryption key.
0596  */
0597 static inline int fscrypt_require_key(struct inode *inode)
0598 {
0599     if (IS_ENCRYPTED(inode)) {
0600         int err = fscrypt_get_encryption_info(inode, false);
0601 
0602         if (err)
0603             return err;
0604         if (!fscrypt_has_encryption_key(inode))
0605             return -ENOKEY;
0606     }
0607     return 0;
0608 }
0609 
0610 /* keysetup_v1.c */
0611 
0612 void fscrypt_put_direct_key(struct fscrypt_direct_key *dk);
0613 
0614 int fscrypt_setup_v1_file_key(struct fscrypt_info *ci,
0615                   const u8 *raw_master_key);
0616 
0617 int fscrypt_setup_v1_file_key_via_subscribed_keyrings(struct fscrypt_info *ci);
0618 
0619 /* policy.c */
0620 
0621 bool fscrypt_policies_equal(const union fscrypt_policy *policy1,
0622                 const union fscrypt_policy *policy2);
0623 int fscrypt_policy_to_key_spec(const union fscrypt_policy *policy,
0624                    struct fscrypt_key_specifier *key_spec);
0625 bool fscrypt_supported_policy(const union fscrypt_policy *policy_u,
0626                   const struct inode *inode);
0627 int fscrypt_policy_from_context(union fscrypt_policy *policy_u,
0628                 const union fscrypt_context *ctx_u,
0629                 int ctx_size);
0630 const union fscrypt_policy *fscrypt_policy_to_inherit(struct inode *dir);
0631 
0632 #endif /* _FSCRYPT_PRIVATE_H */