provably-fair | PHP implementation of Bustabit 's Provably Fair system
kandi X-RAY | provably-fair Summary
kandi X-RAY | provably-fair Summary
PHP implementation of Bustabit's Provably Fair system. Demo here.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Checks if the hash is divisible .
- Calculate the hash .
- Generate a server seed
- Assert that hash algorithm is valid .
- Assert that seed is valid
- Set value .
- Get value .
provably-fair Key Features
provably-fair Examples and Code Snippets
Community Discussions
Trending Discussions on provably-fair
QUESTION
I looked into provably fair random numbers, and came across this website: https://dicesites.com/provably-fair
First off, what class should be used for the server sided hash? There are so many hash algorithms like SHA512, SHA256 or SHA384Cng and I do not understand the difference between them.
Second off, what method would be used to convert from the unhashed seed to the hashed seed, and what method would be used to take the string for the seed provided by the user into account during the hash creation. Also, is the nonce simply added at the end of the string provided by the user in order to prevent duplicate hashes?
Third off, I do not understand why the hashed server seed is originally a SHA256 hash but is later used to calculate a HMAC SHA512 hash.
Lastly, what would be used to convert the first 5 characters of the final generated hash to a roll number?
I have had no luck in finding any examples of any random number generators that use a server seed and client seed, only things like System.Security.Cryptography.RandomNumberGenerator
.
ANSWER
Answered 2017-Jun-13 at 14:58The page you link to describes the process, however I will try to go in to more detail and provide a C# example.
First there are two hashings that happen. One general hash to prove that the server is not changing the server key as you gamble, this hash is not secret and is given to the player at the start of play. There is also a keyed hash (called a HMAC) to actually generate the dice rolls and uses a combination of the server key, the data the user provided, and a number that counts up.
Here is the process that happens:
- The server generates a secret key for the play session and sets a counter to 0.
- SHA256 is used on the key to generate a hash, this hash is given to the player. This hash is not used in any math to generate the dice rolls, it is only used for verification by the player.
- The player requests a dice roll and provides a phrase to be used in the generation of the number.
- The server uses a SHA512-HMAC using secret key as the key then the string the user provided plus "-" plus the number of the counter set in step 1 to generate a hash.
- The server increments the counter by 1, this is done because the same server key is used every time and if the same user string was used it would just generate the same number over and over.
- The server takes the first 21 bits of the hash generated, converts it to a
int
, it then checks to see if theint
is larger than 999999 if it is it keeps repeating till it finds a number that is not over 999999. - It takes the number from step 6 and does
number%(10000)/100.0
on it to get a floating point number. - That floating point number is returned to the user.
- Either repeat starting at step 3 for a new roll or continue to step 10.
- The player signals the play session is over. The server returns the secret key to the user and restarts at step 1.
The user once he gets the secret key from step 10 can hash it using SHA256 and check that he gets the same hash he was told at the start of the play session. He can then re-do all the steps the server did now that he has the secret key and verify that the server did not fake any dice rolls.
How to do this in code:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install provably-fair
PHP requires the Visual C runtime (CRT). The Microsoft Visual C++ Redistributable for Visual Studio 2019 is suitable for all these PHP versions, see visualstudio.microsoft.com. You MUST download the x86 CRT for PHP x86 builds and the x64 CRT for PHP x64 builds. The CRT installer supports the /quiet and /norestart command-line switches, so you can also script it.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page