Merge pull request #182 from lyctw/master

Add error message when sha256 algorithm is not supported
This commit is contained in:
Jim Huang 2022-12-13 01:11:45 +08:00 committed by GitHub
commit 0decb83073
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -26,8 +26,12 @@ static int cryptosha256_init(void)
struct shash_desc *shash; struct shash_desc *shash;
sha256 = crypto_alloc_shash("sha256", 0, 0); sha256 = crypto_alloc_shash("sha256", 0, 0);
if (IS_ERR(sha256)) if (IS_ERR(sha256)) {
pr_err(
"%s(): Failed to allocate sha256 algorithm, enable CONFIG_CRYPTO_SHA256 and try again.\n",
__func__);
return -1; return -1;
}
shash = kmalloc(sizeof(struct shash_desc) + crypto_shash_descsize(sha256), shash = kmalloc(sizeof(struct shash_desc) + crypto_shash_descsize(sha256),
GFP_KERNEL); GFP_KERNEL);

View File

@ -1891,6 +1891,7 @@ To handle crypto stuff, the kernel has its own API enabling common methods of en
Calculating and checking the hashes of things is a common operation. Calculating and checking the hashes of things is a common operation.
Here is a demonstration of how to calculate a sha256 hash within a kernel module. Here is a demonstration of how to calculate a sha256 hash within a kernel module.
To provide the sha256 algorithm support, make sure \cpp|CONFIG_CRYPTO_SHA256| is enabled in kernel.
\samplec{examples/cryptosha256.c} \samplec{examples/cryptosha256.c}