pred@2142: // MD5.CC - source code for the C++/object oriented translation and pred@2142: // modification of MD5. pred@2142: pred@2142: // Translation and modification (c) 1995 by Mordechai T. Abzug pred@2142: pred@2142: // This translation/ modification is provided "as is," without express or pred@2142: // implied warranty of any kind. pred@2142: pred@2142: // The translator/ modifier does not claim (1) that MD5 will do what you think pred@2142: // it does; (2) that this translation/ modification is accurate; or (3) that pred@2142: // this software is "merchantible." (Language for this disclaimer partially pred@2142: // copied from the disclaimer below). pred@2142: pred@2142: /* based on: pred@2142: pred@2142: MD5.H - header file for MD5C.C pred@2142: MDDRIVER.C - test driver for MD2, MD4 and MD5 pred@2142: pred@2142: Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All pred@2142: rights reserved. pred@2142: pred@2142: License to copy and use this software is granted provided that it pred@2142: is identified as the "RSA Data Security, Inc. MD5 Message-Digest pred@2142: Algorithm" in all material mentioning or referencing this software pred@2142: or this function. pred@2142: pred@2142: License is also granted to make and use derivative works provided pred@2142: that such works are identified as "derived from the RSA Data pred@2142: Security, Inc. MD5 Message-Digest Algorithm" in all material pred@2142: mentioning or referencing the derived work. pred@2142: pred@2142: RSA Data Security, Inc. makes no representations concerning either pred@2142: the merchantability of this software or the suitability of this pred@2142: software for any particular purpose. It is provided "as is" pred@2142: without express or implied warranty of any kind. pred@2142: pred@2142: These notices must be retained in any copies of any part of this pred@2142: documentation and/or software. pred@2142: pred@2142: */ pred@2142: pred@2142: #include pred@2142: //#include pred@2142: //#include pred@2142: pred@2142: class MD5 { pred@2142: pred@2142: public: pred@2142: // methods for controlled operation: pred@2142: MD5 (); // simple initializer pred@2142: void update (unsigned char *input, unsigned int input_length); pred@2142: void update (FILE *file); pred@2142: void finalize (); pred@2142: pred@2142: // constructors for special circumstances. All these constructors finalize pred@2142: // the MD5 context. pred@2142: MD5 (unsigned char *string); // digest string, finalize pred@2142: MD5 (FILE *file); // digest file, close, finalize pred@2142: pred@2142: // methods to acquire finalized result pred@2142: unsigned char *raw_digest (); // digest as a 16-byte binary array pred@2142: unsigned char *raw_digest(unsigned char buffer[16]); pred@2142: char * hex_digest (); // digest as a 33-byte ascii-hex string pred@2142: char * hex_digest (char buffer[33]); //same as above, passing buffer pred@2142: pred@2142: pred@2142: pred@2142: private: pred@2142: pred@2142: // first, some types: pred@2142: typedef unsigned int uint4; // assumes integer is 4 words long pred@2142: typedef unsigned short int uint2; // assumes short integer is 2 words long pred@2142: typedef unsigned char uint1; // assumes char is 1 word long pred@2142: pred@2142: // next, the private data: pred@2142: uint4 state[4]; pred@2142: uint4 count[2]; // number of *bits*, mod 2^64 pred@2142: uint1 buffer[64]; // input buffer pred@2142: uint1 digest[16]; pred@2142: uint1 finalized; pred@2142: pred@2142: // last, the private methods, mostly static: pred@2142: void init (); // called by all constructors pred@2142: void transform (uint1 *buffer); // does the real update work. Note pred@2142: // that length is implied to be 64. pred@2142: pred@2142: static void encode (uint1 *dest, uint4 *src, uint4 length); pred@2142: static void decode (uint4 *dest, uint1 *src, uint4 length); pred@2142: static void memcpy (uint1 *dest, uint1 *src, uint4 length); pred@2142: static void memset (uint1 *start, uint1 val, uint4 length); pred@2142: pred@2142: static inline uint4 rotate_left (uint4 x, uint4 n); pred@2142: static inline uint4 F (uint4 x, uint4 y, uint4 z); pred@2142: static inline uint4 G (uint4 x, uint4 y, uint4 z); pred@2142: static inline uint4 H (uint4 x, uint4 y, uint4 z); pred@2142: static inline uint4 I (uint4 x, uint4 y, uint4 z); pred@2142: static inline void FF (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, pred@2142: uint4 s, uint4 ac); pred@2142: static inline void GG (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, pred@2142: uint4 s, uint4 ac); pred@2142: static inline void HH (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, pred@2142: uint4 s, uint4 ac); pred@2142: static inline void II (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, pred@2142: uint4 s, uint4 ac); pred@2142: pred@2142: };