TMD5.h

Go to the documentation of this file.
00001 // @(#)root/base:$Id: TMD5.h 33386 2010-05-05 13:41:15Z rdm $
00002 // Author: Fons Rademakers   29/9/2001
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TMD5
00013 #define ROOT_TMD5
00014 
00015 //////////////////////////////////////////////////////////////////////////
00016 //                                                                      //
00017 // TMD5                                                                 //
00018 //                                                                      //
00019 // This code implements the MD5 message-digest algorithm.               //
00020 // The algorithm is due to Ron Rivest. This code was                    //
00021 // written by Colin Plumb in 1993, no copyright is claimed.             //
00022 // This code is in the public domain; do with it what you wish.         //
00023 //                                                                      //
00024 // Equivalent code is available from RSA Data Security, Inc.            //
00025 // This code has been tested against that, and is equivalent,           //
00026 // except that you don't need to include two pages of legalese          //
00027 // with every copy.                                                     //
00028 //                                                                      //
00029 // To compute the message digest of a chunk of bytes, create an         //
00030 // TMD5 object, call Update() as needed on buffers full of bytes, and   //
00031 // then call Final(), which will, optionally, fill a supplied 16-byte   //
00032 // array with the digest.                                               //
00033 //                                                                      //
00034 //////////////////////////////////////////////////////////////////////////
00035 
00036 #ifndef ROOT_Rtypes
00037 #include "Rtypes.h"
00038 #endif
00039 
00040 // forward declaration
00041 class TBuffer;
00042 class TMD5;
00043 Bool_t operator==(const TMD5 &m1, const TMD5 &m2);
00044 
00045 
00046 class TMD5 {
00047 
00048 friend Bool_t operator==(const TMD5 &m1, const TMD5 &m2);
00049 
00050 private:
00051    UInt_t    fBuf[4];     //!temp buffer
00052    UInt_t    fBits[2];    //!temp buffer
00053    UChar_t   fIn[64];     //!temp buffer
00054    UChar_t   fDigest[16]; //message digest
00055    Bool_t    fFinalized;  //true if message digest has been finalized
00056 
00057    void Transform(UInt_t buf[4], const UChar_t in[64]);
00058    void Encode(UChar_t *out, const UInt_t *in, UInt_t len);
00059    void Decode(UInt_t *out, const UChar_t *in, UInt_t len);
00060 
00061 public:
00062    TMD5();
00063    TMD5(const UChar_t *digest);
00064    TMD5(const TMD5 &md5);
00065    virtual ~TMD5() { }
00066 
00067    TMD5 &operator=(const TMD5 &rhs);
00068 
00069    void        Update(const UChar_t *buf, UInt_t len);
00070    void        Final();
00071    void        Final(UChar_t digest[16]);
00072    void        Print() const;
00073    const char *AsString() const;
00074 
00075    Int_t       SetDigest(const char *md5ascii);
00076 
00077    static TMD5  *ReadChecksum(const char *file);
00078    static Int_t  WriteChecksum(const char *file, const TMD5 *md5);
00079 
00080    static TMD5  *FileChecksum(const char *file);
00081    static Int_t  FileChecksum(const char *file, UChar_t digest[16]);
00082 
00083    ClassDef(TMD5,1)  // MD5 cryptographic hash functions with a 128 bit output
00084 };
00085 
00086 inline TBuffer &operator>>(TBuffer &buf, TMD5 &md5)
00087 { md5.Streamer(buf); return buf; }
00088 
00089 // Not inlined in order to avoid const casted away warning in user code.
00090 TBuffer &operator<<(TBuffer &buf, const TMD5 &md5);
00091 
00092 inline Bool_t operator!=(const TMD5 &m1, const TMD5 &m2)
00093 { return !(m1 == m2); }
00094 
00095 
00096 #endif

Generated on Tue Jul 5 14:10:27 2011 for ROOT_528-00b_version by  doxygen 1.5.1