Skip to content

Commit 3133ee5

Browse files
committed
Add error message when sha256 algorithm is not supported
It failed silently when crypto_alloc_tfm() failed, so add an error message to inform the developer to enable sha256 algorithm support. Signed-off-by: Yu Chien Peter Lin <[email protected]>
1 parent d249317 commit 3133ee5

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

examples/cryptosha256.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ static int cryptosha256_init(void)
2626
struct shash_desc *shash;
2727

2828
sha256 = crypto_alloc_shash("sha256", 0, 0);
29-
if (IS_ERR(sha256))
29+
if (IS_ERR(sha256)) {
30+
pr_err(
31+
"%s(): Failed to allocate sha256 algorithm, enable CONFIG_CRYPTO_SHA256 and try again.\n",
32+
__func__);
3033
return -1;
34+
}
3135

3236
shash = kmalloc(sizeof(struct shash_desc) + crypto_shash_descsize(sha256),
3337
GFP_KERNEL);

lkmpg.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,6 +1891,7 @@ \subsection{Hash functions}
18911891

18921892
Calculating and checking the hashes of things is a common operation.
18931893
Here is a demonstration of how to calculate a sha256 hash within a kernel module.
1894+
To provide the sha256 algorithm support, make sure \cpp|CONFIG_CRYPTO_SHA256| is enabled in kernel.
18941895

18951896
\samplec{examples/cryptosha256.c}
18961897

0 commit comments

Comments
 (0)