Skip to content
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

Fixed range of random produced in BN_is_prime_fasttest_ex() #6547

Closed
wants to merge 1 commit into from

Conversation

slontis
Copy link
Member

@slontis slontis commented Jun 21, 2018

According to the FIPS 186-4 C.3.1 (4.1) The range is expected to be 1 < b < w-1.
It was using 1 <= b < w (which is wrong by 1 on both ends).
This is because rand_range(n) returns 0 <= b < w-1 (and then it added 1).
So instead use 2 + rand_range(w-3).
There is also a check for the number '3' added that early exits (in the case where trial_divisions is not used).
Also removed a redundant check for is_zero after subtracting 1 as it already checks <= 1

Checklist
  • tests are added or updated

… rand < w-1. It was using 1<= rand < w (which is wrong by 1 on both ends)
@levitte levitte added the approval: review pending This pull request needs review by a committer label Jun 21, 2018
@levitte
Copy link
Member

levitte commented Jun 21, 2018

Should this be backported to 1.1.0?

@paulidale
Copy link
Contributor

The probability of hitting either of the end points is low: 2^(1-w). I think hitting the low end could reject a legitimate prime, which would be a slow down, but would otherwise be harmless. I'm not sure about the high end -- I'd need to check for being even and if not work through the mathematics.

If this is back ported to 1.1.0, it should also go to 1.0.2. I don't see a need for either but would be easily convinced otherwise.

@richsalz
Copy link
Contributor

We don't claim FIPS compliance, so this seems like just a bugfix for master.

@richsalz richsalz added approval: done This pull request has the required number of approvals and removed approval: review pending This pull request needs review by a committer labels Jun 21, 2018
@paulidale
Copy link
Contributor

I'm happy with just master. Looking more deeply, it seems that the only result at the limits is that a prime number can be declared not prime which shouldn't be harmful.

@paulidale
Copy link
Contributor

Merged to master only.

@paulidale paulidale closed this Jun 21, 2018
levitte pushed a commit that referenced this pull request Jun 21, 2018
… rand < w-1. It was using 1<= rand < w (which is wrong by 1 on both ends)

Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from #6547)
@paulidale
Copy link
Contributor

Thanks!

@slontis slontis deleted the BN_is_prime-range-fix branch June 21, 2018 23:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approval: done This pull request has the required number of approvals
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants