Thread: Putting several hashes together. Better than md5/sha1?

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    40

    Putting several hashes together. Better than md5/sha1?

    Hi everyone. If I am to example putting several hash function together, would it be as safe as to make an md5 or a sha1 hash? I wonder because I have a program and it generate a md5 hash too slowly. It can only generate up to 20000 hashes (on a laptop) in a second and it is not enough. My idea to fix this is too use several fast hash functions as murmurhash2 and superfasthash, like this:
    Code:
    unsigned int* hashes = new unsigned int[2];
    hashes[0] = MurmurHash2(str,len);
    hashes[1] = SuperFastHash(str,len);
    But is this good in that sense it decrease collision chance than a md5 hash? if I am using a third hash function, would it decrease collision even more? If not, do anyone have any tips on how I can generate a hash fast which have extremely low collision chance?

    Thanks in advance!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What do you intend to use this hash algorithm for?

    EDIT:
    Anyway, thinking about it, my guess would be no: if the first hash applied results in a collision, subsequent applications of hash functions will also result in a collision.
    Last edited by laserlight; 04-03-2009 at 09:39 AM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    40
    To hash 8192 bytes and check if (using a multimap) that sequence of bytes have been added before.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    And you need to do this in 1/2000th of a second EVERY time, or on average? How about if there is a collision, check if it's a match or not, and use some sort of "list" of things with equal hashes.

    That way, you deal with collisions, but also get good throughput on most cases.

    This doesn't work if you have collisions far too often, or if you can't ever exceed your time-limit (in the later case, "Get a faster machine" is the right solution)!

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Feb 2009
    Posts
    40
    no, only when I am adding data. I do it now, but it is so annoying that the "adding part" of my program is limited to how fast it can make md5 hashes Well, the program will run on a much better machine later so, maybe should I wait to see how good it is performing there before I do some changes ;P

    But, Thanks for your answers

  6. #6
    Registered User
    Join Date
    Feb 2009
    Posts
    40
    Hi again. I got a new idea, instead of make 2 hashes of same data, what about:
    Code:
    hashes[0] = MurmurHash2(str,d);
    hashes[1] = MurmurHash2(str,d/2);
    ?

    This would not generate same hash so easy, or?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linux Putting my children to sleep with futex!?
    By Abs in forum Linux Programming
    Replies: 18
    Last Post: 02-12-2009, 06:43 PM
  2. Replies: 6
    Last Post: 06-30-2005, 08:03 AM
  3. how to create hashes
    By B-Con in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 02-26-2005, 02:13 AM
  4. Putting a password on the prog
    By Inferno in forum C++ Programming
    Replies: 24
    Last Post: 09-18-2004, 01:07 PM
  5. Putting a DialogBox into a DLL?
    By xds4lx in forum Windows Programming
    Replies: 1
    Last Post: 11-17-2002, 12:59 AM