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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 7 Jul 2015 21:49:36 +0800
From:	Herbert Xu <herbert@...dor.apana.org.au>
To:	LABBE Corentin <clabbe.montjoie@...il.com>
Cc:	robh+dt@...nel.org, pawel.moll@....com, mark.rutland@....com,
	ijc+devicetree@...lion.org.uk, galak@...eaurora.org,
	maxime.ripard@...e-electrons.com, linux@....linux.org.uk,
	davem@...emloft.net, akpm@...ux-foundation.org,
	gregkh@...uxfoundation.org, mchehab@....samsung.com, arnd@...db.de,
	joe@...ches.com, devicetree@...r.kernel.org,
	linux-doc@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
	linux-kernel@...r.kernel.org, linux-crypto@...r.kernel.org,
	linux-sunxi@...glegroups.com
Subject: Re: [PATCH v10 4/5] crypto: Add Allwinner Security System crypto
 accelerator

On Mon, Jul 06, 2015 at 09:10:47PM +0200, LABBE Corentin wrote:
>
> +int sun4i_hash_init(struct ahash_request *areq)
> +{
> +	const char *hash_type;
> +	struct sun4i_req_ctx *op = ahash_request_ctx(areq);
> +	struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
> +	struct ahash_alg *alg = __crypto_ahash_alg(tfm->base.__crt_alg);
> +	struct sun4i_ss_alg_template *algt;
> +	struct sun4i_ss_ctx *ss;
> +
> +	memset(op, 0, sizeof(struct sun4i_req_ctx));
> +
> +	algt = container_of(alg, struct sun4i_ss_alg_template, alg.hash);
> +	ss = algt->ss;
> +	op->ss = algt->ss;
> +
> +	hash_type = crypto_tfm_alg_name(areq->base.tfm);
> +
> +	if (strcmp(hash_type, "sha1") == 0)
> +		op->mode = SS_OP_SHA1;
> +	else if (strcmp(hash_type, "md5") == 0)
> +		op->mode = SS_OP_MD5;

Please store these modes in algt and then you wouldn't need to do
the strcmp.

> +int sun4i_hash_import_md5(struct ahash_request *areq, const void *in)
> +{
> +	struct sun4i_req_ctx *op = ahash_request_ctx(areq);
> +	const struct md5_state *ictx = in;
> +	int i;

You need to initialise op->ss here.  Ditto for SHA.

> +	/* get the partial hash only if something was written */
> +	if (op->mode == SS_OP_SHA1) {
> +		for (i = 0; i < 5; i++)
> +			op->hash[i] = readl(ss->base + SS_MD0 + i * 4);
> +	} else {
> +		for (i = 0; i < 4; i++)
> +			op->hash[i] = readl(ss->base + SS_MD0 + i * 4);
> +	}

You can avoid the op->mode check by storing the hash size in algt.

> +int sun4i_hash_finup(struct ahash_request *areq)
> +{
> +	int err;
> +
> +	err = sun4i_hash_update(areq);
> +	if (err != 0)
> +		return err;
> +
> +	return sun4i_hash_final(areq);

You can drop finup since the API provides a default finup that's
exactly the same as this.  You only need to provide finup if it
can optimise on this.

Ditto for digest.
 
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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ