Skip to content

Commit

Permalink
crypto: ccp - Check for caller result area before using it
Browse files Browse the repository at this point in the history
For a hash operation, the caller doesn't have to supply a result
area on every call so don't use it / update it if it hasn't
been supplied.

Signed-off-by: Tom Lendacky <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
tlendacky authored and herbertx committed Jan 15, 2014
1 parent 77dc4a5 commit 393897c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion drivers/crypto/ccp/ccp-crypto-aes-cmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ static int ccp_aes_cmac_complete(struct crypto_async_request *async_req,
} else
rctx->buf_count = 0;

memcpy(req->result, rctx->iv, digest_size);
/* Update result area if supplied */
if (req->result)
memcpy(req->result, rctx->iv, digest_size);

e_free:
sg_free_table(&rctx->data_sg);
Expand Down
7 changes: 5 additions & 2 deletions drivers/crypto/ccp/ccp-crypto-sha.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,15 @@ static int ccp_sha_finish_hmac(struct crypto_async_request *async_req)
struct ahash_request *req = ahash_request_cast(async_req);
struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
struct ccp_ctx *ctx = crypto_ahash_ctx(tfm);
struct ccp_sha_req_ctx *rctx = ahash_request_ctx(req);
struct scatterlist sg[2];
unsigned int block_size =
crypto_tfm_alg_blocksize(crypto_ahash_tfm(tfm));
unsigned int digest_size = crypto_ahash_digestsize(tfm);

sg_init_table(sg, ARRAY_SIZE(sg));
sg_set_buf(&sg[0], ctx->u.sha.opad, block_size);
sg_set_buf(&sg[1], req->result, digest_size);
sg_set_buf(&sg[1], rctx->ctx, digest_size);

return ccp_sync_hash(ctx->u.sha.hmac_tfm, req->result, sg,
block_size + digest_size);
Expand All @@ -106,7 +107,9 @@ static int ccp_sha_complete(struct crypto_async_request *async_req, int ret)
} else
rctx->buf_count = 0;

memcpy(req->result, rctx->ctx, digest_size);
/* Update result area if supplied */
if (req->result)
memcpy(req->result, rctx->ctx, digest_size);

/* If we're doing an HMAC, we need to perform that on the final op */
if (rctx->final && ctx->u.sha.key_len)
Expand Down

0 comments on commit 393897c

Please sign in to comment.