Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:fs\verity\open.c Create Date:2022-07-28 20:24:49
Last Modify:2020-03-12 14:18:49 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:sverity_init_merkle_tree_params() - initialize Merkle tree parameters*@params: the parameters struct to initialize*@inode: the inode for which the Merkle tree is being built*@hash_algorithm: number of hash algorithm to use*@log_blocksize: log base 2 of

Proto: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)

Type:int

Parameter:

TypeParameterName
struct merkle_tree_params *params
const struct inode *inode
unsigned inthash_algorithm
unsigned intlog_blocksize
const u8 *salt
size_tsalt_size
40  memset(params, 0, size of params )
42  hash_alg = sverity_get_hash_alg() - validate and prepare a hash algorithm*@inode: optional inode for logging purposes*@num: the hash algorithm number* Get the struct fsverity_hash_alg for the given hash algorithm number, and
43  If IS_ERR(hash_alg) Then Return PTR_ERR(hash_alg)
45  he hash algorithm = hash_alg
46  same as hash_alg->digest_size = digest size in bytes, e.g. 32 for SHA-256
48  itial hash state or NULL = sverity_prepare_hash_state() - precompute the initial hash state*@alg: hash algorithm*@salt: a salt which is to be prepended to all data to be hashed*@salt_size: salt size in bytes, possibly 0* Return: NULL if the salt is empty, otherwise the kmalloc()'ed
50  If IS_ERR(itial hash state or NULL ) Then
51  err = PTR_ERR(itial hash state or NULL )
52  itial hash state or NULL = NULL
53  fsverity_err(inode, "Error %d preparing hash state", err)
54  Go to out_err
57  If log_blocksize != PAGE_SHIFT determines the page size Then
58  fsverity_warn(inode, "Unsupported log_blocksize: %u", log_blocksize)
60  err = -EINVAL
61  Go to out_err
63  log2(block_size) = log_blocksize
64  size of data and tree blocks = 1 << log_blocksize
66  If WARN_ON(!s_power_of_2() - check if a value is a power of two*@n: the value to check* Determine whether some value is a power of two, where zero is* *not* considered a power of two.* Return: true if @n is a power of 2, otherwise false.) Then
67  err = -EINVAL
68  Go to out_err
70  If size of data and tree blocks < 2 * same as hash_alg->digest_size Then
71  fsverity_warn(inode, "Merkle tree block size (%u) too small for hash algorithm \"%s\"", size of data and tree blocks , crypto API name, e.g. sha256 )
74  err = -EINVAL
75  Go to out_err
77  log2(hashes_per_block) = log2(block_size) - log2 - log base 2 of 32-bit or a 64-bit unsigned value*@n: parameter* constant-capable log of base 2 calculation* - this can be used to initialise global variables from constant data, hence* the massive ternary operator construction* selects the (same as hash_alg->digest_size )
78  umber of hashes per tree block = 1 << log2(hashes_per_block)
80  pr_debug("Merkle tree uses %s with %u-byte blocks (%u hashes/block), salt=%*phN\n", crypto API name, e.g. sha256 , size of data and tree blocks , umber of hashes per tree block , (int)salt_size, salt)
92  blocks = i_size + size of data and tree blocks - 1 >> log_blocksize
93  pr_debug("Data is %lld bytes (%llu blocks)\n", i_size, blocks)
94  When blocks > 1 cycle
96  fsverity_err(inode, "Too many levels in Merkle tree")
97  err = -EINVAL
98  Go to out_err
100  blocks = blocks + umber of hashes per tree block - 1 >> log2(hashes_per_block)
103  Starting block index for each tree level, ordered from leaf level (0)* to root level ('num_levels - 1')[umber of levels in Merkle tree ++] = blocks
107  offset = 0
108  When level >= 0 cycle
109  blocks = Starting block index for each tree level, ordered from leaf level (0)* to root level ('num_levels - 1')[level]
110  Starting block index for each tree level, ordered from leaf level (0)* to root level ('num_levels - 1')[level] = offset
111  pr_debug("Level %d is %llu blocks starting at index %llu\n", level, blocks, offset)
113  offset += blocks
116  Merkle tree size in bytes = offset << log_blocksize
117  Return 0
119  out_err :
120  kfree(itial hash state or NULL )
121  memset(params, 0, size of params )
122  Return err
Caller
NameDescribe
fsverity_create_infoValidate the given fsverity_descriptor and create a new fsverity_info from* it. The signature (if present) is also checked.