Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UniqID source not binary #11

Open
Beanow opened this issue Sep 25, 2013 · 2 comments
Open

UniqID source not binary #11

Beanow opened this issue Sep 25, 2013 · 2 comments

Comments

@Beanow
Copy link

Beanow commented Sep 25, 2013

I noticed an off thing about the UniqID source compared to the other sources.
The output format is not in full binary range, but is in the hexadecimal range plus a few dots.

Was this deliberate?
And why, for example is the dot not removed? It's a very predictable part of the output and seems to me, basically wastes locations in the $size of requested characters.

UniqID may be geared towards collision prevention, but when used as a source of entropy, shouldn't it be ok to use a hashing function?

@ircmaxell
Copy link
Owner

It's never used by itself as an entropy source. It's always paired with at least one or two others. It wasn't intended to provide strong randomness, just more entropy. And given that the mixing strategies will use entropy without leaking information (like predictable location of characters), it should be secure as is

With that said, it wouldn't be bad to encode the result as binary. Just not necessary for security. Therefore, I'll leave this open.

@Beanow
Copy link
Author

Beanow commented Sep 26, 2013

True, uniqid is not sufficient as a sole source of entropy. Still in the current setup, every 1 in 23 bytes will be overhead from the dot. And the character range seriously waters down the 'density' of the data. For the sake of having abstract and predictable interfaces it would be nice to have this dot removed or use a hash so the dot in the input becomes irrelevant.

Or another method is to parse the UniqID format and converting it to binary 1:1.
This would save some CPU and provide the same amount of entropy compared to hashing.
Something along the lines of this:

$binary = '';
do{
  $sections = explode('.', uniqid('', true));
  $binary .= hex2bin($sections[0]);
  $binary .= pack('L', (int)$sections[1]);
}
while(strlen($binary) < $size);

return substr($binary, 0, $size);

//Sample output ($size=40): RD�y��4�ϳ�RD�y���eG7�RD�y��u >�RD�y��

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants