Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

vos/metaobjects/misc/md5.hh

Go to the documentation of this file.
00001 // MD5.CC - source code for the C++/object oriented translation and
00002 //          modification of MD5.
00003 
00004 // Translation and modification (c) 1995 by Mordechai T. Abzug
00005 
00006 // This translation/ modification is provided "as is," without express or
00007 // implied warranty of any kind.
00008 
00009 // The translator/ modifier does not claim (1) that MD5 will do what you think
00010 // it does; (2) that this translation/ modification is accurate; or (3) that
00011 // this software is "merchantible."  (Language for this disclaimer partially
00012 // copied from the disclaimer below).
00013 
00014 /* based on:
00015 
00016    MD5.H - header file for MD5C.C
00017    MDDRIVER.C - test driver for MD2, MD4 and MD5
00018 
00019    Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
00020 rights reserved.
00021 
00022 License to copy and use this software is granted provided that it
00023 is identified as the "RSA Data Security, Inc. MD5 Message-Digest
00024 Algorithm" in all material mentioning or referencing this software
00025 or this function.
00026 
00027 License is also granted to make and use derivative works provided
00028 that such works are identified as "derived from the RSA Data
00029 Security, Inc. MD5 Message-Digest Algorithm" in all material
00030 mentioning or referencing the derived work.
00031 
00032 RSA Data Security, Inc. makes no representations concerning either
00033 the merchantability of this software or the suitability of this
00034 software for any particular purpose. It is provided "as is"
00035 without express or implied warranty of any kind.
00036 
00037 These notices must be retained in any copies of any part of this
00038 documentation and/or software.
00039 
00040 */
00041 
00042 #include <cstdio>
00043 #include <fstream>
00044 #include <iostream>
00045 
00046 #if defined(_WIN32) && defined(_MSC_VER)
00047 # ifdef MISC_EXPORTS
00048 #  define MISC_API __declspec(dllexport)
00049 # else
00050 #  define MISC_API __declspec(dllimport)
00051 # endif
00052 #else
00053 # define MISC_API
00054 #endif
00055 
00056 
00057 using namespace std;
00058 
00059 class MISC_API _MD5 {
00060 
00061 public:
00062 // methods for controlled operation:
00063   _MD5              ();  // simple initializer
00064   void  update     (unsigned char *input, unsigned int input_length);
00065   void  update     (istream& stream);
00066   void  update     (FILE *file);
00067   void  update     (ifstream& stream);
00068   void  finalize   ();
00069 
00070 // constructors for special circumstances.  All these constructors finalize
00071 // the _MD5 context.
00072   _MD5              (unsigned char *string); // digest string, finalize
00073   _MD5              (istream& stream);       // digest stream, finalize
00074   _MD5              (FILE *file);            // digest file, close, finalize
00075   _MD5              (ifstream& stream);      // digest stream, close, finalize
00076 
00077 // methods to acquire finalized result
00078   unsigned char    *raw_digest ();  // digest as a 16-byte binary array
00079   char *            hex_digest ();  // digest as a 33-byte ascii-hex string
00080   friend ostream&   operator<< (ostream&, _MD5 context);
00081 
00082 
00083 
00084 private:
00085 
00086 // first, some types:
00087   typedef unsigned       int uint4; // assumes integer is 4 words long
00088   typedef unsigned short int uint2; // assumes short integer is 2 words long
00089   typedef unsigned      char uint1; // assumes char is 1 word long
00090 
00091 // next, the private data:
00092   uint4 state[4];
00093   uint4 count[2];     // number of *bits*, mod 2^64
00094   uint1 buffer[64];   // input buffer
00095   uint1 digest[16];
00096   uint1 finalized;
00097 
00098 // last, the private methods, mostly static:
00099   void init             ();               // called by all constructors
00100   void transform        (uint1 *buffer);  // does the real update work.  Note
00101                                           // that length is implied to be 64.
00102 
00103   static void encode    (uint1 *dest, uint4 *src, uint4 length);
00104   static void decode    (uint4 *dest, uint1 *src, uint4 length);
00105   static void memcpy    (uint1 *dest, uint1 *src, uint4 length);
00106   static void memset    (uint1 *start, uint1 val, uint4 length);
00107 
00108   static inline uint4  rotate_left (uint4 x, uint4 n);
00109   static inline uint4  F           (uint4 x, uint4 y, uint4 z);
00110   static inline uint4  G           (uint4 x, uint4 y, uint4 z);
00111   static inline uint4  H           (uint4 x, uint4 y, uint4 z);
00112   static inline uint4  I           (uint4 x, uint4 y, uint4 z);
00113   static inline void   FF  (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x,
00114                 uint4 s, uint4 ac);
00115   static inline void   GG  (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x,
00116                 uint4 s, uint4 ac);
00117   static inline void   HH  (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x,
00118                 uint4 s, uint4 ac);
00119   static inline void   II  (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x,
00120                 uint4 s, uint4 ac);
00121 
00122 };

Generated on Tue Aug 12 03:55:45 2003 for Interreality Project - VOS by doxygen 1.3.2