crypto: ecdsa - Move X9.62 signature size calculation into template
authorLukas Wunner <lukas@wunner.de>
Tue, 10 Sep 2024 14:30:27 +0000 (16:30 +0200)
committerHerbert Xu <herbert@gondor.apana.org.au>
Sat, 5 Oct 2024 05:22:04 +0000 (13:22 +0800)
commita2471684dae23a676b4badea306140d24e6507f5
treed8a7c20186b1eab3d0edb21720db5b7e26f1401c
parent221f00418e726237dbe38ba627ce08b22d3667f7
crypto: ecdsa - Move X9.62 signature size calculation into template

software_key_query() returns the maximum signature and digest size for a
given key to user space.  When it only supported RSA keys, calculating
those sizes was trivial as they were always equivalent to the key size.

However when ECDSA was added, the function grew somewhat complicated
calculations which take the ASN.1 encoding and curve into account.
This doesn't scale well and adjusting the calculations is easily
forgotten when adding support for new encodings or curves.  In fact,
when NIST P521 support was recently added, the function was initially
not amended:

https://lore.kernel.org/all/b749d5ee-c3b8-4cbd-b252-7773e4536e07@linux.ibm.com/

Introduce a ->max_size() callback to struct sig_alg and take advantage
of it to move the signature size calculations to ecdsa-x962.c.

Introduce a ->digest_size() callback to struct sig_alg and move the
maximum ECDSA digest size to ecdsa.c.  It is common across ecdsa-x962.c
and the upcoming ecdsa-p1363.c and thus inherited by both of them.

For all other algorithms, continue using the key size as maximum
signature and digest size.

Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Documentation/crypto/api-sig.rst
crypto/asymmetric_keys/public_key.c
crypto/ecdsa-x962.c
crypto/ecdsa.c
crypto/sig.c
include/crypto/sig.h