aboutsummaryrefslogtreecommitdiffstats
path: root/arch/s390
diff options
context:
space:
mode:
authorJan Glauber <jan.glauber@de.ibm.com>2006-01-14 16:20:56 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2006-01-14 21:27:08 -0500
commit7ffbc9da137ef475afd5e01f72e1ce1ce49668b1 (patch)
treece30c284745e148e4159190ae84b700d556bd67b /arch/s390
parentfda5e142598341d30006e3715e53b2c983a9fca7 (diff)
[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>
Diffstat (limited to 'arch/s390')
-rw-r--r--arch/s390/crypto/sha256_s390.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/arch/s390/crypto/sha256_s390.c b/arch/s390/crypto/sha256_s390.c
index b75bdbd476c7..1ec5e92b3454 100644
--- a/arch/s390/crypto/sha256_s390.c
+++ b/arch/s390/crypto/sha256_s390.c
@@ -51,6 +51,7 @@ static void sha256_update(void *ctx, const u8 *data, unsigned int len)
51{ 51{
52 struct s390_sha256_ctx *sctx = ctx; 52 struct s390_sha256_ctx *sctx = ctx;
53 unsigned int index; 53 unsigned int index;
54 int ret;
54 55
55 /* how much is already in the buffer? */ 56 /* how much is already in the buffer? */
56 index = sctx->count / 8 & 0x3f; 57 index = sctx->count / 8 & 0x3f;
@@ -58,15 +59,29 @@ static void sha256_update(void *ctx, const u8 *data, unsigned int len)
58 /* update message bit length */ 59 /* update message bit length */
59 sctx->count += len * 8; 60 sctx->count += len * 8;
60 61
61 /* process one block */ 62 if ((index + len) < SHA256_BLOCK_SIZE)
62 if ((index + len) >= SHA256_BLOCK_SIZE) { 63 goto store;
64
65 /* process one stored block */
66 if (index) {
63 memcpy(sctx->buf + index, data, SHA256_BLOCK_SIZE - index); 67 memcpy(sctx->buf + index, data, SHA256_BLOCK_SIZE - index);
64 crypt_s390_kimd(KIMD_SHA_256, sctx->state, sctx->buf, 68 ret = crypt_s390_kimd(KIMD_SHA_256, sctx->state, sctx->buf,
65 SHA256_BLOCK_SIZE); 69 SHA256_BLOCK_SIZE);
70 BUG_ON(ret != SHA256_BLOCK_SIZE);
66 data += SHA256_BLOCK_SIZE - index; 71 data += SHA256_BLOCK_SIZE - index;
67 len -= SHA256_BLOCK_SIZE - index; 72 len -= SHA256_BLOCK_SIZE - index;
68 } 73 }
69 74
75 /* process as many blocks as possible */
76 if (len >= SHA256_BLOCK_SIZE) {
77 ret = crypt_s390_kimd(KIMD_SHA_256, sctx->state, data,
78 len & ~(SHA256_BLOCK_SIZE - 1));
79 BUG_ON(ret != (len & ~(SHA256_BLOCK_SIZE - 1)));
80 data += ret;
81 len -= ret;
82 }
83
84store:
70 /* anything left? */ 85 /* anything left? */
71 if (len) 86 if (len)
72 memcpy(sctx->buf + index , data, len); 87 memcpy(sctx->buf + index , data, len);
@@ -119,9 +134,9 @@ static struct crypto_alg alg = {
119 .cra_list = LIST_HEAD_INIT(alg.cra_list), 134 .cra_list = LIST_HEAD_INIT(alg.cra_list),
120 .cra_u = { .digest = { 135 .cra_u = { .digest = {
121 .dia_digestsize = SHA256_DIGEST_SIZE, 136 .dia_digestsize = SHA256_DIGEST_SIZE,
122 .dia_init = sha256_init, 137 .dia_init = sha256_init,
123 .dia_update = sha256_update, 138 .dia_update = sha256_update,
124 .dia_final = sha256_final } } 139 .dia_final = sha256_final } }
125}; 140};
126 141
127static int init(void) 142static int init(void)