Logo ROOT   6.12/07
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 #include "Rtypes.h"
37 
38 // forward declaration
39 class TBuffer;
40 class TMD5;
41 Bool_t operator==(const TMD5 &m1, const TMD5 &m2);
42 
43 
44 class TMD5 {
45 
46 friend Bool_t operator==(const TMD5 &m1, const TMD5 &m2);
47 
48 private:
49  UInt_t fBuf[4]; //!temp buffer
50  UInt_t fBits[2]; //!temp buffer
51  UChar_t fIn[64]; //!temp buffer
52  mutable Char_t fString[33]; //!string representation of digest
53  UChar_t fDigest[16]; //message digest
54  Bool_t fFinalized; //true if message digest has been finalized
55 
56  void Transform(UInt_t buf[4], const UChar_t in[64]);
57  void Encode(UChar_t *out, const UInt_t *in, UInt_t len);
58  void Decode(UInt_t *out, const UChar_t *in, UInt_t len);
59 
60 public:
61  TMD5();
62  TMD5(const UChar_t *digest);
63  TMD5(const TMD5 &md5);
64  virtual ~TMD5() { }
65 
66  TMD5 &operator=(const TMD5 &rhs);
67 
68  void Update(const UChar_t *buf, UInt_t len);
69  void Final();
70  void Final(UChar_t digest[16]);
71  void Print() const;
72  const char *AsString() const;
73 
74  Int_t SetDigest(const char *md5ascii);
75 
76  static TMD5 *ReadChecksum(const char *file);
77  static Int_t WriteChecksum(const char *file, const TMD5 *md5);
78 
79  static TMD5 *FileChecksum(const char *file);
80  static Int_t FileChecksum(const char *file, UChar_t digest[16]);
81 
82  ClassDef(TMD5,1) // MD5 cryptographic hash functions with a 128 bit output
83 };
84 
85 inline TBuffer &operator>>(TBuffer &buf, TMD5 &md5)
86 { md5.Streamer(buf); return buf; }
87 
88 // Not inlined in order to avoid const casted away warning in user code.
89 TBuffer &operator<<(TBuffer &buf, const TMD5 &md5);
90 
91 inline Bool_t operator!=(const TMD5 &m1, const TMD5 &m2)
92 { return !(m1 == m2); }
93 
94 
95 #endif
void Print() const
Print digest in ascii hex form.
Definition: TMD5.cxx:206
friend Bool_t operator==(const TMD5 &m1, const TMD5 &m2)
Compare two message digests for equality.
Definition: TMD5.cxx:372
static TMD5 * FileChecksum(const char *file)
Returns checksum of specified file.
Definition: TMD5.cxx:474
void Final()
MD5 finalization, ends an MD5 message-digest operation, writing the the message digest and zeroizing ...
Definition: TMD5.cxx:167
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:240
Bool_t operator!=(const TMD5 &m1, const TMD5 &m2)
Definition: TMD5.h:91
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
TMD5 & operator=(const TMD5 &rhs)
MD5 assignment operator.
Definition: TMD5.cxx:90
const char * AsString() const
Return message digest as string.
Definition: TMD5.cxx:220
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Bool_t fFinalized
Definition: TMD5.h:54
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:255
#define ClassDef(name, id)
Definition: Rtypes.h:320
This code implements the MD5 message-digest algorithm.
Definition: TMD5.h:44
TMD5()
Create TMD5 object.
Definition: TMD5.cxx:48
UInt_t fBuf[4]
Definition: TMD5.h:49
Char_t fString[33]
temp buffer
Definition: TMD5.h:52
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:108
static Int_t WriteChecksum(const char *file, const TMD5 *md5)
Writes checksum in ASCII format to specified file.
Definition: TMD5.cxx:452
UChar_t fIn[64]
temp buffer
Definition: TMD5.h:51
unsigned int UInt_t
Definition: RtypesCore.h:42
static constexpr double m2
TBuffer & operator>>(TBuffer &buf, TMD5 &md5)
Definition: TMD5.h:85
char Char_t
Definition: RtypesCore.h:29
Int_t SetDigest(const char *md5ascii)
Set the digest from the ASCII representation &#39;md5ascii&#39;.
Definition: TMD5.cxx:395
Definition: file.py:1
Bool_t operator==(const TMD5 &m1, const TMD5 &m2)
Compare two message digests for equality.
Definition: TMD5.cxx:372
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:422
UChar_t fDigest[16]
string representation of digest
Definition: TMD5.h:53
UInt_t fBits[2]
temp buffer
Definition: TMD5.h:50
virtual ~TMD5()
Definition: TMD5.h:64
TBuffer & operator<<(TBuffer &buf, const TMD5 &md5)
Input operator. Delegate to Streamer.
Definition: TMD5.cxx:554
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:281