-
Notifications
You must be signed in to change notification settings - Fork 49
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
Conversation
8ea377b
to
3945cf1
Compare
|
||
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.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
src/crypto/random.cpp
Outdated
{ | ||
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.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
src/crypto/random.hpp
Outdated
|
||
inline static prng& inst() | ||
{ | ||
static thread_local prng inst; |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
|
||
#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.
This comment was marked as abuse.
Sorry, something went wrong.
|
||
void prng::start() | ||
{ | ||
hnd = new prng_handle; |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
src/crypto/random.cpp
Outdated
std::abort(); | ||
} | ||
#endif | ||
delete hnd; |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
5bc5531
to
0e3b75d
Compare
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
2215345
to
d75be9d
Compare
|
||
while(size_bytes > 200) | ||
{ | ||
buffer[0]++; |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
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
.