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

Allow custom MSB setting in generated primes #69

Merged
merged 1 commit into from
Jan 27, 2025

Conversation

fjarri
Copy link
Member

@fjarri fjarri commented Jan 23, 2025

In the RSA application one needs two primes which, when multiplied, produce a number with a fixed bit length. This can be achieved by requiring two most significant bits to be set on each. The current code just sets the MSB by default, and setting the second one requires writing a custom wrapper over SmallPrimesSieveFactory.

This PR attempts to provide a simpler pathway for most common bit-setting cases: no bits set (primes generated up to the chosen bit length), MSB set, and two MSBs set. random_odd_uint() and SmallPrimesSieveFactory constructors get an additional SetBits parameter.

An RSA application would have to use the new functionality by calling

    sieve_and_find(
        rng,
        SmallPrimesSieveFactory::new(bit_length, SetBits::TwoMsb),
        is_prime_with_rng,
    )

The default currently remains SetBits::Msb, but perhaps it should be changed to SetBits::None.

Copy link

codecov bot commented Jan 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.46%. Comparing base (838c157) to head (9dfe54d).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #69      +/-   ##
==========================================
+ Coverage   99.44%   99.46%   +0.01%     
==========================================
  Files          10       10              
  Lines        1449     1491      +42     
==========================================
+ Hits         1441     1483      +42     
  Misses          8        8              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@dvdplm dvdplm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm so far

src/hazmat/sieve.rs Outdated Show resolved Hide resolved
src/hazmat/sieve.rs Outdated Show resolved Hide resolved
src/hazmat/sieve.rs Outdated Show resolved Hide resolved
src/hazmat/sieve.rs Outdated Show resolved Hide resolved
@fjarri fjarri marked this pull request as ready for review January 24, 2025 20:04
Copy link
Contributor

@dvdplm dvdplm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

One question I have is how this jives with #62. In my head this PR can go in straight away and we should not let #62 be a blocker (it will break semver and require a 0.7 release anyway).

@fjarri fjarri self-assigned this Jan 27, 2025
@fjarri
Copy link
Member Author

fjarri commented Jan 27, 2025

Sure, we can get this in first.

@fjarri fjarri merged commit 4ad6e53 into entropyxyz:master Jan 27, 2025
10 checks passed
@fjarri fjarri deleted the two-msb branch January 27, 2025 22:29
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.

3 participants