Re: [PATCH v2 04/19] crypto: ecrdsa - Migrate to sig_alg backend

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue Sep 10, 2024 at 5:30 PM EEST, Lukas Wunner wrote:
> A sig_alg backend has just been introduced with the intent of moving all
> asymmetric sign/verify algorithms to it one by one.
>
> Migrate ecrdsa.c to the new backend.
>
> One benefit of the new API is the use of kernel buffers instead of
> sglists, which avoids the overhead of copying signature and digest
> sglists back into kernel buffers.  ecrdsa.c is thus simplified quite
> a bit.
>
> Signed-off-by: Lukas Wunner <lukas@xxxxxxxxx>
> ---
>  crypto/Kconfig   |  2 +-
>  crypto/ecrdsa.c  | 56 +++++++++++++++++++++---------------------------
>  crypto/testmgr.c |  4 ++--
>  crypto/testmgr.h |  7 +-----
>  4 files changed, 28 insertions(+), 41 deletions(-)
>
> diff --git a/crypto/Kconfig b/crypto/Kconfig
> index 89b728c72f07..e8488b8c45e3 100644
> --- a/crypto/Kconfig
> +++ b/crypto/Kconfig
> @@ -302,7 +302,7 @@ config CRYPTO_ECDSA
>  config CRYPTO_ECRDSA
>  	tristate "EC-RDSA (Elliptic Curve Russian Digital Signature Algorithm)"
>  	select CRYPTO_ECC
> -	select CRYPTO_AKCIPHER
> +	select CRYPTO_SIG
>  	select CRYPTO_STREEBOG
>  	select OID_REGISTRY
>  	select ASN1
> diff --git a/crypto/ecrdsa.c b/crypto/ecrdsa.c
> index 3811f3805b5d..7383dd11089b 100644
> --- a/crypto/ecrdsa.c
> +++ b/crypto/ecrdsa.c
> @@ -18,12 +18,11 @@
>  
>  #include <linux/module.h>
>  #include <linux/crypto.h>
> +#include <crypto/sig.h>
>  #include <crypto/streebog.h>
> -#include <crypto/internal/akcipher.h>
>  #include <crypto/internal/ecc.h>
> -#include <crypto/akcipher.h>
> +#include <crypto/internal/sig.h>
>  #include <linux/oid_registry.h>
> -#include <linux/scatterlist.h>
>  #include "ecrdsa_params.asn1.h"
>  #include "ecrdsa_pub_key.asn1.h"
>  #include "ecrdsa_defs.h"
> @@ -68,13 +67,12 @@ static const struct ecc_curve *get_curve_by_oid(enum OID oid)
>  	}
>  }
>  
> -static int ecrdsa_verify(struct akcipher_request *req)
> +static int ecrdsa_verify(struct crypto_sig *tfm,
> +			 const void *src, unsigned int slen,
> +			 const void *digest, unsigned int dlen)
>  {
> -	struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
> -	struct ecrdsa_ctx *ctx = akcipher_tfm_ctx(tfm);
> -	unsigned char sig[ECRDSA_MAX_SIG_SIZE];
> -	unsigned char digest[STREEBOG512_DIGEST_SIZE];
> -	unsigned int ndigits = req->dst_len / sizeof(u64);
> +	struct ecrdsa_ctx *ctx = crypto_sig_ctx(tfm);
> +	unsigned int ndigits = dlen / sizeof(u64);
>  	u64 r[ECRDSA_MAX_DIGITS]; /* witness (r) */
>  	u64 _r[ECRDSA_MAX_DIGITS]; /* -r */
>  	u64 s[ECRDSA_MAX_DIGITS]; /* second part of sig (s) */
> @@ -91,25 +89,19 @@ static int ecrdsa_verify(struct akcipher_request *req)
>  	 */
>  	if (!ctx->curve ||
>  	    !ctx->digest ||
> -	    !req->src ||
> +	    !src ||
> +	    !digest ||
>  	    !ctx->pub_key.x ||
> -	    req->dst_len != ctx->digest_len ||
> -	    req->dst_len != ctx->curve->g.ndigits * sizeof(u64) ||
> +	    dlen != ctx->digest_len ||
> +	    dlen != ctx->curve->g.ndigits * sizeof(u64) ||
>  	    ctx->pub_key.ndigits != ctx->curve->g.ndigits ||
> -	    req->dst_len * 2 != req->src_len ||
> -	    WARN_ON(req->src_len > sizeof(sig)) ||
> -	    WARN_ON(req->dst_len > sizeof(digest)))
> +	    dlen * 2 != slen ||
> +	    WARN_ON(slen > ECRDSA_MAX_SIG_SIZE) ||
> +	    WARN_ON(dlen > STREEBOG512_DIGEST_SIZE))

Despite being migration I don't see no point recycling use of WARN_ON()
here, given panic_on_warn kernel command-line flag.

If you want to print to something, please do separate checks and use
pr_warn() instead at most.

BR, Jarkko





[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]
  Powered by Linux