diff options
author | Eric Biggers <ebiggers@google.com> | 2022-11-28 20:51:39 -0800 |
---|---|---|
committer | Eric Biggers <ebiggers@google.com> | 2022-11-29 21:07:41 -0800 |
commit | a4bbf53d88c728da9ff6c316b1e4ded63a8f3940 (patch) | |
tree | 0462f2ab83d7d9e8fe49c98a6625baf62135bcf7 /fs/verity/hash_algs.c | |
parent | 98dc08bae6780bb950b5c0cdefeb662b22482655 (diff) | |
download | linux-a4bbf53d88c728da9ff6c316b1e4ded63a8f3940.tar.bz2 |
fsverity: simplify fsverity_get_digest()
Instead of looking up the algorithm by name in hash_algo_name[] to get
its hash_algo ID, just store the hash_algo ID in the fsverity_hash_alg
struct. Verify at boot time that every fsverity_hash_alg has a valid
hash_algo ID with matching digest size.
Remove an unnecessary memset() of the whole digest array to 0 before the
digest is copied into it.
Finally, remove the pr_debug statement. There is already a pr_debug for
the fsverity digest when the file is opened.
Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Link: https://lore.kernel.org/r/20221129045139.69803-1-ebiggers@kernel.org
Diffstat (limited to 'fs/verity/hash_algs.c')
-rw-r--r-- | fs/verity/hash_algs.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/fs/verity/hash_algs.c b/fs/verity/hash_algs.c index 71d0fccb6d4c..6f8170cf4ae7 100644 --- a/fs/verity/hash_algs.c +++ b/fs/verity/hash_algs.c @@ -16,11 +16,13 @@ struct fsverity_hash_alg fsverity_hash_algs[] = { .name = "sha256", .digest_size = SHA256_DIGEST_SIZE, .block_size = SHA256_BLOCK_SIZE, + .algo_id = HASH_ALGO_SHA256, }, [FS_VERITY_HASH_ALG_SHA512] = { .name = "sha512", .digest_size = SHA512_DIGEST_SIZE, .block_size = SHA512_BLOCK_SIZE, + .algo_id = HASH_ALGO_SHA512, }, }; @@ -324,5 +326,9 @@ void __init fsverity_check_hash_algs(void) */ BUG_ON(!is_power_of_2(alg->digest_size)); BUG_ON(!is_power_of_2(alg->block_size)); + + /* Verify that there is a valid mapping to HASH_ALGO_*. */ + BUG_ON(alg->algo_id == 0); + BUG_ON(alg->digest_size != hash_digest_size[alg->algo_id]); } } |