lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <ZEEPjzLIlZW6HaAM@gondor.apana.org.au>
Date:   Thu, 20 Apr 2023 18:10:23 +0800
From:   Herbert Xu <herbert@...dor.apana.org.au>
To:     Jia Jie Ho <jiajie.ho@...rfivetech.com>
Cc:     "David S . Miller" <davem@...emloft.net>,
        Rob Herring <robh+dt@...nel.org>,
        Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
        Palmer Dabbelt <palmer@...belt.com>,
        Emil Renner Berthing <kernel@...il.dk>,
        Conor Dooley <conor@...nel.org>, linux-crypto@...r.kernel.org,
        devicetree@...r.kernel.org, linux-kernel@...r.kernel.org,
        linux-riscv@...ts.infradead.org
Subject: Re: [PATCH v5 4/4] crypto: starfive - Add hash and HMAC support

On Tue, Apr 11, 2023 at 04:14:24PM +0800, Jia Jie Ho wrote:
>
> +static int starfive_hash_export(struct ahash_request *req, void *out)
> +{
> +	struct starfive_cryp_request_ctx *rctx = ahash_request_ctx(req);
> +	struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
> +	struct starfive_cryp_ctx *ctx = crypto_ahash_ctx(tfm);
> +
> +	ahash_request_set_tfm(&rctx->ahash_fbk_req, ctx->ahash_fbk);
> +	ahash_request_set_callback(&rctx->ahash_fbk_req,
> +				   req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP,
> +				   req->base.complete, req->base.data);
> +
> +	ahash_request_set_crypt(&rctx->ahash_fbk_req, req->src,
> +				req->result, req->nbytes);
> +
> +	return crypto_ahash_export(&rctx->ahash_fbk_req, out);
> +}

You can't export a freshly created request.  The fallback
request needs to have been created by the usual init/update
calls.

The export function should simply invoke export.

> +static int starfive_hash_cra_init_algs(struct crypto_tfm *tfm,
> +				       const char *algs_hmac_name,
> +				       unsigned int mode,
> +				       const char *alg_name)
> +{
> +	struct starfive_cryp_ctx *ctx = crypto_tfm_ctx(tfm);
> +	struct crypto_ahash *ahash = __crypto_ahash_cast(tfm);
> +
> +	ctx->cryp = starfive_cryp_find_dev(ctx);
> +
> +	if (!ctx->cryp)
> +		return -ENODEV;
> +
> +	ctx->ahash_fbk = crypto_alloc_ahash(alg_name, 0,
> +					    CRYPTO_ALG_NEED_FALLBACK);
> +
> +	if (IS_ERR(ctx->ahash_fbk))
> +		return dev_err_probe(ctx->cryp->dev, PTR_ERR(ctx->ahash_fbk),
> +				     "starfive_hash: Could not load fallback driver.\n");
> +
> +	crypto_hash_alg_common(ahash)->statesize = crypto_ahash_statesize(ctx->ahash_fbk);

I've just posted a patch to linux-crypto to do this properly:

https://lore.kernel.org/linux-crypto/ZEEOXIHwqKblKfBJ@gondor.apana.org.au/T/#u

Please switch to using the helper that I added.

> +static int starfive_hash256_setkey(struct crypto_ahash *tfm,
> +				   const u8 *key, unsigned int keylen)
> +{
> +	struct starfive_cryp_ctx *ctx = crypto_ahash_ctx(tfm);
> +	unsigned int digestsize = crypto_ahash_digestsize(tfm);
> +	unsigned int blocksize;
> +	int ret = 0;
> +
> +	blocksize = crypto_tfm_alg_blocksize(crypto_ahash_tfm(tfm));

Please use crypto_ahash_blocksize.  We should never use crypto_ahash_tfm
in new code.

> +static int starfive_hash_cra_sha224_init(struct crypto_tfm *tfm)
> +{
> +	return starfive_hash_cra_init_algs(tfm, NULL,
> +					   STARFIVE_HASH_SHA224,
> +					   "sha224-generic");
> +}

Please switch to the new API and use init_tfm/exit_tfm instead of
cra_init/cra_exit.

Thanks,
-- 
Email: Herbert Xu <herbert@...dor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ