4 ms·
I see some confusion both in the article and in the comments. If we're talking about an API key, then the issue isn't collision and there's no relationship wit
by ecesena 10y ago
I see some confusion both in the article and in the comments.
If we're talking about an API key, then the issue isn't collision and there's no relationship with hashing or uuids except the recommended final length.
A key should be a random 128-bit string (or 192, or 256 if you need additional security).
If you need to generate a key from a passphrase, use a key expansion function, not an hash just because the length is the same.
I don't know if there's any proof of randomness for uuid, the risk (in absence of a proof) is that to provide uniqueness the bit distribution is uneven, which could leak some information to an attacker, thus reducing the real bit strength of the key.
- justusw 10y agoMost programming languages do not use secure random number generators. As you suggested it is not always wise to use UUIDs for API keys if you are not sure about the nature of the PRNG. Python for example uses os.urandom for random UUID generation (uuid4), as can be seen in the source: https://github.com/python/cpython/blob/3.5/Lib/uuid.py#L603 https://github.com/python/cpython/blob/3.5/Lib/uuid.py#L603 The standard library guarantees that os.urandom is "[...] suitable for cryptographic use." (https://docs.python.org/3.5/library/os.html#os.urandom https://docs.python.org/3.5/library/os.html#os.urandom) I'm not sure about other languages, so it might always be a good idea to look it up in the source code.
- nitrogen 10y agoIn Ruby you should use the SecureRandom module, but even that has had issues in the past. http://ruby-doc.org/stdlib-2.3.1/libdoc/securerandom/rdoc/index.html http://ruby-doc.org/stdlib-2.3.1/libdoc/securerandom/rdoc/in... https://news.ycombinator.com/item?id=11624890 https://news.ycombinator.com/item?id=11624890
- MichaelGG 10y agoSeems like it still has issues? The bug is still open. Embarrassing but entertaining.