-
Notifications
You must be signed in to change notification settings - Fork 187
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
Cryptographically Secure RNG #97
Comments
I'll have to think about this some. In principle I like the idea, but there are a few kinks to consider:
|
Thanks for your consideration on this topic. I recognized by your earlier comments on past issues that you are hesitant in gearing your library towards cryptography, but I can assure that it does assume a healthy portion of you audience.
|
I'm inclined to implement this since this is not the first time this has been requested. This will be straightforward if I have a function
With
This is a quick-and-dirty way that kind of works, but it will not generate a uniform distribution, and will skip some values if The same thing is true for If you could look into an elegant way to do this with |
I have found a method to generate a random number up to any specified number of bytes, which could be used as a more accurate multiplier that you were mentioning above: |
If we use a number of bytes, it only works for the situation when the size of the range of numbers we want is a power of 256. How do we find a random number between 0 and 1000, for example? |
So first we identify an upper and lower bound to compute a range. Then we multiply the range by x amount of 32-bit bytes and divide by 2 to the power of the number of bits minus one. Finally, add the lower bound. So, using the function |
Note I did make a small edit to the random bytes generator above as leading zeros were being lost in the process of decimal to binary conversion. |
I have done a bit of work and would like to submit a final RNG for you to test and approve. I now believe it to be as random as the original constructive function, |
If you're wanting to put it directly in the library you can make a pull request. If you just want to share some code with me you can make a gist and I'll look at it |
Thank you, I am relatively new to GitHub and am still learning all its processes. |
OK, thanks, I'll try to look at it later |
Clicking that link appears to be broken, here's the intended target: https://gist.github.com/benjaminBrownlee/2823e06d0b455969a06a13eddbadeb48 |
Thanks for fixing the URL. As I said, I am still getting used to GitHub. |
Sorry I still haven't tried adding this to the library, I've been rather busy lately |
Is anyone aware of where to find tools or processes to check mass calculations? I want to run my proposed RNG at numerous bit sizes and collect the data to check for accuracy and distribution. |
How about injecting the random method instead of having so much headaches about it? |
@benjaminBrownlee you can format your code blocks by using triple backticks, like this: Adding the language name (I used the short version "js" but it also works with "javascript") activates syntax highlighting for that lang (if supported) |
This is more of a recommendation than an issue, but the
bigInt.randBetween()
function could be enhanced with a cryptographically secure alternative. Most of the content can be copied, but instances ofMath.random()
can be replaced with a function that returnswindow.crypto.getRandomValues(new Uint32Array(1))[0]/4294967295
. For performance conditions, the original should be kept, but this new option would definitely be useful.The text was updated successfully, but these errors were encountered: