]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
pkcs7: Allow the signing algo to do whatever digestion it wants itself
authorDavid Howells <dhowells@redhat.com>
Wed, 21 Jan 2026 12:41:42 +0000 (12:41 +0000)
committerDavid Howells <dhowells@redhat.com>
Fri, 30 Jan 2026 11:33:19 +0000 (11:33 +0000)
commitf3eccecd782dbaf33d5ad0d1fd22ea277300acdb
treeb3cc963f76706225409181571d37d3af9c23b9df
parentf728074f1f577565c97e465652c3d4afb0964013
pkcs7: Allow the signing algo to do whatever digestion it wants itself

Allow the data to be verified in a PKCS#7 or CMS message to be passed
directly to an asymmetric cipher algorithm (e.g. ML-DSA) if it wants to do
whatever passes for hashing/digestion itself.  The normal digestion of the
data is then skipped as that would be ignored unless another signed info in
the message has some other algorithm that needs it.

The 'data to be verified' may be the content of the PKCS#7 message or it
will be the authenticatedAttributes (signedAttrs if CMS), modified, if
those are present.

This is done by:

 (1) Make ->m and ->m_size point to the data to be verified rather than
     making public_key_verify_signature() access the data directly.  This
     is so that keyctl(KEYCTL_PKEY_VERIFY) will still work.

 (2) Add a flag, ->algo_takes_data, to indicate that the verification
     algorithm wants to access the data to be verified directly rather than
     having it digested first.

 (3) If the PKCS#7 message has authenticatedAttributes (or CMS
     signedAttrs), then the digest contained therein will be validated as
     now, and the modified attrs blob will either be digested or assigned
     to ->m as appropriate.

 (4) If present, always copy and modify the authenticatedAttributes (or
     signedAttrs) then digest that in one go rather than calling the shash
     update twice (once for the tag and once for the rest).

 (5) For ML-DSA, point ->m to the TBSCertificate instead of digesting it
     and using the digest.

Note that whilst ML-DSA does allow for an "external mu", CMS doesn't yet
have that standardised.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Lukas Wunner <lukas@wunner.de>
cc: Ignat Korchagin <ignat@cloudflare.com>
cc: Stephan Mueller <smueller@chronox.de>
cc: Eric Biggers <ebiggers@kernel.org>
cc: Herbert Xu <herbert@gondor.apana.org.au>
cc: keyrings@vger.kernel.org
cc: linux-crypto@vger.kernel.org
crypto/asymmetric_keys/pkcs7_parser.c
crypto/asymmetric_keys/pkcs7_verify.c
crypto/asymmetric_keys/signature.c
crypto/asymmetric_keys/x509_public_key.c
include/crypto/public_key.h