/***************************************************************************
                          MD5.h  -  description
                             -------------------
    begin                : Fri Nov 21 2003
    copyright            : (C) 2003 by Wei Zheng
    email                : v_zheng@yahoo.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef MD5_H
#define MD5_H

#include <string.h>
#include <stdio.h>
#ifndef HEADER_MD5_H
/* Try to avoid clashes with OpenSSL */
#define HEADER_MD5_H
#endif

#if SIZEOF_INT == 4
typedef unsigned int uint32;
#else
typedef unsigned long int uint32;
#endif

struct MD5Context {
  uint32 buf[4];
  uint32 bits[2];
  unsigned char in[64];
};
typedef struct MD5Context MD5_CTX;

/* The four core functions - F1 is optimized somewhat */

/* #define F1(x, y, z) (x & y | ~x & z) */
#define F1(x, y, z) (z ^ (x & (y ^ z)))
#define F2(x, y, z) F1(z, x, y)
#define F3(x, y, z) (x ^ y ^ z)
#define F4(x, y, z) (y ^ (x | ~z))

/* This is the central step in the MD5 algorithm. */
#define MD5STEP(f, w, x, y, z, data, s) \
        ( w += f(x, y, z) + data,  w = w<<s | w>>(32-s),  w += x )


/**
  *@author Wei Zheng
  */

class MD5 {

public:
  char ascii_digest[33];
  char ascii_original[56];

public: 
	MD5();
	~MD5();
  /** No descriptions */
  void byteReverse(unsigned char *buf,unsigned longs);
  /** No descriptions */
  void MD5Init(struct MD5Context *context);
  /** No descriptions */
  void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len) ;
  /** No descriptions */
  void MD5Final(unsigned char digest[16], struct MD5Context *ctx);
  /** No descriptions */
  void MD5Transform(uint32 buf[4], uint32 const in[16]);
  /** No descriptions */
  void MD5Digest();
};

#endif
