]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Add MD2 support, tiny patch from Martin Kostner.
authorSimon Josefsson <simon@josefsson.org>
Sun, 26 Dec 2004 16:17:06 +0000 (16:17 +0000)
committerSimon Josefsson <simon@josefsson.org>
Sun, 26 Dec 2004 16:17:06 +0000 (16:17 +0000)
crypto/gc-libgcrypt.c
crypto/gc.h

index 7376220e69ae4debcdb0761990cecb57acd81e5b..94e2a69cdffcda81e5454784a40f66456f4ebeee 100644 (file)
@@ -231,6 +231,10 @@ gc_hash_open (int hash, int mode, gc_hash * outhandle)
       gcryalg = GCRY_MD_RMD160;
       break;
 
+    case GC_MD2:
+      gcryalg = GCRY_MD_MD2;
+      break;
+
     default:
       return GC_INVALID_HASH;
     }
@@ -287,6 +291,10 @@ gc_hash_digest_length (int hash)
       gcryalg = GCRY_MD_RMD160;
       break;
 
+    case GC_MD2:
+      gcryalg = GCRY_MD_MD2;
+      break;
+
     default:
       return 0;
     }
@@ -342,6 +350,10 @@ gc_hash_buffer (int hash, const char *in, size_t inlen, char *out)
       gcryalg = GCRY_MD_RMD160;
       break;
 
+    case GC_MD2:
+      gcryalg = GCRY_MD_MD2;
+      break;
+
     default:
       return GC_INVALID_HASH;
     }
@@ -378,6 +390,33 @@ gc_md5 (const char *in, size_t inlen, char out[GC_MD5_LEN])
   return GC_OK;
 }
 
+int
+gc_md2 (const char *in, size_t inlen, char out[GC_MD2_LEN])
+{
+  size_t outlen = gcry_md_get_algo_dlen (GCRY_MD_MD2);
+  gcry_md_hd_t hd;
+  gpg_error_t err;
+  unsigned char *p;
+
+  assert (outlen == GC_MD2_LEN);
+
+  err = gcry_md_open (&hd, GCRY_MD_MD2, 0);
+  if (err != GPG_ERR_NO_ERROR)
+    return GC_INVALID_HASH;
+
+  gcry_md_write (hd, in, inlen);
+
+  p = gcry_md_read (hd, GCRY_MD_MD2);
+  if (p == NULL)
+    return GC_INVALID_HASH;
+
+  memcpy (out, p, outlen);
+
+  gcry_md_close (hd);
+
+  return GC_OK;
+}
+
 int
 gc_hmac_md5 (const char *key, size_t keylen,
             const char *in, size_t inlen, char outhash[GC_MD5_LEN])
index c3a68ed9cf321f5e2c8b4bccd3fa8eef3c32231a..b734e514afa7b5c12e231f38fd94d619cae4d1eb 100644 (file)
@@ -68,7 +68,8 @@ enum Gc_hash
   {
     GC_MD5,
     GC_SHA1,
-    GC_RMD160
+    GC_RMD160,
+    GC_MD2
   };
 typedef enum Gc_hash Gc_hash;
 
@@ -82,6 +83,7 @@ typedef void *gc_hash;
 
 #define GC_MD5_LEN 16
 #define GC_SHA1_LEN 20
+#define GC_MD2_LEN 16
 
 /* Public-key types. */
 enum Gc_pk