With the current way that version numbers and timestamps are encoded, there could be a ton of 0s in the ID compared to how many 1s are present since the ID and timestamps are encoded as they are represented in binary.
I have thought about this for a while and have come to the conclusion that it might be best to use an additional Mac instance. This implementation will depend on the utils provided in #7. The procedure will be like so:
MasterKeyGenerator has an additional "static" Mac member (its key never changes).
ID is generated as [Prefix][RandomBytes][empty mac slice]
The first 2 bits of metadata are encoded (the two bools)
Call insert_ints_into_slice(), preserving those two bools, overwriting all remaining space that will be taking up TIMESTAMP_BITS + VERSION_BITS with 0s
Compute the "static" mac
XOR the version with the first 4 bytes of the mac as a u32
XOR the timestamp with the next 8 bytes of the mac as a u64
Call insert_ints_into_slice() to insert these values into the ID
By keeping this MAC's key static, different versions and timestamps will be readable, while this section of the ID will always look different (except for the two bools). The MAC and its key do not need to be super secure, as it is primarily just to have some more random-looking IDs. The only requirement for the MAC is that it must be able to output 12 bytes.
With the current way that version numbers and timestamps are encoded, there could be a ton of 0s in the ID compared to how many 1s are present since the ID and timestamps are encoded as they are represented in binary.
I have thought about this for a while and have come to the conclusion that it might be best to use an additional
Mac
instance. This implementation will depend on theutils
provided in #7. The procedure will be like so:By keeping this MAC's key static, different versions and timestamps will be readable, while this section of the ID will always look different (except for the two bools). The MAC and its key do not need to be super secure, as it is primarily just to have some more random-looking IDs. The only requirement for the MAC is that it must be able to output 12 bytes.