#ifndef _FSVERITY_PRIVATE_H
#define _FSVERITY_PRIVATE_H
#define pr_fmt(fmt) "fs-verity: " fmt
#include <linux/fsverity.h>
#define FS_VERITY_MAX_LEVELS 8
struct fsverity_hash_alg {
struct crypto_shash *tfm;
const char *name;
unsigned int digest_size;
unsigned int block_size;
enum hash_algo algo_id;
};
struct merkle_tree_params {
const struct fsverity_hash_alg *hash_alg;
const u8 *hashstate;
unsigned int digest_size;
unsigned int block_size;
unsigned int hashes_per_block;
unsigned int blocks_per_page;
u8 log_digestsize;
u8 log_blocksize;
u8 log_arity;
u8 log_blocks_per_page;
unsigned int num_levels;
u64 tree_size;
unsigned long tree_pages;
unsigned long level_start[FS_VERITY_MAX_LEVELS];
};
struct fsverity_info {
struct merkle_tree_params tree_params;
u8 root_hash[FS_VERITY_MAX_DIGEST_SIZE];
u8 file_digest[FS_VERITY_MAX_DIGEST_SIZE];
const struct inode *inode;
unsigned long *hash_block_verified;
spinlock_t hash_page_init_lock;
};
#define FS_VERITY_MAX_SIGNATURE_SIZE (FS_VERITY_MAX_DESCRIPTOR_SIZE - \
sizeof(struct fsverity_descriptor))
extern struct fsverity_hash_alg fsverity_hash_algs[];
const struct fsverity_hash_alg *fsverity_get_hash_alg(const struct inode *inode,
unsigned int num);
const u8 *fsverity_prepare_hash_state(const struct fsverity_hash_alg *alg,
const u8 *salt, size_t salt_size);
int fsverity_hash_block(const struct merkle_tree_params *params,
const struct inode *inode, const void *data, u8 *out);
int fsverity_hash_buffer(const struct fsverity_hash_alg *alg,
const void *data, size_t size, u8 *out);
void __init fsverity_check_hash_algs(void);
void __printf(3, 4) __cold
fsverity_msg(const struct inode *inode, const char *level,
const char *fmt, ...);
#define fsverity_warn(inode, fmt, ...) \
fsverity_msg((inode), KERN_WARNING, fmt, ##__VA_ARGS__)
#define fsverity_err(inode, fmt, ...) \
fsverity_msg((inode), KERN_ERR, fmt, ##__VA_ARGS__)
int fsverity_init_merkle_tree_params(struct merkle_tree_params *params,
const struct inode *inode,
unsigned int hash_algorithm,
unsigned int log_blocksize,
const u8 *salt, size_t salt_size);
struct fsverity_info *fsverity_create_info(const struct inode *inode,
struct fsverity_descriptor *desc);
void fsverity_set_info(struct inode *inode, struct fsverity_info *vi);
void fsverity_free_info(struct fsverity_info *vi);
int fsverity_get_descriptor(struct inode *inode,
struct fsverity_descriptor **desc_ret);
void __init fsverity_init_info_cache(void);
#ifdef CONFIG_FS_VERITY_BUILTIN_SIGNATURES
extern int fsverity_require_signatures;
int fsverity_verify_signature(const struct fsverity_info *vi,
const u8 *signature, size_t sig_size);
void __init fsverity_init_signature(void);
#else /* !CONFIG_FS_VERITY_BUILTIN_SIGNATURES */
static inline int
fsverity_verify_signature(const struct fsverity_info *vi,
const u8 *signature, size_t sig_size)
{
return 0;
}
static inline void fsverity_init_signature(void)
{
}
#endif /* !CONFIG_FS_VERITY_BUILTIN_SIGNATURES */
void __init fsverity_init_workqueue(void);
#endif /* _FSVERITY_PRIVATE_H */