Main Page | Class Hierarchy | Class List | File List | Class Members

MD5.h

00001 // MD5.h -- C++ wrapper arount the MD5 C interface.
00002 
00003 // Translation and modification (c) 1995 by Mordechai T. Abzug
00004 
00005 // This translation/ modification is provided "as is," without express or
00006 // implied warranty of any kind.
00007 
00008 // The translator/ modifier does not claim (1) that MD5 will do what you think
00009 // it does; (2) that this translation/ modification is accurate; or (3) that
00010 // this software is "merchantible."  (Language for this disclaimer partially
00011 // copied from the disclaimer below).
00012 
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 #ifndef _CSP_EXAMPLES_MD5_H
00042 #define _CSP_EXAMPLES_MD5_H
00043 
00044 
00045 #include <cstdio>
00046 #include <fstream>
00047 #include <iostream>
00048 
00049 
00050 class MD5
00051 {
00052   public:
00054     MD5();
00055 
00059     bool update(unsigned char* input, unsigned int input_length);
00060 
00063     bool update(std::istream& stream);
00064 
00066     bool update(FILE* file);
00067 
00069     bool update(std::ifstream& stream);
00070 
00073     bool finalize();
00074 
00077 
00079     MD5(unsigned char* asciiz);
00080 
00082     MD5(std::istream& stream);
00083 
00085     MD5(std::ifstream& stream);
00086 
00088     MD5(FILE* file);
00089 
00091 
00094     unsigned char* rawDigest();
00095 
00098     char* hexDigest();
00099 
00100     friend std::ostream& operator<<(std::ostream&, MD5 context);
00101 
00102   private:
00104     typedef unsigned int uint4;
00106     typedef unsigned short int uint2;
00107 
00109     typedef unsigned char uint1;
00110 
00111     uint4 state[4];
00112 
00114     uint4 count[2];
00115 
00117     uint1 buffer[64];
00118     uint1 digest[16];
00119     uint1 finalized;
00120 
00122     void init();
00123 
00125     void transform(uint1* buffer);
00126 
00127     static void encode(uint1* dest, uint4* src, uint4 length);
00128     static void decode(uint4* dest, uint1* src, uint4 length);
00129     static void memcpy(uint1* dest, uint1* src, uint4 length);
00130     static void memset(uint1* start, uint1 val, uint4 length);
00131 
00132     static inline uint4 rotate_left(uint4 x, uint4 n);
00133     static inline uint4 F(uint4 x, uint4 y, uint4 z);
00134     static inline uint4 G(uint4 x, uint4 y, uint4 z);
00135     static inline uint4 H(uint4 x, uint4 y, uint4 z);
00136     static inline uint4 I(uint4 x, uint4 y, uint4 z);
00137     static inline void FF(
00138         uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac);
00139     static inline void GG(
00140         uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac);
00141     static inline void HH(
00142         uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac);
00143     static inline void II(
00144         uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac);
00145 };
00146 
00147 
00148 #endif // _CSP_EXAMPLES_MD5_H
00149 
00150 // Local Variables:
00151 // mode: C++
00152 // End:

Generated on Wed May 25 12:21:14 2005 for csp.kdevelop by  doxygen 1.3.9.1