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

Make CtrDrbg easier to use #207

Open
chethega opened this issue Aug 17, 2019 · 0 comments
Open

Make CtrDrbg easier to use #207

chethega opened this issue Aug 17, 2019 · 0 comments

Comments

@chethega
Copy link

Generating nonces is a very typical need. This is rather inconvenient with the currently existing exports. The issue came up when looking for a fix for GenieFramework/Genie.jl#162 . Tangentially related JuliaLang/julia#27614

What I'd like to see:

  1. Document-by-example proper safe usage, especially with respect to initialization and seeding.
  2. Use entropy as a default argument: CSPRNG = MbedTLS.CtrDrbg() does not give us a usable state. I am happy to report that direct calls to rand(CSPRNG, n) segfault instead of returning bad random. This is laudable: bad random is almost the worst possible behavior; a clean panic, or even a segfault is a much safer outcome. Exploitable memory corruption is the only worse thing one could possibly do.
  3. Either implement the Random interface correctly, or do not declare as a subtype of AbstractRNG. For comparison:
julia> rng1 = Random.RandomDevice(); rng2 = MbedTLS.CtrDrbg(); MbedTLS.seed!(rng2, MbedTLS.Entropy());
julia> rand(rng1, Float32)
0.5747224f0

julia> rand(rng2, Float32)
ERROR: ArgumentError: Sampler for this object is not defined

julia> rand(rng1, 2)
2-element Array{Float64,1}:
 0.32157480543452466 
 0.032868961307404465

julia> rand(rng2, 2)
2-element Array{UInt8,1}:
 0xc6
 0x2f
  1. Alternatively, don't export at all. People can look for other ways of generating secure random; better send them off than provide an option that is not misuse resistant.
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

1 participant