Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _MMH_h_
00025 #define _MMH_h_
00026
00027 #include "ink_code.h"
00028 #include "ink_defs.h"
00029 #include "CryptoHash.h"
00030
00031 struct MMH_CTX
00032 {
00033 uint64_t state[4];
00034 unsigned char buffer[32];
00035 int buffer_size;
00036 int blocks;
00037 };
00038
00039
00040
00041
00042 int inkcoreapi ink_code_incr_MMH_init(MMH_CTX * context);
00043 int inkcoreapi ink_code_incr_MMH_update(MMH_CTX * context, const char *input, int input_length);
00044 int inkcoreapi ink_code_incr_MMH_final(uint8_t *sixteen_byte_hash_pointer, MMH_CTX * context);
00045 int inkcoreapi ink_code_MMH(unsigned char *input, int len, unsigned char *sixteen_byte_hash);
00046
00047
00048
00049
00050
00051
00052
00053 class MMHContext : public CryptoContext
00054 {
00055 protected:
00056 MMH_CTX _ctx;
00057 public:
00058 MMHContext();
00059
00060 virtual bool update(void const* data, int length);
00061
00062 virtual bool finalize(CryptoHash& hash);
00063 # if 0
00064 MMH & loadFromBuffer(char *MMH_buf)
00065 {
00066 int i;
00067 char *s, *d;
00068
00069 for (i = 0, s = MMH_buf, d = (char *) (&(b[0])); i < 8; i++, *d++ = *s++);
00070 for (i = 0, d = (char *) (&(b[1])); i < 8; i++, *d++ = *s++);
00071 return *this;
00072 }
00073 MMH & storeToBuffer(char *MMH_buf) {
00074 int i;
00075 char *s, *d;
00076
00077 for (i = 0, d = MMH_buf, s = (char *) (&(b[0])); i < 8; i++, *d++ = *s++);
00078 for (i = 0, s = (char *) (&(b[1])); i < 8; i++, *d++ = *s++);
00079 return *this;
00080 }
00081 MMH & operator =(char *MMH) {
00082 return loadFromBuffer(MMH);
00083 }
00084 MMH & operator =(unsigned char *MMH) {
00085 return loadFromBuffer(reinterpret_cast<char *>(MMH));
00086 }
00087
00088 char *toStr(char *MMH_str) const
00089 {
00090 int i;
00091 char *s, *d;
00092
00093 for (i = 0, d = MMH_str, s = (char *) (&(b[0])); i < 8; i++, *d++ = *s++);
00094 for (i = 0, s = (char *) (&(b[1])); i < 8; i++, *d++ = *s++);
00095
00096 return MMH_str;
00097 }
00098 void encodeBuffer(unsigned char *buffer, int len)
00099 {
00100 unsigned char MMH[16];
00101 ink_code_MMH(buffer, len, MMH);
00102 *this = MMH;
00103 }
00104 void encodeBuffer(char *buffer, int len)
00105 {
00106 encodeBuffer((unsigned char *) buffer, len);
00107 }
00108 char *str()
00109 {
00110 return reinterpret_cast<char *>(b);
00111 }
00112 char *toHexStr(char hex_MMH[33])
00113 {
00114 return ink_code_md5_stringify_fast(hex_MMH, str());
00115 }
00116 # endif
00117 };
00118
00119 #endif