-
Notifications
You must be signed in to change notification settings - Fork 1k
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
seed random with a real random data #377
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b22c4e9
seed random with a real random data
jrossi 7412d4e
clean up win32 stuff
jrossi 150cc1a
open not fopen and other mistakes
jrossi f98efe9
correction of types
jrossi 675ae12
fix typo
jrossi 1c393e2
program name when erroring
jrossi 65638e7
better message
jrossi 3f063e5
merging master into random. Fixing conflicts
jrossi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
|
||
#ifndef __RANDOMBYTES_H | ||
#define __RANDOMBYTES_H | ||
|
||
void randombytes(void *ptr, unsigned int length); | ||
void srandom_init(void); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#ifdef WIN32 | ||
#include "windows.h" | ||
#else | ||
#include <sys/stat.h> | ||
#include <fcntl.h> | ||
#endif | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include "shared.h" | ||
|
||
|
||
void randombytes(void *ptr, unsigned int length) | ||
{ | ||
|
||
char failed = 0; | ||
|
||
#ifdef WIN32 | ||
|
||
static HCRYPTPROV prov = 0; | ||
if (prov == 0) { | ||
if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, 0)) { | ||
failed = 1; | ||
} | ||
} | ||
if (!failed && !CryptGenRandom(prov, length, ptr)) { | ||
failed = 1; | ||
} | ||
|
||
#else | ||
|
||
int fh; | ||
if ((fh = open("/dev/urandom", O_RDONLY)) >= 0 || (fh = open("/dev/random", O_RDONLY)) >= 0) { | ||
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. open() returns an int: http://linux.die.net/man/3/open 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. Crap changed from fopen to open :) and did not correct everything. Will fix thank you |
||
if (read(fh, ptr, length) == 0) { | ||
failed = 1; | ||
} | ||
close(fh); | ||
} else { | ||
failed = 1; | ||
} | ||
|
||
#endif | ||
|
||
if (failed) { | ||
ErrorExit("%s: ERROR: randombytes failed for all possible methods for accessing random data", __local_name); | ||
} | ||
} | ||
|
||
|
||
void srandom_init(void) | ||
{ | ||
|
||
#ifndef WIN32 | ||
unsigned int seed; | ||
#ifdef __OpenBSD__ | ||
srandomdev(); | ||
#else | ||
randombytes(&seed, sizeof seed); | ||
srandom(seed); | ||
#endif // __OpenBSD__ | ||
#endif // Win32 | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
declaration was
void randombytes(unsigned char * ptr,unsigned int length);
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.
thanks needs this to be void so that we can file just about anything. Might be some downsides to that. Do you know of any?