Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:12:16

0001 // @(#)root/base:$Id$
0002 // Author: Fons Rademakers   29/9/2001
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TMD5
0013 #define ROOT_TMD5
0014 
0015 //////////////////////////////////////////////////////////////////////////
0016 //                                                                      //
0017 // TMD5                                                                 //
0018 //                                                                      //
0019 // This code implements the MD5 message-digest algorithm.               //
0020 // The algorithm is due to Ron Rivest. This code was                    //
0021 // written by Colin Plumb in 1993, no copyright is claimed.             //
0022 // This code is in the public domain; do with it what you wish.         //
0023 //                                                                      //
0024 // Equivalent code is available from RSA Data Security, Inc.            //
0025 // This code has been tested against that, and is equivalent,           //
0026 // except that you don't need to include two pages of legalese          //
0027 // with every copy.                                                     //
0028 //                                                                      //
0029 // To compute the message digest of a chunk of bytes, create an         //
0030 // TMD5 object, call Update() as needed on buffers full of bytes, and   //
0031 // then call Final(), which will, optionally, fill a supplied 16-byte   //
0032 // array with the digest.                                               //
0033 //                                                                      //
0034 //////////////////////////////////////////////////////////////////////////
0035 
0036 #include "Rtypes.h"
0037 
0038 // forward declaration
0039 class TBuffer;
0040 class TMD5;
0041 Bool_t operator==(const TMD5 &m1, const TMD5 &m2);
0042 
0043 
0044 class TMD5 {
0045 
0046 friend Bool_t operator==(const TMD5 &m1, const TMD5 &m2);
0047 
0048 private:
0049    UInt_t    fBuf[4];     //!temp buffer
0050    UInt_t    fBits[2];    //!temp buffer
0051    UChar_t   fIn[64];     //!temp buffer
0052    mutable Char_t fString[33]; //!string representation of digest
0053    UChar_t   fDigest[16]; //message digest
0054    Bool_t    fFinalized;  //true if message digest has been finalized
0055 
0056    void Transform(UInt_t buf[4], const UChar_t in[64]);
0057    void Encode(UChar_t *out, const UInt_t *in, UInt_t len);
0058    void Decode(UInt_t *out, const UChar_t *in, UInt_t len);
0059 
0060 public:
0061    TMD5();
0062    TMD5(const UChar_t *digest);
0063    TMD5(const TMD5 &md5);
0064    virtual ~TMD5() { }
0065 
0066    TMD5 &operator=(const TMD5 &rhs);
0067 
0068    void        Update(const UChar_t *buf, UInt_t len);
0069    void        Final();
0070    void        Final(UChar_t digest[16]);
0071    void        Print() const;
0072    const char *AsString() const;
0073 
0074    Int_t       SetDigest(const char *md5ascii);
0075 
0076    static TMD5  *ReadChecksum(const char *file);
0077    static Int_t  WriteChecksum(const char *file, const TMD5 *md5);
0078 
0079    static TMD5  *FileChecksum(const char *file);
0080    static Int_t  FileChecksum(const char *file, UChar_t digest[16]);
0081 
0082    ClassDef(TMD5,1)  // MD5 cryptographic hash functions with a 128 bit output
0083 };
0084 
0085 inline TBuffer &operator>>(TBuffer &buf, TMD5 &md5)
0086 { md5.Streamer(buf); return buf; }
0087 
0088 // Not inlined in order to avoid const casted away warning in user code.
0089 TBuffer &operator<<(TBuffer &buf, const TMD5 &md5);
0090 
0091 inline Bool_t operator!=(const TMD5 &m1, const TMD5 &m2)
0092 { return !(m1 == m2); }
0093 
0094 
0095 #endif