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

MD5Hasher.h

Go to the documentation of this file.
00001 /*
00002  * This file is part of the ToolBox.
00003  * Copyright Thomas Jacob.
00004  *
00005  * READ README.TXT BEFORE USE!!
00006  */
00007 
00008 
00009 #ifndef __TOOLBOX_MD5HASHER_H
00010 #define __TOOLBOX_MD5HASHER_H
00011 
00012 
00013 #define _TB_MD5HASHER_RL(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
00014 
00015 #define _TB_MD5HASHER_F(x, y, z) (((x) & (y)) | ((~x) & (z)))
00016 #define _TB_MD5HASHER_G(x, y, z) (((x) & (z)) | ((y) & (~z)))
00017 #define _TB_MD5HASHER_H(x, y, z) ((x) ^ (y) ^ (z))
00018 #define _TB_MD5HASHER_I(x, y, z) ((y) ^ ((x) | (~z)))
00019 
00020 #define _TB_MD5HASHER_FF(a, b, c, d, x, s, ac) \
00021    { \
00022       (a) += _TB_MD5HASHER_F ((b), (c), (d)) + (x) + (unsigned long) (ac); \
00023       (a) = _TB_MD5HASHER_RL ((a), (s)); \
00024       (a) += (b); \
00025    }
00026 
00027 #define _TB_MD5HASHER_GG(a, b, c, d, x, s, ac) \
00028    { \
00029       (a) += _TB_MD5HASHER_G ((b), (c), (d)) + (x) + (unsigned long) (ac); \
00030       (a) = _TB_MD5HASHER_RL ((a), (s)); \
00031       (a) += (b); \
00032    }
00033 
00034 #define _TB_MD5HASHER_HH(a, b, c, d, x, s, ac) \
00035    { \
00036       (a) += _TB_MD5HASHER_H ((b), (c), (d)) + (x) + (unsigned long) (ac); \
00037       (a) = _TB_MD5HASHER_RL ((a), (s)); \
00038       (a) += (b); \
00039    }
00040 
00041 #define _TB_MD5HASHER_II(a, b, c, d, x, s, ac) \
00042    { \
00043       (a) += _TB_MD5HASHER_I ((b), (c), (d)) + (x) + (unsigned long) (ac); \
00044       (a) = _TB_MD5HASHER_RL ((a), (s)); \
00045       (a) += (b); \
00046    }
00047 
00048 
00049 namespace toolbox
00050 {
00051    class MD5Hasher
00052    {
00053       private:
00054 
00055          static const unsigned char PADDING[64];
00056 
00057          unsigned char buffer[64];
00058          unsigned long count1;
00059          unsigned long count2;
00060          unsigned long state[4];
00061 
00062          void reset();
00063          inline void transform(unsigned long * newState);
00064 
00065       public:
00066 
00067          MD5Hasher();
00068          void finalize(unsigned char * digest);
00069          inline void hash(unsigned char number);
00070          inline void hash(unsigned int number);
00071          inline void hash(unsigned long number);
00072          void hash(const unsigned char * data, int length);
00073    };
00074 }
00075 
00076 
00077 #endif

Generated on Tue Oct 3 00:23:38 2006 for ToolBox by doxygen 1.3.6