Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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