aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/crypto/nx/nx-sha256.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/crypto/nx/nx-sha256.c')
-rw-r--r--drivers/crypto/nx/nx-sha256.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/drivers/crypto/nx/nx-sha256.c b/drivers/crypto/nx/nx-sha256.c
index 9767315f8c0b..67024f2f0b78 100644
--- a/drivers/crypto/nx/nx-sha256.c
+++ b/drivers/crypto/nx/nx-sha256.c
@@ -69,7 +69,7 @@ static int nx_sha256_update(struct shash_desc *desc, const u8 *data,
69 * 1: <= SHA256_BLOCK_SIZE: copy into state, return 0 69 * 1: <= SHA256_BLOCK_SIZE: copy into state, return 0
70 * 2: > SHA256_BLOCK_SIZE: process X blocks, copy in leftover 70 * 2: > SHA256_BLOCK_SIZE: process X blocks, copy in leftover
71 */ 71 */
72 if (len + sctx->count <= SHA256_BLOCK_SIZE) { 72 if (len + sctx->count < SHA256_BLOCK_SIZE) {
73 memcpy(sctx->buf + sctx->count, data, len); 73 memcpy(sctx->buf + sctx->count, data, len);
74 sctx->count += len; 74 sctx->count += len;
75 goto out; 75 goto out;
@@ -110,7 +110,8 @@ static int nx_sha256_update(struct shash_desc *desc, const u8 *data,
110 atomic_inc(&(nx_ctx->stats->sha256_ops)); 110 atomic_inc(&(nx_ctx->stats->sha256_ops));
111 111
112 /* copy the leftover back into the state struct */ 112 /* copy the leftover back into the state struct */
113 memcpy(sctx->buf, data + len - leftover, leftover); 113 if (leftover)
114 memcpy(sctx->buf, data + len - leftover, leftover);
114 sctx->count = leftover; 115 sctx->count = leftover;
115 116
116 csbcpb->cpb.sha256.message_bit_length += (u64) 117 csbcpb->cpb.sha256.message_bit_length += (u64)
@@ -130,6 +131,7 @@ static int nx_sha256_final(struct shash_desc *desc, u8 *out)
130 struct nx_sg *in_sg, *out_sg; 131 struct nx_sg *in_sg, *out_sg;
131 int rc; 132 int rc;
132 133
134
133 if (NX_CPB_FDM(csbcpb) & NX_FDM_CONTINUATION) { 135 if (NX_CPB_FDM(csbcpb) & NX_FDM_CONTINUATION) {
134 /* we've hit the nx chip previously, now we're finalizing, 136 /* we've hit the nx chip previously, now we're finalizing,
135 * so copy over the partial digest */ 137 * so copy over the partial digest */
@@ -162,7 +164,7 @@ static int nx_sha256_final(struct shash_desc *desc, u8 *out)
162 164
163 atomic_inc(&(nx_ctx->stats->sha256_ops)); 165 atomic_inc(&(nx_ctx->stats->sha256_ops));
164 166
165 atomic64_add(csbcpb->cpb.sha256.message_bit_length, 167 atomic64_add(csbcpb->cpb.sha256.message_bit_length / 8,
166 &(nx_ctx->stats->sha256_bytes)); 168 &(nx_ctx->stats->sha256_bytes));
167 memcpy(out, csbcpb->cpb.sha256.message_digest, SHA256_DIGEST_SIZE); 169 memcpy(out, csbcpb->cpb.sha256.message_digest, SHA256_DIGEST_SIZE);
168out: 170out: