Commit 809c9b60 authored by Thorsten Blum's avatar Thorsten Blum Committed by Herbert Xu
Browse files

crypto: omap - convert reqctx buffer to fixed-size array



The flexible array member 'buffer' in 'omap_sham_reqctx' is always
allocated with BUFLEN bytes. Replace the flexible array with a
fixed-size array and remove the now-redundant 'buflen' field.

Since 'struct omap_sham_reqctx' now includes the buffer, simplify
'reqsize' and 'statesize' and use an offsetof-based memcpy() in
omap_sham_export() and omap_sham_import().

Signed-off-by: default avatarThorsten Blum <thorsten.blum@linux.dev>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent a883b38a
Loading
Loading
Loading
Loading
+10 −11
Original line number Diff line number Diff line
@@ -147,7 +147,6 @@ struct omap_sham_reqctx {
	u8			digest[SHA512_DIGEST_SIZE] OMAP_ALIGNED;
	size_t			digcnt;
	size_t			bufcnt;
	size_t			buflen;

	/* walk state */
	struct scatterlist	*sg;
@@ -156,7 +155,7 @@ struct omap_sham_reqctx {
	int			sg_len;
	unsigned int		total;	/* total request */

	u8			buffer[] OMAP_ALIGNED;
	u8			buffer[BUFLEN] OMAP_ALIGNED;
};

struct omap_sham_hmac_ctx {
@@ -891,7 +890,7 @@ static int omap_sham_prepare_request(struct crypto_engine *engine, void *areq)
	if (hash_later < 0)
		hash_later = 0;

	if (hash_later && hash_later <= rctx->buflen) {
	if (hash_later && hash_later <= sizeof(rctx->buffer)) {
		scatterwalk_map_and_copy(rctx->buffer,
					 req->src,
					 req->nbytes - hash_later,
@@ -902,7 +901,7 @@ static int omap_sham_prepare_request(struct crypto_engine *engine, void *areq)
		rctx->bufcnt = 0;
	}

	if (hash_later > rctx->buflen)
	if (hash_later > sizeof(rctx->buffer))
		set_bit(FLAGS_HUGE, &rctx->dd->flags);

	rctx->total = min(nbytes, rctx->total);
@@ -987,7 +986,6 @@ static int omap_sham_init(struct ahash_request *req)
	ctx->digcnt = 0;
	ctx->total = 0;
	ctx->offset = 0;
	ctx->buflen = BUFLEN;

	if (tctx->flags & BIT(FLAGS_HMAC)) {
		if (!test_bit(FLAGS_AUTO_XOR, &dd->flags)) {
@@ -1200,7 +1198,7 @@ static int omap_sham_update(struct ahash_request *req)
	if (!req->nbytes)
		return 0;

	if (ctx->bufcnt + req->nbytes <= ctx->buflen) {
	if (ctx->bufcnt + req->nbytes <= sizeof(ctx->buffer)) {
		scatterwalk_map_and_copy(ctx->buffer + ctx->bufcnt, req->src,
					 0, req->nbytes, 0);
		ctx->bufcnt += req->nbytes;
@@ -1333,7 +1331,7 @@ static int omap_sham_cra_init_alg(struct crypto_tfm *tfm, const char *alg_base)
	}

	crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm),
				 sizeof(struct omap_sham_reqctx) + BUFLEN);
				 sizeof(struct omap_sham_reqctx));

	if (alg_base) {
		struct omap_sham_hmac_ctx *bctx = tctx->base;
@@ -1404,7 +1402,8 @@ static int omap_sham_export(struct ahash_request *req, void *out)
{
	struct omap_sham_reqctx *rctx = ahash_request_ctx(req);

	memcpy(out, rctx, sizeof(*rctx) + rctx->bufcnt);
	memcpy(out, rctx, offsetof(struct omap_sham_reqctx, buffer) +
			  rctx->bufcnt);

	return 0;
}
@@ -1414,7 +1413,8 @@ static int omap_sham_import(struct ahash_request *req, const void *in)
	struct omap_sham_reqctx *rctx = ahash_request_ctx(req);
	const struct omap_sham_reqctx *ctx_in = in;

	memcpy(rctx, in, sizeof(*rctx) + ctx_in->bufcnt);
	memcpy(rctx, in, offsetof(struct omap_sham_reqctx, buffer) +
			 ctx_in->bufcnt);

	return 0;
}
@@ -2146,8 +2146,7 @@ static int omap_sham_probe(struct platform_device *pdev)
			alg = &ealg->base;
			alg->export = omap_sham_export;
			alg->import = omap_sham_import;
			alg->halg.statesize = sizeof(struct omap_sham_reqctx) +
					      BUFLEN;
			alg->halg.statesize = sizeof(struct omap_sham_reqctx);
			err = crypto_engine_register_ahash(ealg);
			if (err)
				goto err_algs;