summaryrefslogtreecommitdiffstats
path: root/drivers/crypto/omap-sham.c
diff options
context:
space:
mode:
authorTero Kristo <t-kristo@ti.com>2017-05-24 03:35:32 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2017-06-10 00:04:19 -0400
commit5d78d57ede8f9e7f656c610ed25be7be337e0529 (patch)
tree4c8434bae305c92272b5ac2dc0b97b9c4714333b /drivers/crypto/omap-sham.c
parentad18cc9d0f911928704cdc37f4d126853daa9e4e (diff)
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: Tero Kristo <t-kristo@ti.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto/omap-sham.c')
-rw-r--r--drivers/crypto/omap-sham.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/drivers/crypto/omap-sham.c b/drivers/crypto/omap-sham.c
index 1864a57caaa4..ca9e48a19b15 100644
--- a/drivers/crypto/omap-sham.c
+++ b/drivers/crypto/omap-sham.c
@@ -874,14 +874,21 @@ static int omap_sham_prepare_request(struct ahash_request *req, bool update)
874 } 874 }
875 875
876 if (hash_later) { 876 if (hash_later) {
877 if (req->nbytes) { 877 int offset = 0;
878 scatterwalk_map_and_copy(rctx->buffer, req->src, 878
879 req->nbytes - hash_later, 879 if (hash_later > req->nbytes) {
880 hash_later, 0);
881 } else {
882 memcpy(rctx->buffer, rctx->buffer + xmit_len, 880 memcpy(rctx->buffer, rctx->buffer + xmit_len,
883 hash_later); 881 hash_later - req->nbytes);
882 offset = hash_later - req->nbytes;
884 } 883 }
884
885 if (req->nbytes) {
886 scatterwalk_map_and_copy(rctx->buffer + offset,
887 req->src,
888 offset + req->nbytes -
889 hash_later, hash_later, 0);
890 }
891
885 rctx->bufcnt = hash_later; 892 rctx->bufcnt = hash_later;
886 } else { 893 } else {
887 rctx->bufcnt = 0; 894 rctx->bufcnt = 0;
@@ -1190,11 +1197,10 @@ static int omap_sham_update(struct ahash_request *req)
1190 if (!req->nbytes) 1197 if (!req->nbytes)
1191 return 0; 1198 return 0;
1192 1199
1193 if (ctx->total + req->nbytes < ctx->buflen) { 1200 if (ctx->bufcnt + req->nbytes <= ctx->buflen) {
1194 scatterwalk_map_and_copy(ctx->buffer + ctx->bufcnt, req->src, 1201 scatterwalk_map_and_copy(ctx->buffer + ctx->bufcnt, req->src,
1195 0, req->nbytes, 0); 1202 0, req->nbytes, 0);
1196 ctx->bufcnt += req->nbytes; 1203 ctx->bufcnt += req->nbytes;
1197 ctx->total += req->nbytes;
1198 return 0; 1204 return 0;
1199 } 1205 }
1200 1206