[CRYPTO] digest: Remove unnecessary zeroing during init
authorHerbert Xu <herbert@gondor.apana.org.au>
Tue, 16 May 2006 12:06:54 +0000 (22:06 +1000)
committerHerbert Xu <herbert@gondor.apana.org.au>
Mon, 26 Jun 2006 07:34:38 +0000 (17:34 +1000)
Various digest algorithms operate one block at a time and therefore
keep a temporary buffer of partial blocks.  This buffer does not need
to be initialised since there is a counter which indicates what is and
isn't valid in it.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
arch/s390/crypto/sha1_s390.c
arch/s390/crypto/sha256_s390.c
crypto/sha256.c
crypto/sha512.c
crypto/tgr192.c

index 98c896b86dcd2a7c66e1025c56bd1c12eb02e266..36bb5346a8c46369d50ae16111f5f911511d148c 100644 (file)
@@ -40,19 +40,20 @@ struct crypt_s390_sha1_ctx {
        u8 buffer[2 * SHA1_BLOCK_SIZE];
 };
 
-static void
-sha1_init(void *ctx)
+static void sha1_init(void *ctx_arg) 
 {
-       static const struct crypt_s390_sha1_ctx initstate = {
-               .state = {
-                       0x67452301,
-                       0xEFCDAB89,
-                       0x98BADCFE,
-                       0x10325476,
-                       0xC3D2E1F0
-               },
+       struct crypt_s390_sha1_ctx *ctx = ctx_arg;
+       static const u32 initstate[5] = {
+               0x67452301,
+               0xEFCDAB89,
+               0x98BADCFE,
+               0x10325476,
+               0xC3D2E1F0
        };
-       memcpy(ctx, &initstate, sizeof(initstate));
+
+       ctx->count = 0;
+       memcpy(ctx->state, &initstate, sizeof(initstate));
+       ctx->buf_len = 0;
 }
 
 static void
index 1ec5e92b34544a360126717d233394c524c2643f..2c76e7bee41ca95191df3a9bbefb5414c0eed06e 100644 (file)
@@ -44,7 +44,6 @@ static void sha256_init(void *ctx)
        sctx->state[6] = 0x1f83d9ab;
        sctx->state[7] = 0x5be0cd19;
        sctx->count = 0;
-       memset(sctx->buf, 0, sizeof(sctx->buf));
 }
 
 static void sha256_update(void *ctx, const u8 *data, unsigned int len)
index d62264a8a33e637d6d057b0a20ffd71da59b4813..4533a0564895797b623a80ecd8afb3788f02591c 100644 (file)
@@ -242,7 +242,6 @@ static void sha256_init(void *ctx)
        sctx->state[6] = H6;
        sctx->state[7] = H7;
        sctx->count[0] = sctx->count[1] = 0;
-       memset(sctx->buf, 0, sizeof(sctx->buf));
 }
 
 static void sha256_update(void *ctx, const u8 *data, unsigned int len)
index 7dbec4f6b9471e9a59442c26a87ec0ef124872cd..bc77a66d9de251d4fdd1393ec057960b9a8c49f2 100644 (file)
@@ -173,7 +173,6 @@ sha512_init(void *ctx)
        sctx->state[6] = H6;
        sctx->state[7] = H7;
        sctx->count[0] = sctx->count[1] = sctx->count[2] = sctx->count[3] = 0;
-       memset(sctx->buf, 0, sizeof(sctx->buf));
 }
 
 static void
@@ -189,7 +188,6 @@ sha384_init(void *ctx)
         sctx->state[6] = HP6;
         sctx->state[7] = HP7;
         sctx->count[0] = sctx->count[1] = sctx->count[2] = sctx->count[3] = 0;
-        memset(sctx->buf, 0, sizeof(sctx->buf));
 }
 
 static void
index 1eae1bb7e495d99250e14a7576319cedf1f052c6..004bb841cc5bdd7a51c81688ac87c185fb33c7e3 100644 (file)
@@ -500,7 +500,6 @@ static void tgr192_init(void *ctx)
 {
        struct tgr192_ctx *tctx = ctx;
 
-       memset (tctx->hash, 0, 64);
        tctx->a = 0x0123456789abcdefULL;
        tctx->b = 0xfedcba9876543210ULL;
        tctx->c = 0xf096a5b4c3b2e187ULL;