Skip to content

Add missing FIPS 186-5 GCD check in Lucas probable prime test#5626

Open
Shounak611 wants to merge 1 commit into
randombit:masterfrom
Shounak611:fix-fips1865-lucas-gcd-check
Open

Add missing FIPS 186-5 GCD check in Lucas probable prime test#5626
Shounak611 wants to merge 1 commit into
randombit:masterfrom
Shounak611:fix-fips1865-lucas-gcd-check

Conversation

@Shounak611

Copy link
Copy Markdown

Implements the additional FIPS 186-5 B.3.3 check:

gcd(C, (1-D)/4) == 1

inside is_lucas_probable_prime().

This aligns the implementation with the updated FIPS 186-5 specification.

@randombit

Copy link
Copy Markdown
Owner

I would at the very least want some testcases that actually hits this. (1-D)/4) is going to just be 1,2,3,... afaict this is basically just testing (in a somewhat expensive way) that Cdoesn't have any very small factors. And I'm pretty sure our existing check that jacobi(C,D) != 0 catches this anyway.

If needed, it would be much more effective to precompute 2*3*5*... up to some reasonable size then gcd C with that. That GCD would eliminate strictly more values of C than this check would.

@Shounak611

Copy link
Copy Markdown
Author

I’ll verify whether the additional GCD check actually rejects any cases not already handled by the existing Jacobi condition and try to produce concrete examples/benchmarks. If it turns out to be redundant or not materially beneficial, I’ll remove the change from the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants