Example #1
0
Gc_rc
gc_hash_buffer (Gc_hash hash, const void *in, size_t inlen, char *resbuf)
{
  switch (hash)
    {
#ifdef GNULIB_GC_MD2
    case GC_MD2:
      md2_buffer (in, inlen, resbuf);
      break;
#endif

#ifdef GNULIB_GC_MD4
    case GC_MD4:
      md4_buffer (in, inlen, resbuf);
      break;
#endif

#ifdef GNULIB_GC_MD5
    case GC_MD5:
      md5_buffer (in, inlen, resbuf);
      break;
#endif

#ifdef GNULIB_GC_SHA1
    case GC_SHA1:
      sha1_buffer (in, inlen, resbuf);
      break;
#endif

    default:
      return GC_INVALID_HASH;
    }

  return GC_OK;
}
Example #2
0
int
main (int argc, char *argv[])
{
  const char *in1 = "abc";
  const char *out1 =
    "\xda\x85\x3b\x0d\x3f\x88\xd9\x9b\x30\x28\x3a\x69\xe6\xde\xd6\xbb";
  const char *in2 = "abcdefghijklmnopqrstuvwxyz";
  const char *out2 =
    "\x4e\x8d\xdf\xf3\x65\x02\x92\xab\x5a\x41\x08\xc3\xaa\x47\x94\x0b";
  char buf[MD2_DIGEST_SIZE];

  if (memcmp (md2_buffer (in1, strlen (in1), buf), out1, MD2_DIGEST_SIZE) !=
      0)
    {
      size_t i;
      printf ("expected:\n");
      for (i = 0; i < MD2_DIGEST_SIZE; i++)
        printf ("%02x ", out1[i] & 0xFF);
      printf ("\ncomputed:\n");
      for (i = 0; i < MD2_DIGEST_SIZE; i++)
        printf ("%02x ", buf[i] & 0xFF);
      printf ("\n");
      return 1;
    }

  if (memcmp (md2_buffer (in2, strlen (in2), buf), out2, MD2_DIGEST_SIZE) !=
      0)
    {
      size_t i;
      printf ("expected:\n");
      for (i = 0; i < MD2_DIGEST_SIZE; i++)
        printf ("%02x ", out2[i] & 0xFF);
      printf ("\ncomputed:\n");
      for (i = 0; i < MD2_DIGEST_SIZE; i++)
        printf ("%02x ", buf[i] & 0xFF);
      printf ("\n");
      return 1;
    }

  return 0;
}
Example #3
0
Gc_rc
gc_md2 (const void *in, size_t inlen, void *resbuf)
{
  md2_buffer (in, inlen, resbuf);
  return GC_OK;
}
Example #4
0
Gc_rc
gc_hash_buffer (Gc_hash hash, const void *in, size_t inlen, char *resbuf)
{
    int gcryalg;

    switch (hash)
    {
#ifdef GNULIB_GC_MD2
    case GC_MD2:
        md2_buffer (in, inlen, resbuf);
        return GC_OK;
        break;
#endif

#ifdef GNULIB_GC_MD4
    case GC_MD4:
        gcryalg = GCRY_MD_MD4;
        break;
#endif

#ifdef GNULIB_GC_MD5
    case GC_MD5:
        gcryalg = GCRY_MD_MD5;
        break;
#endif

#ifdef GNULIB_GC_SHA1
    case GC_SHA1:
        gcryalg = GCRY_MD_SHA1;
        break;
#endif

#ifdef GNULIB_GC_SHA256
    case GC_SHA256:
        gcryalg = GCRY_MD_SHA256;
        break;
#endif

#ifdef GNULIB_GC_SHA384
    case GC_SHA384:
        gcryalg = GCRY_MD_SHA384;
        break;
#endif

#ifdef GNULIB_GC_SHA512
    case GC_SHA512:
        gcryalg = GCRY_MD_SHA512;
        break;
#endif

#ifdef GNULIB_GC_SHA224
    case GC_SHA224:
        gcryalg = GCRY_MD_SHA224;
        break;
#endif

#ifdef GNULIB_GC_RMD160
    case GC_RMD160:
        gcryalg = GCRY_MD_RMD160;
        break;
#endif

    default:
        return GC_INVALID_HASH;
    }

    gcry_md_hash_buffer (gcryalg, resbuf, in, inlen);

    return GC_OK;
}