Commit 5d78d57e authored by Tero Kristo's avatar Tero Kristo Committed by Herbert Xu

crypto: omap-sham - buffer handling fixes for hashing later

Currently, the hash later code only handles the cases when we have
either new data coming in with the request or old data in the buffer,
but not the combination when we have both. Fix this by changing the
ordering of the code a bit and handling both cases properly
simultaneously if needed. Also, fix an issue with omap_sham_update
that surfaces with this fix, so that the code checks the bufcnt
instead of total data amount against buffer length to avoid any
buffer overflows.
Signed-off-by: default avatarTero Kristo <t-kristo@ti.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent ad18cc9d
...@@ -874,14 +874,21 @@ static int omap_sham_prepare_request(struct ahash_request *req, bool update) ...@@ -874,14 +874,21 @@ static int omap_sham_prepare_request(struct ahash_request *req, bool update)
} }
if (hash_later) { if (hash_later) {
if (req->nbytes) { int offset = 0;
scatterwalk_map_and_copy(rctx->buffer, req->src,
req->nbytes - hash_later, if (hash_later > req->nbytes) {
hash_later, 0);
} else {
memcpy(rctx->buffer, rctx->buffer + xmit_len, memcpy(rctx->buffer, rctx->buffer + xmit_len,
hash_later); hash_later - req->nbytes);
offset = hash_later - req->nbytes;
} }
if (req->nbytes) {
scatterwalk_map_and_copy(rctx->buffer + offset,
req->src,
offset + req->nbytes -
hash_later, hash_later, 0);
}
rctx->bufcnt = hash_later; rctx->bufcnt = hash_later;
} else { } else {
rctx->bufcnt = 0; rctx->bufcnt = 0;
...@@ -1190,11 +1197,10 @@ static int omap_sham_update(struct ahash_request *req) ...@@ -1190,11 +1197,10 @@ static int omap_sham_update(struct ahash_request *req)
if (!req->nbytes) if (!req->nbytes)
return 0; return 0;
if (ctx->total + req->nbytes < ctx->buflen) { if (ctx->bufcnt + req->nbytes <= ctx->buflen) {
scatterwalk_map_and_copy(ctx->buffer + ctx->bufcnt, req->src, scatterwalk_map_and_copy(ctx->buffer + ctx->bufcnt, req->src,
0, req->nbytes, 0); 0, req->nbytes, 0);
ctx->bufcnt += req->nbytes; ctx->bufcnt += req->nbytes;
ctx->total += req->nbytes;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment