[PATCH] s390: sha256 crypto code fix

Fix processing of messages larger than 2 * SHA256_BLOCK_SIZE.

Signed-off-by: Jan Glauber <jan.glauber@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by Jan Glauber and committed by Linus Torvalds 7ffbc9da fda5e142

+22 -7
+22 -7
arch/s390/crypto/sha256_s390.c
··· 51 51 { 52 52 struct s390_sha256_ctx *sctx = ctx; 53 53 unsigned int index; 54 + int ret; 54 55 55 56 /* how much is already in the buffer? */ 56 57 index = sctx->count / 8 & 0x3f; ··· 59 58 /* update message bit length */ 60 59 sctx->count += len * 8; 61 60 62 - /* process one block */ 63 - if ((index + len) >= SHA256_BLOCK_SIZE) { 61 + if ((index + len) < SHA256_BLOCK_SIZE) 62 + goto store; 63 + 64 + /* process one stored block */ 65 + if (index) { 64 66 memcpy(sctx->buf + index, data, SHA256_BLOCK_SIZE - index); 65 - crypt_s390_kimd(KIMD_SHA_256, sctx->state, sctx->buf, 66 - SHA256_BLOCK_SIZE); 67 + ret = crypt_s390_kimd(KIMD_SHA_256, sctx->state, sctx->buf, 68 + SHA256_BLOCK_SIZE); 69 + BUG_ON(ret != SHA256_BLOCK_SIZE); 67 70 data += SHA256_BLOCK_SIZE - index; 68 71 len -= SHA256_BLOCK_SIZE - index; 69 72 } 70 73 74 + /* process as many blocks as possible */ 75 + if (len >= SHA256_BLOCK_SIZE) { 76 + ret = crypt_s390_kimd(KIMD_SHA_256, sctx->state, data, 77 + len & ~(SHA256_BLOCK_SIZE - 1)); 78 + BUG_ON(ret != (len & ~(SHA256_BLOCK_SIZE - 1))); 79 + data += ret; 80 + len -= ret; 81 + } 82 + 83 + store: 71 84 /* anything left? */ 72 85 if (len) 73 86 memcpy(sctx->buf + index , data, len); ··· 134 119 .cra_list = LIST_HEAD_INIT(alg.cra_list), 135 120 .cra_u = { .digest = { 136 121 .dia_digestsize = SHA256_DIGEST_SIZE, 137 - .dia_init = sha256_init, 138 - .dia_update = sha256_update, 139 - .dia_final = sha256_final } } 122 + .dia_init = sha256_init, 123 + .dia_update = sha256_update, 124 + .dia_final = sha256_final } } 140 125 }; 141 126 142 127 static int init(void)