#ifndef _FSCRYPT_PRIVATE_H
#define _FSCRYPT_PRIVATE_H
#include <linux/fscrypt.h>
#include <linux/siphash.h>
#include <crypto/hash.h>
#include <linux/blk-crypto.h>
#define CONST_STRLEN(str) …
#define FSCRYPT_FILE_NONCE_SIZE …
#define FSCRYPT_MIN_KEY_SIZE …
#define FSCRYPT_CONTEXT_V1 …
#define FSCRYPT_CONTEXT_V2 …
#define FSCRYPT_MODE_MAX …
struct fscrypt_context_v1 { … };
struct fscrypt_context_v2 { … };
fscrypt_context;
static inline int fscrypt_context_size(const union fscrypt_context *ctx)
{ … }
static inline bool fscrypt_context_is_valid(const union fscrypt_context *ctx,
int ctx_size)
{ … }
static inline const u8 *fscrypt_context_nonce(const union fscrypt_context *ctx)
{ … }
fscrypt_policy;
static inline int fscrypt_policy_size(const union fscrypt_policy *policy)
{ … }
static inline u8
fscrypt_policy_contents_mode(const union fscrypt_policy *policy)
{ … }
static inline u8
fscrypt_policy_fnames_mode(const union fscrypt_policy *policy)
{ … }
static inline u8
fscrypt_policy_flags(const union fscrypt_policy *policy)
{ … }
static inline int
fscrypt_policy_v2_du_bits(const struct fscrypt_policy_v2 *policy,
const struct inode *inode)
{ … }
static inline int
fscrypt_policy_du_bits(const union fscrypt_policy *policy,
const struct inode *inode)
{ … }
struct fscrypt_symlink_data { … } __packed;
struct fscrypt_prepared_key { … };
struct fscrypt_inode_info { … };
fscrypt_direction_t;
extern struct kmem_cache *fscrypt_inode_info_cachep;
int fscrypt_initialize(struct super_block *sb);
int fscrypt_crypt_data_unit(const struct fscrypt_inode_info *ci,
fscrypt_direction_t rw, u64 index,
struct page *src_page, struct page *dest_page,
unsigned int len, unsigned int offs,
gfp_t gfp_flags);
struct page *fscrypt_alloc_bounce_page(gfp_t gfp_flags);
void __printf(3, 4) __cold
fscrypt_msg(const struct inode *inode, const char *level, const char *fmt, ...);
#define fscrypt_warn(inode, fmt, ...) …
#define fscrypt_err(inode, fmt, ...) …
#define FSCRYPT_MAX_IV_SIZE …
fscrypt_iv;
void fscrypt_generate_iv(union fscrypt_iv *iv, u64 index,
const struct fscrypt_inode_info *ci);
static inline int
fscrypt_max_file_dun_bits(const struct super_block *sb, int du_bits)
{ … }
bool __fscrypt_fname_encrypted_size(const union fscrypt_policy *policy,
u32 orig_len, u32 max_len,
u32 *encrypted_len_ret);
struct fscrypt_hkdf { … };
int fscrypt_init_hkdf(struct fscrypt_hkdf *hkdf, const u8 *master_key,
unsigned int master_key_size);
#define HKDF_CONTEXT_KEY_IDENTIFIER …
#define HKDF_CONTEXT_PER_FILE_ENC_KEY …
#define HKDF_CONTEXT_DIRECT_KEY …
#define HKDF_CONTEXT_IV_INO_LBLK_64_KEY …
#define HKDF_CONTEXT_DIRHASH_KEY …
#define HKDF_CONTEXT_IV_INO_LBLK_32_KEY …
#define HKDF_CONTEXT_INODE_HASH_KEY …
int fscrypt_hkdf_expand(const struct fscrypt_hkdf *hkdf, u8 context,
const u8 *info, unsigned int infolen,
u8 *okm, unsigned int okmlen);
void fscrypt_destroy_hkdf(struct fscrypt_hkdf *hkdf);
#ifdef CONFIG_FS_ENCRYPTION_INLINE_CRYPT
int fscrypt_select_encryption_impl(struct fscrypt_inode_info *ci);
static inline bool
fscrypt_using_inline_encryption(const struct fscrypt_inode_info *ci)
{ … }
int fscrypt_prepare_inline_crypt_key(struct fscrypt_prepared_key *prep_key,
const u8 *raw_key,
const struct fscrypt_inode_info *ci);
void fscrypt_destroy_inline_crypt_key(struct super_block *sb,
struct fscrypt_prepared_key *prep_key);
static inline bool
fscrypt_is_key_prepared(struct fscrypt_prepared_key *prep_key,
const struct fscrypt_inode_info *ci)
{ … }
#else
static inline int fscrypt_select_encryption_impl(struct fscrypt_inode_info *ci)
{
return 0;
}
static inline bool
fscrypt_using_inline_encryption(const struct fscrypt_inode_info *ci)
{
return false;
}
static inline int
fscrypt_prepare_inline_crypt_key(struct fscrypt_prepared_key *prep_key,
const u8 *raw_key,
const struct fscrypt_inode_info *ci)
{
WARN_ON_ONCE(1);
return -EOPNOTSUPP;
}
static inline void
fscrypt_destroy_inline_crypt_key(struct super_block *sb,
struct fscrypt_prepared_key *prep_key)
{
}
static inline bool
fscrypt_is_key_prepared(struct fscrypt_prepared_key *prep_key,
const struct fscrypt_inode_info *ci)
{
return smp_load_acquire(&prep_key->tfm) != NULL;
}
#endif
struct fscrypt_master_key_secret { … } __randomize_layout;
struct fscrypt_master_key { … } __randomize_layout;
static inline const char *master_key_spec_type(
const struct fscrypt_key_specifier *spec)
{ … }
static inline int master_key_spec_len(const struct fscrypt_key_specifier *spec)
{ … }
void fscrypt_put_master_key(struct fscrypt_master_key *mk);
void fscrypt_put_master_key_activeref(struct super_block *sb,
struct fscrypt_master_key *mk);
struct fscrypt_master_key *
fscrypt_find_master_key(struct super_block *sb,
const struct fscrypt_key_specifier *mk_spec);
int fscrypt_get_test_dummy_key_identifier(
u8 key_identifier[FSCRYPT_KEY_IDENTIFIER_SIZE]);
int fscrypt_add_test_dummy_key(struct super_block *sb,
struct fscrypt_key_specifier *key_spec);
int fscrypt_verify_key_added(struct super_block *sb,
const u8 identifier[FSCRYPT_KEY_IDENTIFIER_SIZE]);
int __init fscrypt_init_keyring(void);
struct fscrypt_mode { … };
extern struct fscrypt_mode fscrypt_modes[];
int fscrypt_prepare_key(struct fscrypt_prepared_key *prep_key,
const u8 *raw_key, const struct fscrypt_inode_info *ci);
void fscrypt_destroy_prepared_key(struct super_block *sb,
struct fscrypt_prepared_key *prep_key);
int fscrypt_set_per_file_enc_key(struct fscrypt_inode_info *ci,
const u8 *raw_key);
int fscrypt_derive_dirhash_key(struct fscrypt_inode_info *ci,
const struct fscrypt_master_key *mk);
void fscrypt_hash_inode_number(struct fscrypt_inode_info *ci,
const struct fscrypt_master_key *mk);
int fscrypt_get_encryption_info(struct inode *inode, bool allow_unsupported);
static inline int fscrypt_require_key(struct inode *inode)
{ … }
void fscrypt_put_direct_key(struct fscrypt_direct_key *dk);
int fscrypt_setup_v1_file_key(struct fscrypt_inode_info *ci,
const u8 *raw_master_key);
int fscrypt_setup_v1_file_key_via_subscribed_keyrings(
struct fscrypt_inode_info *ci);
bool fscrypt_policies_equal(const union fscrypt_policy *policy1,
const union fscrypt_policy *policy2);
int fscrypt_policy_to_key_spec(const union fscrypt_policy *policy,
struct fscrypt_key_specifier *key_spec);
const union fscrypt_policy *fscrypt_get_dummy_policy(struct super_block *sb);
bool fscrypt_supported_policy(const union fscrypt_policy *policy_u,
const struct inode *inode);
int fscrypt_policy_from_context(union fscrypt_policy *policy_u,
const union fscrypt_context *ctx_u,
int ctx_size);
const union fscrypt_policy *fscrypt_policy_to_inherit(struct inode *dir);
#endif