Skip to content
This repository has been archived by the owner on Jan 25, 2020. It is now read-only.

Password generation is flawed #662

Open
giucal opened this issue Mar 18, 2019 · 0 comments
Open

Password generation is flawed #662

giucal opened this issue Mar 18, 2019 · 0 comments

Comments

@giucal
Copy link

giucal commented Mar 18, 2019

Password generation uses modulo reduction, which notoriously does not preserve uniformity of the random source.

let idx = Int((cryptoRandomStream?.getInt())! % UInt32(charSet.characters.count))

See the documentation for the SystemRandomNumberGenerator. Something like

Int.random(in: 0..<charsetSize)

does generate cryptographically secure indices in the desired range, which is all that you need.

If you really want to use a Salsa20 key stream, you must implement proper uniform generation. To this end, have a look at the source of next(upperBound:).

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

No branches or pull requests

1 participant