// @(#)root/base:$Id$
// Author: Fons Rademakers   29/9/2001

/*************************************************************************
 * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TMD5
#define ROOT_TMD5

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TMD5                                                                 //
//                                                                      //
// This code implements the MD5 message-digest algorithm.               //
// The algorithm is due to Ron Rivest. This code was                    //
// written by Colin Plumb in 1993, no copyright is claimed.             //
// This code is in the public domain; do with it what you wish.         //
//                                                                      //
// Equivalent code is available from RSA Data Security, Inc.            //
// This code has been tested against that, and is equivalent,           //
// except that you don't need to include two pages of legalese          //
// with every copy.                                                     //
//                                                                      //
// To compute the message digest of a chunk of bytes, create an         //
// TMD5 object, call Update() as needed on buffers full of bytes, and   //
// then call Final(), which will, optionally, fill a supplied 16-byte   //
// array with the digest.                                               //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_Rtypes
#include "Rtypes.h"
#endif

// forward declaration
class TBuffer;
class TMD5;
Bool_t operator==(const TMD5 &m1, const TMD5 &m2);


class TMD5 {

friend Bool_t operator==(const TMD5 &m1, const TMD5 &m2);

private:
   UInt_t    fBuf[4];     //!temp buffer
   UInt_t    fBits[2];    //!temp buffer
   UChar_t   fIn[64];     //!temp buffer
   mutable Char_t fString[33]; //!string representation of digest
   UChar_t   fDigest[16]; //message digest
   Bool_t    fFinalized;  //true if message digest has been finalized

   void Transform(UInt_t buf[4], const UChar_t in[64]);
   void Encode(UChar_t *out, const UInt_t *in, UInt_t len);
   void Decode(UInt_t *out, const UChar_t *in, UInt_t len);

public:
   TMD5();
   TMD5(const UChar_t *digest);
   TMD5(const TMD5 &md5);
   virtual ~TMD5() { }

   TMD5 &operator=(const TMD5 &rhs);

   void        Update(const UChar_t *buf, UInt_t len);
   void        Final();
   void        Final(UChar_t digest[16]);
   void        Print() const;
   const char *AsString() const;

   Int_t       SetDigest(const char *md5ascii);

   static TMD5  *ReadChecksum(const char *file);
   static Int_t  WriteChecksum(const char *file, const TMD5 *md5);

   static TMD5  *FileChecksum(const char *file);
   static Int_t  FileChecksum(const char *file, UChar_t digest[16]);

   ClassDef(TMD5,1)  // MD5 cryptographic hash functions with a 128 bit output
};

inline TBuffer &operator>>(TBuffer &buf, TMD5 &md5)
{ md5.Streamer(buf); return buf; }

// Not inlined in order to avoid const casted away warning in user code.
TBuffer &operator<<(TBuffer &buf, const TMD5 &md5);

inline Bool_t operator!=(const TMD5 &m1, const TMD5 &m2)
{ return !(m1 == m2); }


#endif
 TMD5.h:1
 TMD5.h:2
 TMD5.h:3
 TMD5.h:4
 TMD5.h:5
 TMD5.h:6
 TMD5.h:7
 TMD5.h:8
 TMD5.h:9
 TMD5.h:10
 TMD5.h:11
 TMD5.h:12
 TMD5.h:13
 TMD5.h:14
 TMD5.h:15
 TMD5.h:16
 TMD5.h:17
 TMD5.h:18
 TMD5.h:19
 TMD5.h:20
 TMD5.h:21
 TMD5.h:22
 TMD5.h:23
 TMD5.h:24
 TMD5.h:25
 TMD5.h:26
 TMD5.h:27
 TMD5.h:28
 TMD5.h:29
 TMD5.h:30
 TMD5.h:31
 TMD5.h:32
 TMD5.h:33
 TMD5.h:34
 TMD5.h:35
 TMD5.h:36
 TMD5.h:37
 TMD5.h:38
 TMD5.h:39
 TMD5.h:40
 TMD5.h:41
 TMD5.h:42
 TMD5.h:43
 TMD5.h:44
 TMD5.h:45
 TMD5.h:46
 TMD5.h:47
 TMD5.h:48
 TMD5.h:49
 TMD5.h:50
 TMD5.h:51
 TMD5.h:52
 TMD5.h:53
 TMD5.h:54
 TMD5.h:55
 TMD5.h:56
 TMD5.h:57
 TMD5.h:58
 TMD5.h:59
 TMD5.h:60
 TMD5.h:61
 TMD5.h:62
 TMD5.h:63
 TMD5.h:64
 TMD5.h:65
 TMD5.h:66
 TMD5.h:67
 TMD5.h:68
 TMD5.h:69
 TMD5.h:70
 TMD5.h:71
 TMD5.h:72
 TMD5.h:73
 TMD5.h:74
 TMD5.h:75
 TMD5.h:76
 TMD5.h:77
 TMD5.h:78
 TMD5.h:79
 TMD5.h:80
 TMD5.h:81
 TMD5.h:82
 TMD5.h:83
 TMD5.h:84
 TMD5.h:85
 TMD5.h:86
 TMD5.h:87
 TMD5.h:88
 TMD5.h:89
 TMD5.h:90
 TMD5.h:91
 TMD5.h:92
 TMD5.h:93
 TMD5.h:94
 TMD5.h:95
 TMD5.h:96
 TMD5.h:97