提交 7ffbc9da 编写于 作者: J Jan Glauber 提交者: Linus Torvalds

[PATCH] s390: sha256 crypto code fix

Fix processing of messages larger than 2 * SHA256_BLOCK_SIZE.
Signed-off-by: NJan Glauber <jan.glauber@de.ibm.com>
Signed-off-by: NMartin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: NAndrew Morton <akpm@osdl.org>
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
上级 fda5e142
...@@ -51,6 +51,7 @@ static void sha256_update(void *ctx, const u8 *data, unsigned int len) ...@@ -51,6 +51,7 @@ static void sha256_update(void *ctx, const u8 *data, unsigned int len)
{ {
struct s390_sha256_ctx *sctx = ctx; struct s390_sha256_ctx *sctx = ctx;
unsigned int index; unsigned int index;
int ret;
/* how much is already in the buffer? */ /* how much is already in the buffer? */
index = sctx->count / 8 & 0x3f; index = sctx->count / 8 & 0x3f;
...@@ -58,15 +59,29 @@ static void sha256_update(void *ctx, const u8 *data, unsigned int len) ...@@ -58,15 +59,29 @@ static void sha256_update(void *ctx, const u8 *data, unsigned int len)
/* update message bit length */ /* update message bit length */
sctx->count += len * 8; sctx->count += len * 8;
/* process one block */ if ((index + len) < SHA256_BLOCK_SIZE)
if ((index + len) >= SHA256_BLOCK_SIZE) { goto store;
/* process one stored block */
if (index) {
memcpy(sctx->buf + index, data, SHA256_BLOCK_SIZE - index); memcpy(sctx->buf + index, data, SHA256_BLOCK_SIZE - index);
crypt_s390_kimd(KIMD_SHA_256, sctx->state, sctx->buf, ret = crypt_s390_kimd(KIMD_SHA_256, sctx->state, sctx->buf,
SHA256_BLOCK_SIZE); SHA256_BLOCK_SIZE);
BUG_ON(ret != SHA256_BLOCK_SIZE);
data += SHA256_BLOCK_SIZE - index; data += SHA256_BLOCK_SIZE - index;
len -= SHA256_BLOCK_SIZE - index; len -= SHA256_BLOCK_SIZE - index;
} }
/* process as many blocks as possible */
if (len >= SHA256_BLOCK_SIZE) {
ret = crypt_s390_kimd(KIMD_SHA_256, sctx->state, data,
len & ~(SHA256_BLOCK_SIZE - 1));
BUG_ON(ret != (len & ~(SHA256_BLOCK_SIZE - 1)));
data += ret;
len -= ret;
}
store:
/* anything left? */ /* anything left? */
if (len) if (len)
memcpy(sctx->buf + index , data, len); memcpy(sctx->buf + index , data, len);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册