diff options
-rw-r--r-- | arch/s390/crypto/sha256_s390.c | 29 |
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 | |||
84 | store: | ||
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 | ||
127 | static int init(void) | 142 | static int init(void) |