src/addon/md5.hpp

Go to the documentation of this file.
00001 //
00002 // MD5 message-digest algorithm
00003 // Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All rights reserved.
00004 //
00005 // C++/object oriented translation and modification:
00006 // Copyright (C) 1995 Mordechai T. Abzug
00007 //
00008 // Further adaptations for SuperTux:
00009 // Copyright (C) 2008 Christoph Sommer <christoph.sommer@2008.expires.deltadevelopment.de>
00010 //
00011 // This translation/modification is provided "as is," without express or
00012 // implied warranty of any kind.
00013 //
00014 // The translators/modifiers do not claim:
00015 // (1) that MD5 will do what you think it does; 
00016 // (2) that this translation/ modification is accurate; or 
00017 // (3) that this software is "merchantible."
00018 //
00019 // based on:
00020 //
00021 // MD5.H - header file for MD5C.C
00022 // MDDRIVER.C - test driver for MD2, MD4 and MD5
00023 // Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All rights reserved.
00024 //
00025 // License to copy and use this software is granted provided that it
00026 // is identified as the "RSA Data Security, Inc. MD5 Message-Digest
00027 // Algorithm" in all material mentioning or referencing this software
00028 // or this function.
00029 // 
00030 // License is also granted to make and use derivative works provided
00031 // that such works are identified as "derived from the RSA Data
00032 // Security, Inc. MD5 Message-Digest Algorithm" in all material
00033 // mentioning or referencing the derived work.
00034 // 
00035 // RSA Data Security, Inc. makes no representations concerning either
00036 // the merchantability of this software or the suitability of this
00037 // software for any particular purpose. It is provided "as is"
00038 // without express or implied warranty of any kind.
00039 // 
00040 // These notices must be retained in any copies of any part of this
00041 // documentation and/or software.
00042 // 
00043 
00044 #ifndef HEADER_SUPERTUX_ADDON_MD5_HPP
00045 #define HEADER_SUPERTUX_ADDON_MD5_HPP
00046 
00047 #include <fstream>
00048 #include <stdint.h>
00049 
00050 class MD5 
00051 {
00052 public:
00053   MD5(); 
00054   MD5(uint8_t* string); 
00055   MD5(std::istream& stream); 
00056   MD5(FILE *file); 
00057   MD5(std::ifstream& stream); 
00059   void update(uint8_t* input, unsigned int input_length); 
00060   void update(std::istream& stream);
00061   void update(FILE *file);
00062   void update(std::ifstream& stream);
00063 
00064   uint8_t* raw_digest(); 
00065   std::string hex_digest(); 
00066   friend std::ostream& operator<<(std::ostream&, MD5 context);
00067 
00068 private:
00069   uint32_t state[4];
00070   uint32_t count[2]; 
00071   uint8_t buffer[64]; 
00072   uint8_t digest[16];
00073   bool finalized;
00074 
00075   void init(); 
00076   void finalize(); 
00077   void transform(uint8_t* buffer); 
00079   static void encode(uint8_t* dest, uint32_t* src, uint32_t length); 
00080   static void decode(uint32_t* dest, uint8_t* src, uint32_t length); 
00081   static void memcpy(uint8_t* dest, uint8_t* src, uint32_t length);
00082   static void memset(uint8_t* start, uint8_t val, uint32_t length);
00083 
00084   static inline uint32_t rotate_left(uint32_t x, uint32_t n);
00085   static inline uint32_t F(uint32_t x, uint32_t y, uint32_t z); //*< F, G, H and I are basic MD5 functions. */
00086   static inline uint32_t G(uint32_t x, uint32_t y, uint32_t z);
00087   static inline uint32_t H(uint32_t x, uint32_t y, uint32_t z);
00088   static inline uint32_t I(uint32_t x, uint32_t y, uint32_t z);
00089   static inline void FF(uint32_t& a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac); 
00090   static inline void GG(uint32_t& a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac);
00091   static inline void HH(uint32_t& a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac);
00092   static inline void II(uint32_t& a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac);
00093 
00094 };
00095 
00096 #endif /*SUPERTUX_ADDON_MD5_HPP*/
00097 
00098 /* EOF */

Generated on Mon Jun 9 03:38:16 2014 for SuperTux by  doxygen 1.5.1