-
Notifications
You must be signed in to change notification settings - Fork 505
Move random_int() to util.cpp #5555
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
39a8e8e
f290892
ce7ab83
ff5e878
d60cab9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -542,3 +542,41 @@ bool process_exists(int pid) { | |||||
| } | ||||||
|
|
||||||
| #endif | ||||||
|
|
||||||
| unsigned int random_int() { | ||||||
| unsigned int n; | ||||||
| #if defined(_WIN32) | ||||||
| #if defined(__CYGWIN32__) | ||||||
| HMODULE hLib=LoadLibrary((const char *)"ADVAPI32.DLL"); | ||||||
| #else | ||||||
| HMODULE hLib=LoadLibrary("ADVAPI32.DLL"); | ||||||
computezrmle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| #endif | ||||||
| if (!hLib) { | ||||||
| fprintf(stderr, "Error: can't load ADVAPI32.DLL\n"); | ||||||
| exit(2); | ||||||
computezrmle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| } | ||||||
| BOOLEAN (APIENTRY *pfn)(void*, ULONG) = | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the library was not loaded correctly two lines above - this will fail with an exception |
||||||
| (BOOLEAN (APIENTRY *)(void*,ULONG))GetProcAddress(hLib,"SystemFunction036"); | ||||||
| if (pfn) { | ||||||
| char buff[32]; | ||||||
| ULONG ulCbBuff = sizeof(buff); | ||||||
| if(pfn(buff,ulCbBuff)) { | ||||||
| // use buff full of random goop | ||||||
| memcpy(&n,buff,sizeof(n)); | ||||||
| } | ||||||
| } | ||||||
| FreeLibrary(hLib); | ||||||
| #else | ||||||
| FILE* f = fopen("/dev/random", "r"); | ||||||
|
||||||
| FILE* f = fopen("/dev/random", "r"); | |
| FILE* f = boinc::fopen("/dev/random", "r"); |
computezrmle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (1 != fread(&n, sizeof(n), 1, f)) { | |
| if (1 != boinc::fread(&n, sizeof(n), 1, f)) { |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| fclose(f); | |
| boinc::fclose(f); |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What will be returned in case of an error?
We should indicate somehow that the function returns a proper result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to change signature function to something like this:
bool random_int(unsigned int& value)And return the random value using the output parameter, and return
trueon success andfalsein case of an errorThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, then you need to adjust
crypt_prog.cppwith the new function signature