Repository navigation
Add RAND_DRBG_bytes - #4752
Add RAND_DRBG_bytes#4752kroeckx wants to merge 3 commits into
Conversation
mspncp
left a comment
There was a problem hiding this comment.
Looks fine to me on first view in principle, except for one issue: I don't think it's a good idea to allow a NULL drbg pointer and fallback to using RAND_bytes(). See my annotations.
There was a problem hiding this comment.
I don't like this automagical fallback to RAND_bytes(). The default RAND_METHOD (RAND_OpenSSL()) is implemented on top of the RAND_DRBG api, so RAND_DRBG's implementation should not refer back to RAND_METHODs.
Also, no other RAND_DRBG_xxx() api call accepts a NULL pointer as drbg. It's the caller's duty to choose properly between RAND_bytes() and RAND_DRBG_bytes(), like in ssl_randbytes.
There was a problem hiding this comment.
See my previous comment:
if (s->drbg != NULL) {
...
return RAND_DRBG_bytes(s->drbg, rnd, size);
}
if (size > INT_MAX)
return 0;
return RAND_bytes(rnd, (int)size);
There was a problem hiding this comment.
The first version of the code snippet was buggy, so I edited it.
|
But I do like that you add additional data automatically. |
6e9a3ad to
4c46337
Compare
|
I've pushed a new version |
There was a problem hiding this comment.
I'm wondering if OPENSSL_secure_free() would be acceptable for this case.
There was a problem hiding this comment.
Does it make a great difference in performance? If not, I would leave it as it is.
Also, if performance is an issue, then I would be more worried about the performance impact of calling rand_drbg_get_additional_data() on every call.
d9a5dfd to
8262261
Compare
|
I've pushed a new version |
8262261 to
79f1d43
Compare
|
What has changed w.r.t the version from two days ago? |
|
Only the rand_drbg_get_additional_data() function, it should do something useful on at least unix and windows. |
|
The travis failure with --strict-warnings is something I'm trying to deal with in #4757 |
There was a problem hiding this comment.
Since we're generating new bytes, RDRAND might be appropriate even though it is feeding into the DRBG.
The other quick data source that comes to mind are the clock_gettime(2) timers:
#if _POSIX_C_SOURCE >= 199309L
struct timespec ts;
clockid_t cid;
# ifdef CLOCK_BOOTTIME
cid = CLOCK_BOOTTIME;
# elif defined CLOCK_MONOTONIC
cid = CLOCK_MONOTONIC;
# else
cid = CLOCK_REALTIME;
# endif
if (clock_gettime(cid, &ts) == 0)
...
#endif
There was a problem hiding this comment.
I've actually had clock_gettime(CLOCK_MONOTONIC) in a previous version of the patch but I've removed it in favor of just reading the TSC ourselves.
But clock_gettime(CLOCK_REALTIME) might be a useful replacement for gettimeofday(), it has a resolution ns instead of μs.
6b43ee4 to
7c0ede3
Compare
|
I've pushed a new commit |
|
I'll try to have a decent look at this tomorrow. |
paulidale
left a comment
There was a problem hiding this comment.
One typo in a comment which is insignificant.
|
|
||
| /* | ||
| * Generates |outlen| random bytes and stores them in |out|. It will | ||
| * using the given |drbg| to generate the bytes. |
|
Ping @kroeckx. Looks like this has the necessary approvals to be pushed? |
|
Conflicts? |
|
@kroeckx could you please rebase to resolve the conflicts? @mattcaswell this PR is ready except for the conflicts. Is it ok to move it from the 'Post 1.1.1' to the '1.1.1.' milestone? |
@mspncp by all means merge it if it is ready. The milestone should not be seen as a blocker for that. The milestone is more about stuff which must be merged before 1.1.1. |
Reviewed-by: Paul Dale <[email protected]> Reviewed-by: Matthias St. Pierre <[email protected]> (Merged from #4752)
|
Squashed and rebased, resolving the trivial conflicts. Closing, thanks! |
No description provided.