aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/sha256.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/sha256.c')
-rw-r--r--crypto/sha256.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/crypto/sha256.c b/crypto/sha256.c
index 9d5ef674d6a9..bc71d85a7d02 100644
--- a/crypto/sha256.c
+++ b/crypto/sha256.c
@@ -230,9 +230,9 @@ static void sha256_transform(u32 *state, const u8 *input)
230 memset(W, 0, 64 * sizeof(u32)); 230 memset(W, 0, 64 * sizeof(u32));
231} 231}
232 232
233static void sha256_init(void *ctx) 233static void sha256_init(struct crypto_tfm *tfm)
234{ 234{
235 struct sha256_ctx *sctx = ctx; 235 struct sha256_ctx *sctx = crypto_tfm_ctx(tfm);
236 sctx->state[0] = H0; 236 sctx->state[0] = H0;
237 sctx->state[1] = H1; 237 sctx->state[1] = H1;
238 sctx->state[2] = H2; 238 sctx->state[2] = H2;
@@ -242,12 +242,12 @@ static void sha256_init(void *ctx)
242 sctx->state[6] = H6; 242 sctx->state[6] = H6;
243 sctx->state[7] = H7; 243 sctx->state[7] = H7;
244 sctx->count[0] = sctx->count[1] = 0; 244 sctx->count[0] = sctx->count[1] = 0;
245 memset(sctx->buf, 0, sizeof(sctx->buf));
246} 245}
247 246
248static void sha256_update(void *ctx, const u8 *data, unsigned int len) 247static void sha256_update(struct crypto_tfm *tfm, const u8 *data,
248 unsigned int len)
249{ 249{
250 struct sha256_ctx *sctx = ctx; 250 struct sha256_ctx *sctx = crypto_tfm_ctx(tfm);
251 unsigned int i, index, part_len; 251 unsigned int i, index, part_len;
252 252
253 /* Compute number of bytes mod 128 */ 253 /* Compute number of bytes mod 128 */
@@ -277,9 +277,9 @@ static void sha256_update(void *ctx, const u8 *data, unsigned int len)
277 memcpy(&sctx->buf[index], &data[i], len-i); 277 memcpy(&sctx->buf[index], &data[i], len-i);
278} 278}
279 279
280static void sha256_final(void* ctx, u8 *out) 280static void sha256_final(struct crypto_tfm *tfm, u8 *out)
281{ 281{
282 struct sha256_ctx *sctx = ctx; 282 struct sha256_ctx *sctx = crypto_tfm_ctx(tfm);
283 __be32 *dst = (__be32 *)out; 283 __be32 *dst = (__be32 *)out;
284 __be32 bits[2]; 284 __be32 bits[2];
285 unsigned int index, pad_len; 285 unsigned int index, pad_len;
@@ -293,10 +293,10 @@ static void sha256_final(void* ctx, u8 *out)
293 /* Pad out to 56 mod 64. */ 293 /* Pad out to 56 mod 64. */
294 index = (sctx->count[0] >> 3) & 0x3f; 294 index = (sctx->count[0] >> 3) & 0x3f;
295 pad_len = (index < 56) ? (56 - index) : ((64+56) - index); 295 pad_len = (index < 56) ? (56 - index) : ((64+56) - index);
296 sha256_update(sctx, padding, pad_len); 296 sha256_update(tfm, padding, pad_len);
297 297
298 /* Append length (before padding) */ 298 /* Append length (before padding) */
299 sha256_update(sctx, (const u8 *)bits, sizeof(bits)); 299 sha256_update(tfm, (const u8 *)bits, sizeof(bits));
300 300
301 /* Store state in digest */ 301 /* Store state in digest */
302 for (i = 0; i < 8; i++) 302 for (i = 0; i < 8; i++)
@@ -313,6 +313,7 @@ static struct crypto_alg alg = {
313 .cra_blocksize = SHA256_HMAC_BLOCK_SIZE, 313 .cra_blocksize = SHA256_HMAC_BLOCK_SIZE,
314 .cra_ctxsize = sizeof(struct sha256_ctx), 314 .cra_ctxsize = sizeof(struct sha256_ctx),
315 .cra_module = THIS_MODULE, 315 .cra_module = THIS_MODULE,
316 .cra_alignmask = 3,
316 .cra_list = LIST_HEAD_INIT(alg.cra_list), 317 .cra_list = LIST_HEAD_INIT(alg.cra_list),
317 .cra_u = { .digest = { 318 .cra_u = { .digest = {
318 .dia_digestsize = SHA256_DIGEST_SIZE, 319 .dia_digestsize = SHA256_DIGEST_SIZE,