sha256_block advances the input pointer double as fast sometimes. Fix the
authorAndy Polyakov <appro@openssl.org>
Mon, 27 Sep 2004 09:35:59 +0000 (09:35 +0000)
committerAndy Polyakov <appro@openssl.org>
Mon, 27 Sep 2004 09:35:59 +0000 (09:35 +0000)
bug and test that it's actually gone.
PR: 950

crypto/sha/sha256.c
crypto/sha/sha256t.c

index 618ba3bc101f601926d374963f0b0e1beb9615a1..5f3845f55ca7f67176e1c6b3e507e6d4c7d3b330 100644 (file)
@@ -179,6 +179,8 @@ static void sha256_block (SHA256_CTX *ctx, const void *in, size_t num, int host)
                        h = g;  g = f;  f = e;  e = d + T1;
                        d = c;  c = b;  b = a;  a = T1 + T2;
                        }
+
+               data += SHA256_CBLOCK;
                }
        else
                {
@@ -209,7 +211,6 @@ static void sha256_block (SHA256_CTX *ctx, const void *in, size_t num, int host)
        ctx->h[0] += a; ctx->h[1] += b; ctx->h[2] += c; ctx->h[3] += d;
        ctx->h[4] += e; ctx->h[5] += f; ctx->h[6] += g; ctx->h[7] += h;
 
-                       data += SHA256_CBLOCK;
                        }
 }
 
@@ -258,6 +259,8 @@ static void sha256_block (SHA256_CTX *ctx, const void *in, size_t num, int host)
                T1 = X[13] = W[13];     ROUND_00_15(13,d,e,f,g,h,a,b,c);
                T1 = X[14] = W[14];     ROUND_00_15(14,c,d,e,f,g,h,a,b);
                T1 = X[15] = W[15];     ROUND_00_15(15,b,c,d,e,f,g,h,a);
+
+               data += SHA256_CBLOCK;
                }
        else
                {
@@ -296,7 +299,6 @@ static void sha256_block (SHA256_CTX *ctx, const void *in, size_t num, int host)
        ctx->h[0] += a; ctx->h[1] += b; ctx->h[2] += c; ctx->h[3] += d;
        ctx->h[4] += e; ctx->h[5] += f; ctx->h[6] += g; ctx->h[7] += h;
 
-                       data += SHA256_CBLOCK;
                        }
        }
 
index 20580faf5add3699845bd916562f78dcc92ce794..5c26ec86ef71ce9f6a11b10ce2736371716b35e3 100644 (file)
@@ -74,10 +74,13 @@ int main ()
 
     EVP_MD_CTX_init (&evp);
     EVP_DigestInit_ex (&evp,EVP_sha256(),NULL);
-    for (i=0;i<1000000;i+=64)
+    for (i=0;i<1000000;i+=160)
        EVP_DigestUpdate (&evp, "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
+                               "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
+                               "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
+                               "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
                                "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa",
-                               (1000000-i)<64?1000000-i:64);
+                               (1000000-i)<160?1000000-i:160);
     EVP_DigestFinal_ex (&evp,md,NULL);
     EVP_MD_CTX_cleanup (&evp);