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.
main (int argc, char *argv[])
{
Gc_rc rc;
+ gc_hash_handle h;
rc = gc_init ();
if (rc != GC_OK)
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 */
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 ();
main (int argc, char *argv[])
{
Gc_rc rc;
+ gc_hash_handle h;
rc = gc_init ();
if (rc != GC_OK)
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 */
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");
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 ();
main (int argc, char *argv[])
{
Gc_rc rc;
+ gc_hash_handle h;
rc = gc_init ();
if (rc != GC_OK)
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)
{
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 ();