Re: [PATCHv4 3/7] crypto: sa2ul: add sha1/sha256/sha512 support

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

 



On Mon, Jun 15, 2020 at 10:14:48AM +0300, Tero Kristo wrote:
>
> +static int sa_sha_update(struct ahash_request *req)
> +{
> +	struct sa_sha_req_ctx *rctx = ahash_request_ctx(req);
> +	struct scatterlist *sg;
> +	void *buf;
> +	int pages;
> +	struct page *pg;
> +
> +	if (!req->nbytes)
> +		return 0;
> +
> +	if (rctx->buf_free >= req->nbytes) {
> +		pg = sg_page(rctx->sg_next);
> +		buf = kmap_atomic(pg);
> +		scatterwalk_map_and_copy(buf + rctx->offset, req->src, 0,
> +					 req->nbytes, 0);
> +		kunmap_atomic(buf);
> +		rctx->buf_free -= req->nbytes;
> +		rctx->sg_next->length += req->nbytes;
> +		rctx->offset += req->nbytes;
> +	} else {
> +		pages = get_order(req->nbytes);
> +		buf = (void *)__get_free_pages(GFP_ATOMIC, pages);
> +		if (!buf)
> +			return -ENOMEM;
> +
> +		sg = kzalloc(sizeof(*sg) * 2, GFP_KERNEL);
> +		if (!sg)
> +			return -ENOMEM;
> +
> +		sg_init_table(sg, 1);
> +		sg_set_buf(sg, buf, req->nbytes);
> +		scatterwalk_map_and_copy(buf, req->src, 0, req->nbytes, 0);
> +
> +		rctx->buf_free = (PAGE_SIZE << pages) - req->nbytes;
> +
> +		if (rctx->sg_next) {
> +			sg_unmark_end(rctx->sg_next);
> +			sg_chain(rctx->sg_next, 2, sg);
> +		} else {
> +			rctx->src = sg;
> +		}
> +
> +		rctx->sg_next = sg;
> +		rctx->src_nents++;
> +
> +		rctx->offset = req->nbytes;
> +	}
> +
> +	rctx->len += req->nbytes;
> +
> +	return 0;
> +}

This is not how it's supposed to work.  To support the partial
hashing interface, you must actually hash the data and not just
save it in your context.  Otherwise your export is completely
meaningless.

If your hardware cannot export partially hashed state, then you
should use a software fallback for everything but digest.

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



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

  Powered by Linux