Skip to content

Commit ad5d278

Browse files
sebastianasDavid S. Miller
authored andcommitted
[CRYPTO] sha: Load the SHA[1|256] module by an alias
Loading the crypto algorithm by the alias instead of by module directly has the advantage that all possible implementations of this algorithm are loaded automatically and the crypto API can choose the best one depending on its priority. Additionally it ensures that the generic implementation as well as the HW driver (if available) is loaded in case the HW driver needs the generic version as fallback in corner cases. Also remove the probe for sha1 in padlock's init code. Quote from Herbert: The probe is actually pointless since we can always probe when the algorithm is actually used which does not lead to dead-locks like this. Signed-off-by: Sebastian Siewior <sebastian@breakpoint.cc> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent f8246af commit ad5d278

6 files changed

Lines changed: 8 additions & 21 deletions

File tree

‎arch/s390/crypto/sha1_s390.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Author(s): Thomas Spatzier
1313
* Jan Glauber (jan.glauber@de.ibm.com)
1414
*
15-
* Derived from "crypto/sha1.c"
15+
* Derived from "crypto/sha1_generic.c"
1616
* Copyright (c) Alan Smithee.
1717
* Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk>
1818
* Copyright (c) Jean-Francois Dive <jef@linuxbe.org>

‎arch/s390/crypto/sha256_s390.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Copyright IBM Corp. 2005,2007
88
* Author(s): Jan Glauber (jang@de.ibm.com)
99
*
10-
* Derived from "crypto/sha256.c"
10+
* Derived from "crypto/sha256_generic.c"
1111
* and "arch/s390/crypto/sha1_s390.c"
1212
*
1313
* This program is free software; you can redistribute it and/or modify it

‎crypto/Makefile‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ obj-$(CONFIG_CRYPTO_XCBC) += xcbc.o
2121
obj-$(CONFIG_CRYPTO_NULL) += crypto_null.o
2222
obj-$(CONFIG_CRYPTO_MD4) += md4.o
2323
obj-$(CONFIG_CRYPTO_MD5) += md5.o
24-
obj-$(CONFIG_CRYPTO_SHA1) += sha1.o
25-
obj-$(CONFIG_CRYPTO_SHA256) += sha256.o
24+
obj-$(CONFIG_CRYPTO_SHA1) += sha1_generic.o
25+
obj-$(CONFIG_CRYPTO_SHA256) += sha256_generic.o
2626
obj-$(CONFIG_CRYPTO_SHA512) += sha512.o
2727
obj-$(CONFIG_CRYPTO_WP512) += wp512.o
2828
obj-$(CONFIG_CRYPTO_TGR192) += tgr192.o

crypto/sha1.c renamed to crypto/sha1_generic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,4 @@ module_exit(fini);
139139
MODULE_LICENSE("GPL");
140140
MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm");
141141

142-
MODULE_ALIAS("sha1-generic");
142+
MODULE_ALIAS("sha1");

crypto/sha256.c renamed to crypto/sha256_generic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,4 +339,4 @@ module_exit(fini);
339339
MODULE_LICENSE("GPL");
340340
MODULE_DESCRIPTION("SHA256 Secure Hash Algorithm");
341341

342-
MODULE_ALIAS("sha256-generic");
342+
MODULE_ALIAS("sha256");

‎drivers/crypto/padlock-sha.c‎

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -253,19 +253,6 @@ static struct crypto_alg sha256_alg = {
253253
}
254254
};
255255

256-
static void __init padlock_sha_check_fallbacks(void)
257-
{
258-
if (!crypto_has_hash("sha1", 0, CRYPTO_ALG_ASYNC |
259-
CRYPTO_ALG_NEED_FALLBACK))
260-
printk(KERN_WARNING PFX
261-
"Couldn't load fallback module for sha1.\n");
262-
263-
if (!crypto_has_hash("sha256", 0, CRYPTO_ALG_ASYNC |
264-
CRYPTO_ALG_NEED_FALLBACK))
265-
printk(KERN_WARNING PFX
266-
"Couldn't load fallback module for sha256.\n");
267-
}
268-
269256
static int __init padlock_init(void)
270257
{
271258
int rc = -ENODEV;
@@ -280,8 +267,6 @@ static int __init padlock_init(void)
280267
return -ENODEV;
281268
}
282269

283-
padlock_sha_check_fallbacks();
284-
285270
rc = crypto_register_alg(&sha1_alg);
286271
if (rc)
287272
goto out;
@@ -314,5 +299,7 @@ MODULE_DESCRIPTION("VIA PadLock SHA1/SHA256 algorithms support.");
314299
MODULE_LICENSE("GPL");
315300
MODULE_AUTHOR("Michal Ludvig");
316301

302+
MODULE_ALIAS("sha1");
303+
MODULE_ALIAS("sha256");
317304
MODULE_ALIAS("sha1-padlock");
318305
MODULE_ALIAS("sha256-padlock");

0 commit comments

Comments
 (0)