Convert lib/digsig.c to SHA-1 library
Subsystems (6)
cover Convert lib/digsig.c to SHA-1 library
This series converts lib/digsig.c to use the SHA-1 library API.
Please consider taking this series through the integrity tree.
Eric Biggers (2):
integrity: Select CRYPTO from INTEGRITY_ASYMMETRIC_KEYS lib/digsig: Use SHA-1 library instead of crypto_shash
lib/Kconfig | 3 +-- lib/digsig.c | 46 +++++--------------------------------- security/integrity/Kconfig | 1 + 3 files changed, 8 insertions(+), 42 deletions(-)
base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585
Signature · 1 line
2.50.1
PATCH 1/2 integrity: Select CRYPTO from INTEGRITY_ASYMMETRIC_KEYS
Select CRYPTO from INTEGRITY_ASYMMETRIC_KEYS, since INTEGRITY_ASYMMETRIC_KEYS selects several options that depend on CRYPTO.
This unblocks the removal of the CRYPTO selection from SIGNATURE. SIGNATURE (lib/digsig.c) itself will no longer need CRYPTO, but INTEGRITY_ASYMMETRIC_KEYS was depending on it indirectly via the chain SIGNATURE => INTEGRITY_SIGNATURE => INTEGRITY_ASYMMETRIC_KEYS.
--- security/integrity/Kconfig | 1 + 1 file changed, 1 insertion(+)
security/integrity/Kconfig +1 -0
@@ -34,10 +34,11 @@ config INTEGRITY_ASYMMETRIC_KEYS bool "Enable asymmetric keys support" depends on INTEGRITY_SIGNATURE default n select ASYMMETRIC_KEY_TYPE select ASYMMETRIC_PUBLIC_KEY_SUBTYPE + select CRYPTO select CRYPTO_RSA select X509_CERTIFICATE_PARSER help This option enables digital signature verification using asymmetric keys.
Signature · 1 line
2.50.1
Re: [PATCH 1/2] integrity: Select CRYPTO from INTEGRITY_ASYMMETRIC_KEYS
Dear Eric,
Thank you for your patch.
Am 15.08.25 um 04:17 schrieb Eric Biggers:
Quoted 19 lines
Select CRYPTO from
INTEGRITY_ASYMMETRIC_KEYS, sinceINTEGRITY_ASYMMETRIC_KEYSselects several options that depend on CRYPTO.This unblocks the removal of the CRYPTO selection from SIGNATURE. SIGNATURE (
lib/digsig.c) itself will no longer need CRYPTO, butINTEGRITY_ASYMMETRIC_KEYSwas depending on it indirectly via the chain SIGNATURE =>INTEGRITY_SIGNATURE=>INTEGRITY_ASYMMETRIC_KEYS.Signed-off-by Eric Biggers <[email protected]>--- security/integrity/Kconfig | 1 + 1 file changed, 1 insertion(+)security/integrity/Kconfig +0
-0@@ -34,10 +34,11 @@ config INTEGRITY_ASYMMETRIC_KEYS bool "Enable asymmetric keys support"
security/integrity/Kconfig config INTEGRITY_ASYMMETRIC_KEYS · line 44
Quoted 10 lines
security/integrity/Kconfig +1
-0depends on INTEGRITY_SIGNATURE default n select ASYMMETRIC_KEY_TYPE select ASYMMETRIC_PUBLIC_KEY_SUBTYPE + select CRYPTO select CRYPTO_RSA select X509_CERTIFICATE_PARSER help This option enables digital signature verification using asymmetric keys.
Kind regards,
Paul
PATCH 2/2 lib/digsig: Use SHA-1 library instead of crypto_shash
In reply to Eric BiggersNow that a SHA-1 library API is available, use it instead of crypto_shash. This is simpler and faster.
--- lib/Kconfig | 3 +-- lib/digsig.c | 46 ++++++---------------------------------------- 2 files changed, 7 insertions(+), 42 deletions(-)
lib/Kconfig +1 -2
@@ -475,12 +475,11 @@ config MPILIB which is used by IMA/EVM digital signature extension. config SIGNATURE tristate depends on KEYS - select CRYPTO - select CRYPTO_SHA1 + select CRYPTO_LIB_SHA1 select MPILIB help Digital signature verification. Currently only RSA is supported. Implementation is done using GnuPG MPI library
lib/digsig.c +6 -40
92 lines not on this page · raw message
Signature · 1 line
2.50.1
Re: [PATCH 2/2] lib/digsig: Use SHA-1 library instead of crypto_shash
Dear Eric,
Thank you for your patch.
Am 15.08.25 um 04:17 schrieb Eric Biggers:
Quoted 116 lines
Now that a SHA-1 library API is available, use it instead of
crypto_shash. This is simpler and faster.Signed-off-by Eric Biggers <[email protected]>--- lib/Kconfig | 3 +-- lib/digsig.c | 46 ++++++---------------------------------------- 2 files changed, 7 insertions(+), 42 deletions(-)lib/Kconfig +1
-2@@ -475,12 +475,11 @@ config MPILIB which is used by IMA/EVM digital signature extension. config SIGNATURE tristate depends on KEYS - select CRYPTO - select CRYPTO_SHA1 + select CRYPTO_LIB_SHA1 select MPILIB help Digital signature verification. Currently only RSA is supported. Implementation is done using GnuPG MPI librarylib/digsig.c +6
-31@@ -16,19 +16,15 @@#include <linux/err.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/key.h> -#include <linux/crypto.h> -#include <crypto/hash.h> #include <crypto/sha1.h> #include <keys/user-type.h> #include <linux/mpi.h> #include <linux/digsig.h> -static struct crypto_shash *shash; -static const char *pkcs_1_v1_5_decode_emsa (const unsigned char *msg,unsigned long msglen,unsigned long modulus_bitlen,unsigned long *outlen) {@@ -197,16 +193,16 @@ static int digsig_verify_rsa(struct key *key,* */ int digsig_verify (struct key *keyring,const char *sig,int siglen,const char *data,int datalen) { -int err = -ENOMEM ;struct signature_hdr *sh = (struct signature_hdr *)sig; -struct shash_desc *desc =NULL ; +struct sha1_ctx ctx;unsigned char hash[SHA1_DIGEST_SIZE ];struct key *key;char name[20 ]; +int err;if (siglen <sizeof (*sh) +2 )return -EINVAL ;if (sh->algo !=PUBKEY_ALGO_RSA )@@ -229,51 +225,21 @@ int digsig_verify(struct key *keyring, const char *sig, int siglen,if (IS_ERR (key)) {pr_err ("key not found, id: %s\n" , name);return PTR_ERR (key); } - desc =kzalloc (sizeof (*desc) +crypto_shash_descsize (shash), -GFP_KERNEL ); -if (!desc) - goto err; - - desc->tfm = shash; - -crypto_shash_init (desc); -crypto_shash_update (desc, data, datalen); -crypto_shash_update (desc, sig,sizeof (*sh)); -crypto_shash_final (desc, hash); - -kfree (desc); +sha1_init (&ctx); +sha1_update (&ctx, data, datalen); +sha1_update (&ctx, sig,sizeof (*sh)); +sha1_final (&ctx, hash);/* pass signature mpis address */ err =digsig_verify_rsa (key, sig +sizeof (*sh), siglen -sizeof (*sh), hash,sizeof (hash)); -err:key_put (key);return err ? -EINVAL :0 ; }EXPORT_SYMBOL_GPL (digsig_verify); -static int __init digsig_init (void ) -{ - shash =crypto_alloc_shash ("sha1" ,0 ,0 ); -if (IS_ERR (shash)) { -pr_err ("shash allocation failed\n" ); -return PTR_ERR (shash); - } - -return 0 ; - -}
lib/digsig.c int digsig_verify(struct key *keyring, const char *sig, int siglen, · line 245
Quoted 10 lines
lib/digsig.c +0
-9- -static void __exit digsig_cleanup(void) -{ -crypto_free_shash (shash); -} - -module_init (digsig_init); -module_exit (digsig_cleanup); -MODULE_LICENSE ("GPL" );
Kind regards,
Paul
Mimi Zohar
maintainerQuoted 5 lines · Eric Biggers
This series converts
lib/digsig.cto use the SHA-1 library API.Please consider taking this series through the integrity tree.
Eric Biggers (2):
Thanks, Eric.
Mimi