// SPDX-License-Identifier: GPL-2.0 /* * fs-verity hash algorithms * * Copyright 2019 Google LLC */ #include "fsverity_private.h" #include <crypto/hash.h> /* The hash algorithms supported by fs-verity */ struct fsverity_hash_alg fsverity_hash_algs[] = …; static DEFINE_MUTEX(fsverity_hash_alg_init_mutex); /** * fsverity_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 * ensure it has a hash transform ready to go. The hash transforms are * allocated on-demand so that we don't waste resources unnecessarily, and * because the crypto modules may be initialized later than fs/verity/. * * Return: pointer to the hash alg on success, else an ERR_PTR() */ const struct fsverity_hash_alg *fsverity_get_hash_alg(const struct inode *inode, unsigned int num) { … } /** * fsverity_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 precomputed * initial hash state on success or an ERR_PTR() on failure. */ const u8 *fsverity_prepare_hash_state(const struct fsverity_hash_alg *alg, const u8 *salt, size_t salt_size) { … } /** * fsverity_hash_block() - hash a single data or hash block * @params: the Merkle tree's parameters * @inode: inode for which the hashing is being done * @data: virtual address of a buffer containing the block to hash * @out: output digest, size 'params->digest_size' bytes * * Hash a single data or hash block. The hash is salted if a salt is specified * in the Merkle tree parameters. * * Return: 0 on success, -errno on failure */ int fsverity_hash_block(const struct merkle_tree_params *params, const struct inode *inode, const void *data, u8 *out) { … } /** * fsverity_hash_buffer() - hash some data * @alg: the hash algorithm to use * @data: the data to hash * @size: size of data to hash, in bytes * @out: output digest, size 'alg->digest_size' bytes * * Return: 0 on success, -errno on failure */ 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) { … }