ROOT  6.06/09
Reference Guide
TMD5.h
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Fons Rademakers 29/9/2001
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TMD5
13 #define ROOT_TMD5
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TMD5 //
18 // //
19 // This code implements the MD5 message-digest algorithm. //
20 // The algorithm is due to Ron Rivest. This code was //
21 // written by Colin Plumb in 1993, no copyright is claimed. //
22 // This code is in the public domain; do with it what you wish. //
23 // //
24 // Equivalent code is available from RSA Data Security, Inc. //
25 // This code has been tested against that, and is equivalent, //
26 // except that you don't need to include two pages of legalese //
27 // with every copy. //
28 // //
29 // To compute the message digest of a chunk of bytes, create an //
30 // TMD5 object, call Update() as needed on buffers full of bytes, and //
31 // then call Final(), which will, optionally, fill a supplied 16-byte //
32 // array with the digest. //
33 // //
34 //////////////////////////////////////////////////////////////////////////
35 
36 #ifndef ROOT_Rtypes
37 #include "Rtypes.h"
38 #endif
39 
40 // forward declaration
41 class TBuffer;
42 class TMD5;
43 Bool_t operator==(const TMD5 &m1, const TMD5 &m2);
44 
45 
46 class TMD5 {
47 
48 friend Bool_t operator==(const TMD5 &m1, const TMD5 &m2);
49 
50 private:
51  UInt_t fBuf[4]; //!temp buffer
52  UInt_t fBits[2]; //!temp buffer
53  UChar_t fIn[64]; //!temp buffer
54  mutable Char_t fString[33]; //!string representation of digest
55  UChar_t fDigest[16]; //message digest
56  Bool_t fFinalized; //true if message digest has been finalized
57 
58  void Transform(UInt_t buf[4], const UChar_t in[64]);
59  void Encode(UChar_t *out, const UInt_t *in, UInt_t len);
60  void Decode(UInt_t *out, const UChar_t *in, UInt_t len);
61 
62 public:
63  TMD5();
64  TMD5(const UChar_t *digest);
65  TMD5(const TMD5 &md5);
66  virtual ~TMD5() { }
67 
68  TMD5 &operator=(const TMD5 &rhs);
69 
70  void Update(const UChar_t *buf, UInt_t len);
71  void Final();
72  void Final(UChar_t digest[16]);
73  void Print() const;
74  const char *AsString() const;
75 
76  Int_t SetDigest(const char *md5ascii);
77 
78  static TMD5 *ReadChecksum(const char *file);
79  static Int_t WriteChecksum(const char *file, const TMD5 *md5);
80 
81  static TMD5 *FileChecksum(const char *file);
82  static Int_t FileChecksum(const char *file, UChar_t digest[16]);
83 
84  ClassDef(TMD5,1) // MD5 cryptographic hash functions with a 128 bit output
85 };
86 
87 inline TBuffer &operator>>(TBuffer &buf, TMD5 &md5)
88 { md5.Streamer(buf); return buf; }
89 
90 // Not inlined in order to avoid const casted away warning in user code.
91 TBuffer &operator<<(TBuffer &buf, const TMD5 &md5);
92 
93 inline Bool_t operator!=(const TMD5 &m1, const TMD5 &m2)
94 { return !(m1 == m2); }
95 
96 
97 #endif
void Print() const
Print digest in ascii hex form.
Definition: TMD5.cxx:204
friend Bool_t operator==(const TMD5 &m1, const TMD5 &m2)
Compare two message digests for equality.
Definition: TMD5.cxx:370
static TMD5 * FileChecksum(const char *file)
Returns checksum of specified file.
Definition: TMD5.cxx:472
void Final()
MD5 finalization, ends an MD5 message-digest operation, writing the the message digest and zeroizing ...
Definition: TMD5.cxx:165
void Encode(UChar_t *out, const UInt_t *in, UInt_t len)
Encodes input into output. Assumes len is a multiple of 4.
Definition: TMD5.cxx:238
Bool_t operator!=(const TMD5 &m1, const TMD5 &m2)
Definition: TMD5.h:93
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
TMD5 & operator=(const TMD5 &rhs)
MD5 assignment operator.
Definition: TMD5.cxx:88
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Bool_t fFinalized
Definition: TMD5.h:56
void Decode(UInt_t *out, const UChar_t *in, UInt_t len)
Decodes input into output. Assumes len is a multiple of 4.
Definition: TMD5.cxx:253
#define ClassDef(name, id)
Definition: Rtypes.h:254
const char * AsString() const
Return message digest as string.
Definition: TMD5.cxx:218
This code implements the MD5 message-digest algorithm.
Definition: TMD5.h:46
UInt_t fBuf[4]
Definition: TMD5.h:51
char * out
Definition: TBase64.cxx:29
Char_t fString[33]
temp buffer
Definition: TMD5.h:54
void Update(const UChar_t *buf, UInt_t len)
Update TMD5 object to reflect the concatenation of another buffer full of bytes.
Definition: TMD5.cxx:106
static Int_t WriteChecksum(const char *file, const TMD5 *md5)
Writes checksum in ASCII format to specified file.
Definition: TMD5.cxx:450
UChar_t fIn[64]
temp buffer
Definition: TMD5.h:53
unsigned int UInt_t
Definition: RtypesCore.h:42
TBuffer & operator>>(TBuffer &buf, TMD5 &md5)
Definition: TMD5.h:87
char Char_t
Definition: RtypesCore.h:29
Int_t SetDigest(const char *md5ascii)
Set the digest from the ASCII representation 'md5ascii'.
Definition: TMD5.cxx:393
Bool_t operator==(const TMD5 &m1, const TMD5 &m2)
Compare two message digests for equality.
Definition: TMD5.cxx:370
unsigned char UChar_t
Definition: RtypesCore.h:34
static TMD5 * ReadChecksum(const char *file)
Returns checksum stored in ASCII in specified file.
Definition: TMD5.cxx:420
UChar_t fDigest[16]
string representation of digest
Definition: TMD5.h:55
UInt_t fBits[2]
temp buffer
Definition: TMD5.h:52
virtual ~TMD5()
Definition: TMD5.h:66
TBuffer & operator<<(TBuffer &buf, const TMD5 &md5)
Input operator. Delegate to Streamer.
Definition: TMD5.cxx:552
void Transform(UInt_t buf[4], const UChar_t in[64])
The core of the MD5 algorithm, this alters an existing MD5 hash to reflect the addition of 16 longwor...
Definition: TMD5.cxx:279