#include <mhash.h>
#include <stdio.h>

extern int debug;
                    
#define MD5_LENGTH 16

void md5(char *buf, int len, char *rhash)
{

  int i;
  MHASH td;    
  char *hash;  

  if (MD5_LENGTH != mhash_get_block_size(MHASH_MD5)) {
    printf("Error MD5 Length\n");
  }
  td = mhash_init(MHASH_MD5);

  mhash(td, buf, len);
  hash = (char *)mhash_end(td);
  memcpy(rhash,hash,MD5_LENGTH);
             
  if (debug) {
    printf(" ");
    for (i = 0; i < MD5_LENGTH; i++) {
      printf("%.2x", hash[i]);
    }
    printf(" ");
  }
}  


