• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

MMH.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
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 // signed-unsigned-const gratuitous differences brought
00040 // to you by history and the ANSI committee
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   MMH will return different values on big-endian and little-endian
00049   machines. It can be adapted to return the same values at some additional
00050   cost.
00051 
00052 */
00053 class MMHContext : public CryptoContext
00054 {
00055 protected:
00056   MMH_CTX _ctx;
00057 public:
00058   MMHContext();
00059   /// Update the hash with @a data of @a length bytes.
00060   virtual bool update(void const* data, int length);
00061   /// Finalize and extract the @a hash.
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

Generated by  doxygen 1.7.1