Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
39class TBuffer;
40class TMD5;
41Bool_t operator==(const TMD5 &m1, const TMD5 &m2);
42
43
44class TMD5 {
45
46friend Bool_t operator==(const TMD5 &m1, const TMD5 &m2);
47
48private:
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
60public:
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
85inline 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.
89TBuffer &operator<<(TBuffer &buf, const TMD5 &md5);
90
91inline Bool_t operator!=(const TMD5 &m1, const TMD5 &m2)
92{ return !(m1 == m2); }
93
94
95#endif
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
unsigned char UChar_t
Definition RtypesCore.h:38
char Char_t
Definition RtypesCore.h:37
unsigned int UInt_t
Definition RtypesCore.h:46
#define ClassDef(name, id)
Definition Rtypes.h:337
TBuffer & operator<<(TBuffer &buf, const Tmpl *obj)
Definition TBuffer.h:397
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
TBuffer & operator>>(TBuffer &buf, TMD5 &md5)
Definition TMD5.h:85
Bool_t operator==(const TMD5 &m1, const TMD5 &m2)
Compare two message digests for equality.
Definition TMD5.cxx:372
Bool_t operator!=(const TMD5 &m1, const TMD5 &m2)
Definition TMD5.h:91
Buffer base class used for serializing objects.
Definition TBuffer.h:43
This code implements the MD5 message-digest algorithm.
Definition TMD5.h:44
const char * AsString() const
Return message digest as string.
Definition TMD5.cxx:220
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 TMD5 * FileChecksum(const char *file)
Returns checksum of specified file.
Definition TMD5.cxx:474
TMD5 & operator=(const TMD5 &rhs)
MD5 assignment operator.
Definition TMD5.cxx:90
virtual void Streamer(TBuffer &)
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
UChar_t fIn[64]
temp buffer
Definition TMD5.h:51
UInt_t fBits[2]
temp buffer
Definition TMD5.h:50
virtual ~TMD5()
Definition TMD5.h:64
UInt_t fBuf[4]
Definition TMD5.h:49
TMD5()
Create TMD5 object.
Definition TMD5.cxx:48
void Final()
MD5 finalization, ends an MD5 message-digest operation, writing the the message digest and zeroizing ...
Definition TMD5.cxx:167
Int_t SetDigest(const char *md5ascii)
Set the digest from the ASCII representation 'md5ascii'.
Definition TMD5.cxx:395
static TMD5 * ReadChecksum(const char *file)
Returns checksum stored in ASCII in specified file.
Definition TMD5.cxx:422
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
friend Bool_t operator==(const TMD5 &m1, const TMD5 &m2)
Compare two message digests for equality.
Definition TMD5.cxx:372
Bool_t fFinalized
Definition TMD5.h:54
UChar_t fDigest[16]
string representation of digest
Definition TMD5.h:53
Char_t fString[33]
temp buffer
Definition TMD5.h:52
void Print() const
Print digest in ascii hex form.
Definition TMD5.cxx:206
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
static Int_t WriteChecksum(const char *file, const TMD5 *md5)
Writes checksum in ASCII format to specified file.
Definition TMD5.cxx:452