[PATCH 3/4] Use more odd chuck sizes for check_one_md

Jussi Kivilinna jussi.kivilinna at iki.fi
Fri May 1 15:08:07 CEST 2015


* tests/basic.c (check_one_md): Make chuck size vary oddly, instead
of using fixed length of 1000 bytes.
--

Signed-off-by: Jussi Kivilinna <jussi.kivilinna at iki.fi>
---
 tests/basic.c |   24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/tests/basic.c b/tests/basic.c
index f3105de..8400f9e 100644
--- a/tests/basic.c
+++ b/tests/basic.c
@@ -5231,11 +5231,29 @@ check_one_md (int algo, const char *data, int len, const char *expect)
   if (*data == '!' && !data[1])
     {				/* hash one million times a "a" */
       char aaa[1000];
+      size_t left = 1000 * 1000;
+      size_t startlen = 1;
+      size_t piecelen = startlen;
 
-      /* Write in odd size chunks so that we test the buffering.  */
       memset (aaa, 'a', 1000);
-      for (i = 0; i < 1000; i++)
-        gcry_md_write (hd, aaa, 1000);
+
+      /* Write in odd size chunks so that we test the buffering.  */
+      while (left > 0)
+        {
+          if (piecelen > sizeof(aaa))
+            piecelen = sizeof(aaa);
+          if (piecelen > left)
+            piecelen = left;
+
+          gcry_md_write (hd, aaa, piecelen);
+
+          left -= piecelen;
+
+          if (piecelen == sizeof(aaa))
+            piecelen = ++startlen;
+          else
+            piecelen = piecelen * 2 - ((piecelen != startlen) ? startlen : 0);
+        }
     }
   else
     gcry_md_write (hd, data, len);




More information about the Gcrypt-devel mailing list