0

I need to choose a hashing function to convert a unique 8 byte ID to a 4 byte ID (as unique as possible) on a 12-Bit micro-controller(MSP430) in C.

What hashing function would you suggest?

I found some functions here but I don't know which one to choose.

Update: here is an old similar question specifying the original unique ID format: Hashing a 64-bit value into a 32-bit MAC address

Update 2:

 RSHash((const uint8_t*)ID_8BYTE, 8); 

uint32_t RSHash(const uint8_t* key, unsigned int len)
{
   uint32_t b    = 378551;
   uint32_t a    = 63689;
   uint32_t hash = 0;
   uint32_t i    = 0;

   for(i = 0; i < len; key++, i++)
   {
      hash = hash * a + (*key);
      a    = a * b;
   }

   return hash;
}
Tibbe
  • 317
  • 1
  • 2
  • 17
  • 4
    u have 8-byte id already hashed, then the bytes are rather random, just cut off any 4 bytes would do, i guess – Dee Oct 12 '18 at 08:36
  • Hmm, I wonder if this might be better elsewhere ([cryptography.se]? [stats.se]?) as I think the answer depends on how well distributed the 8-byte hashes are. If they are from a good hashing algorithm, then any hashing algorithm would work, I think, but if there are biases you might need special handling. – Ken Y-N Oct 12 '18 at 08:38
  • 1
    As Ken Y-N wrote, we need to know more about the 8-byte ID. The question is tagged "uuid", so maybe it is a random number? In that case, are all bits random, or only some? Or is it something else, such as a sequence number? Taking, let's say, the highest 4 bytes would work well if all bits are random, but very badly if it is a sequence number! – Thomas Padron-McCarthy Oct 12 '18 at 08:40
  • Depending on the properties of the 8byte ID an LFSR might yield usable results. – Kami Kaze Oct 12 '18 at 08:42
  • Hmm, without more context (how the original 8 byte ID are constructed), this is either asking for opinion only answers or too broad... So just my opinion (hence not an answer) but CRC32 could be useable (nice implementation already exist on [Lammert Bies's site](https://www.lammertbies.nl/comm/info/crc-calculation.html) ). But no real reason to prefere that to one on the general hashing function you linked... – Serge Ballesta Oct 12 '18 at 08:56
  • It is not already hashed, so cutting 4 bytes off would not be good. Here is an old similar question specifying the original unique ID format: https://stackoverflow.com/questions/20082130/hashing-a-64-bit-value-into-a-32-bit-mac-address – Tibbe Oct 12 '18 at 08:58
  • What about CRC-32? – dbush Oct 12 '18 at 14:46
  • I think you ask for magic here. – Stargateur Oct 12 '18 at 14:46

0 Answers0