Test more.
authorSimon Josefsson <simon@josefsson.org>
Fri, 28 Oct 2005 12:17:40 +0000 (12:17 +0000)
committerSimon Josefsson <simon@josefsson.org>
Fri, 28 Oct 2005 12:17:40 +0000 (12:17 +0000)
ChangeLog
tests/test-gc-md4.c
tests/test-gc-md5.c
tests/test-gc-sha1.c

index 1999e76..345d053 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2005-10-28  Simon Josefsson  <jas@extundo.com>
 
+       * tests/test-gc-md4.c, tests/test-gc-md5.c, tests/test-gc-sha1.c:
+       Test more.
+
        * tests/test-gc-md2.c, tests/test-md2.c: New files.
 
        * modules/md2, modules/md2-tests: New files.
index 67621a6..b208897 100644 (file)
@@ -29,6 +29,7 @@ int
 main (int argc, char *argv[])
 {
   Gc_rc rc;
+  gc_hash_handle h;
 
   rc = gc_init ();
   if (rc != GC_OK)
@@ -45,6 +46,7 @@ main (int argc, char *argv[])
     const char *expect =
       "\xa4\x48\x01\x7a\xaf\x21\xd8\x52\x5f\xc1\x0a\xe8\x7a\xa6\x72\x9d";
     char out[16];
+    const char *p;
 
     /* MD4 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b */
 
@@ -85,6 +87,43 @@ main (int argc, char *argv[])
        printf ("\n");
        return 1;
       }
+
+    if (gc_hash_digest_length (GC_MD4) != 16)
+      {
+       printf ("gc_hash_digest_length (GC_MD4) failed\n");
+       return 1;
+      }
+
+    if ((rc = gc_hash_open (GC_MD4, 0, &h)) != GC_OK)
+      {
+       printf ("gc_hash_open(GC_MD4) failed (%d)\n", rc);
+       return 1;
+      }
+
+    gc_hash_write (h, inlen, in);
+
+    p = gc_hash_read (h);
+
+    if (!p)
+      {
+       printf ("gc_hash_read failed\n");
+       return 1;
+      }
+
+    if (memcmp (p, expect, 16) != 0)
+      {
+       size_t i;
+       printf ("md4 1 missmatch. expected:\n");
+       for (i = 0; i < 16; i++)
+         printf ("%02x ", expect[i] & 0xFF);
+       printf ("\ncomputed:\n");
+       for (i = 0; i < 16; i++)
+         printf ("%02x ", p[i] & 0xFF);
+       printf ("\n");
+       return 1;
+      }
+
+    gc_hash_close (h);
   }
 
   gc_done ();
index 5483517..61cc573 100644 (file)
@@ -29,6 +29,7 @@ int
 main (int argc, char *argv[])
 {
   Gc_rc rc;
+  gc_hash_handle h;
 
   rc = gc_init ();
   if (rc != GC_OK)
@@ -45,6 +46,7 @@ main (int argc, char *argv[])
     char *expect =
       "\xc3\xfc\xd3\xd7\x61\x92\xe4\x00\x7d\xfb\x49\x6c\xca\x67\xe1\x3b";
     char out[16];
+    const char *p;
 
     /* MD5 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b */
 
@@ -76,7 +78,7 @@ main (int argc, char *argv[])
     if (memcmp (out, expect, 16) != 0)
       {
        size_t i;
-       printf ("md5 1 missmatch. expected:\n");
+       printf ("md5 2 missmatch. expected:\n");
        for (i = 0; i < 16; i++)
          printf ("%02x ", expect[i] & 0xFF);
        printf ("\ncomputed:\n");
@@ -85,6 +87,43 @@ main (int argc, char *argv[])
        printf ("\n");
        return 1;
       }
+
+    if (gc_hash_digest_length (GC_MD5) != 16)
+      {
+       printf ("gc_hash_digest_length (GC_MD5) failed\n");
+       return 1;
+      }
+
+    if ((rc = gc_hash_open (GC_MD5, 0, &h)) != GC_OK)
+      {
+       printf ("gc_hash_open(GC_MD5) failed (%d)\n", rc);
+       return 1;
+      }
+
+    gc_hash_write (h, inlen, in);
+
+    p = gc_hash_read (h);
+
+    if (!p)
+      {
+       printf ("gc_hash_read failed\n");
+       return 1;
+      }
+
+    if (memcmp (p, expect, 16) != 0)
+       {
+       size_t i;
+       printf ("md5 3 missmatch. expected:\n");
+       for (i = 0; i < 16; i++)
+         printf ("%02x ", expect[i] & 0xFF);
+       printf ("\ncomputed:\n");
+       for (i = 0; i < 16; i++)
+         printf ("%02x ", p[i] & 0xFF);
+       printf ("\n");
+       return 1;
+      }
+
+    gc_hash_close (h);
   }
 
   gc_done ();
index b8ee901..6f05744 100644 (file)
@@ -29,6 +29,7 @@ int
 main (int argc, char *argv[])
 {
   Gc_rc rc;
+  gc_hash_handle h;
 
   rc = gc_init ();
   if (rc != GC_OK)
@@ -43,6 +44,7 @@ main (int argc, char *argv[])
     char *expect = "\x42\x5a\xf1\x2a\x07\x43\x50\x2b"
       "\x32\x2e\x93\xa0\x15\xbc\xf8\x68\xe3\x24\xd5\x6a";
     char out[20];
+    const char *p;
 
     if (gc_sha1 (in, inlen, out) != 0)
       {
@@ -82,6 +84,43 @@ main (int argc, char *argv[])
        printf ("\n");
        return 1;
       }
+
+    if (gc_hash_digest_length (GC_SHA1) != 20)
+      {
+       printf ("gc_hash_digest_length (GC_SHA1) failed\n");
+       return 1;
+      }
+
+    if ((rc = gc_hash_open (GC_SHA1, 0, &h)) != GC_OK)
+      {
+       printf ("gc_hash_open(GC_SHA1) failed (%d)\n", rc);
+       return 1;
+      }
+
+    gc_hash_write (h, inlen, in);
+
+    p = gc_hash_read (h);
+
+    if (!p)
+      {
+       printf ("gc_hash_read failed\n");
+       return 1;
+      }
+
+    if (memcmp (p, expect, 20) != 0)
+      {
+       size_t i;
+       printf ("sha1 1 missmatch. expected:\n");
+       for (i = 0; i < 20; i++)
+         printf ("%02x ", expect[i] & 0xFF);
+       printf ("\ncomputed:\n");
+       for (i = 0; i < 20; i++)
+         printf ("%02x ", p[i] & 0xFF);
+       printf ("\n");
+       return 1;
+      }
+
+    gc_hash_close (h);
   }
 
   gc_done ();