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

Upgrade prng to c++ #92

Merged
merged 6 commits into from
Aug 20, 2018
Merged

Conversation

fireice-uk
Copy link
Member

@fireice-uk fireice-uk commented Aug 14, 2018

Use C++ and remove INITIALIZER

I removed a global random seed, as this is insecure. Instead we either use the randomness function directly or we use keccak hashes of a random seed stored on stack.

This might complicate test slightly. If you need to fix the prng for the test, I recommend wiring something based on C++11 mt just for tests, enabled by #define.


void prng::generate_random(uint8_t* output, size_t size_bytes)
{
if(hnd == nullptr)

This comment was marked as abuse.

This comment was marked as abuse.

{
hnd = new prng_handle;
#if defined(_WIN32)
if(!CryptAcquireContext(&hnd->prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT))

This comment was marked as abuse.

This comment was marked as abuse.


inline static prng& inst()
{
static thread_local prng inst;

This comment was marked as abuse.


#include "crypto-tests.h"

void setup_random(void)
{
memset(&state, 42, sizeof(union hash_state));
//memset(&state, 42, sizeof(union hash_state));

This comment was marked as abuse.


void prng::start()
{
hnd = new prng_handle;

This comment was marked as abuse.

This comment was marked as abuse.

std::abort();
}
#endif
delete hnd;

This comment was marked as abuse.

This comment was marked as abuse.

fireice-uk and others added 6 commits August 19, 2018 12:06
Co-authored-by: cryptoseyed <cryptoseyed@gmail.com>
Co-authored-by: omid-mmd <om.mo1375@gmail.com>
Create the cncrypto library two times, once for deamon and co and a special version with a deterministic random number generator for the crypto tests.

- build a test library `cncrypto_for_test`
- link crypto tests against `cncrypto_for_test`
add missing define guard
We use a new deterministic random number generator for the tests, therefore some hashes
differ compared to the old tests.

- update hashes those depends on the RNG
- add documentation to the test to see where the RNG effects the hashes

while(size_bytes > 200)
{
buffer[0]++;

This comment was marked as abuse.

This comment was marked as abuse.

@psychocrypt psychocrypt added this to the 0.4.0.0/0.3.X.X milestone Aug 20, 2018
@psychocrypt psychocrypt added the enhancement New feature or request label Aug 20, 2018
@psychocrypt psychocrypt self-assigned this Aug 20, 2018
@psychocrypt psychocrypt merged commit d763d3f into ryo-currency:dev Aug 20, 2018
@psychocrypt psychocrypt mentioned this pull request Sep 8, 2018
@fireice-uk fireice-uk deleted the topic-new-prng branch September 9, 2018 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants