-
Notifications
You must be signed in to change notification settings - Fork 211
Fix #103 #105
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
Conversation
I've just tested this on Windows and it's horribly slow... it's a bit better if I change the |
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.
Looks ok, have tested that urandom works as expected.
Needs another level of nesting for that #ifdef
bn_mp_rand.c
Outdated
} | ||
#endif /* WIN32 */ | ||
|
||
#if !defined(MP_WIN_CSP) && defined(__linux__) && defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 25) |
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.
This fails to build on OSX (clang 9.0.0)
bn_mp_rand.c:72:78: error: function-like macro '__GLIBC_PREREQ' is not defined
#if !defined(MP_WIN_CSP) && defined(__linux__) && defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 25)
I guess it needs to be
+#if !defined(MP_WIN_CSP) && defined(__linux__) && defined(__GLIBC_PREREQ)
+#if __GLIBC_PREREQ(2, 25)
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.
Yeah, I've seen that as well on windows but I'm busy right now, will update 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.
done
could someone please have a look&try? I'd like to prepare a new release asap |
int ret; | ||
do { | ||
ret = getrandom(p, sizeof(*p), 0); | ||
} while((ret == -1) && (errno == EINTR)); |
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.
- return ret;
+ if (ret == sizeof(*p))
+ return MP_OKAY;
+ return -1;
otherwise you do this and fallback to /dev/urandom because getrandom returns the number of random bytes.
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.
done
bn_mp_rand.c
Outdated
fd = open(MP_DEV_URANDOM, O_RDONLY); | ||
} while((fd == -1) && (errno == EINTR)); | ||
if (fd == -1) return -1; | ||
r = read(fd, p, sizeof(*p)); |
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.
this read() needs a do while loop which will retry for errno==EINTR just like open.
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.
- r = read(fd, p, sizeof(*p));
+ do {
+ r = read(fd, p, sizeof(*p));
+ } while((r == -1) && (errno == EINTR));
like that?
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.
yes, I think this is good now.
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.
done
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.
just the two things from my point of view :)
8f6b2ba
to
3d672de
Compare
This fixes #103
@mkj can you please re-review? |
Sorry won't be able to look at this until Saturday |
Perfectly fine! |
I've re-factored the way
mp_rand()
gets its random values.There are now 4 big different cases
arc4random()
for *BSDgetrandom()
for linux with new glibc/dev/urandom
for linux with old glibc and all other platformsSome of the code is based on
rng_get_bytes()
of libtomcrypt.This fixes #103