Is there any simple to use hashing algorithm to generate a 48-bit hash? I need to generate unique MAC addresses from unique input strings. There are no security issues here, just a question of mapping it to MAC address space (which is 48 bits).
I thought about CRC32, which is just 32 bits and easy (and cksum
is on every Linux), and use them for the lower 32 bits, but the collisions are pretty high if it is more than a few hosts.
If I could get 48 bit hash, I could mask the second least significant bit of the 8 most significant bits to ensure it is a Locally Administered Address. The loss of a single bit is minor.
Conversely, I could use a longer hashing algorithm (MD5, SHA1, etc.) and just take the 48 most significant or least significant bits.
Is there a simple way to do this?
My preference is command-line utility, but if I have to write short python or similar, no big deal.
After 2 years, here's an idea, in a real application (very close to what you needed).
I just needed a serial number of only 48 bits for a custom board that doesn't have a non-volatile memory. The board features a STM32 processor that has an unique ID of 96 bits (STM32_UUID).
Here is the complete C code:
I tested this solution on a batch of about 200 units (boards) and there was absolutely no problem, no conflicts. I've seen a lot of people having this issue, when they needed a smaller device ID that somehow originates from a large unique unit serial number.
Alternatively, you may search for an implementation of Bobcat 48 bit hash.