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

Bugfixes to fp_prime_random_ex [reboot] #39

Merged
merged 2 commits into from
Sep 19, 2024

Conversation

levitte
Copy link
Collaborator

@levitte levitte commented Sep 18, 2024

This branch contains some fixes to fp_prime_random_ex. See the specific commits. Specifically:

  • Avoid generating primes with MSB=0x80 when size is a multiple of 8
  • Avoid usage of malloc()

This is a reboot of #4

This fixes #32

@levitte
Copy link
Collaborator Author

levitte commented Sep 18, 2024

Differences from #4:

  • squashed obvious fixup commits into their original
  • dropped the 't' removal changes, as 't' is actually used now
  • fixed some comments
  • fixed the placement of DIGIT_SHIFT

@sjaeckel
Copy link
Member

TBH I'm not sure what we should do with stuff like that! We have advanced a lot more in LTM, especially with the work done by @minad and @czurnieden and all the others I forgot. The original plan was to merge LTM and TFM into one library, but that never took place because reasons.

I think this API is a good example, the LTM counterpart is mp_prime_rand.c. Here we call fp_isprime_ex(), there we call mp_prime_is_prime().

The effort of @czurnieden that went into the prime checking and the complexity this now has, I don't think we should even think of porting this over to TFM. But then we're talking about a critical part FMU and what is done in TFM is just not OK.

But maybe this discussion also belongs somewhere else and we should simply merge this stuff as is...

@levitte
Copy link
Collaborator Author

levitte commented Sep 18, 2024

I haven't been along for those discussions, and frankly didn't look at all at LTM to compare. I only looked at these changes, and they make sense to me.

This is the only instance of dynamic memory in TFM. It can be avoided
by writing directly into the dp[] array, and it does not violate C
aliasing rules which specifically allow access on objects through char*.
It does not matter the platform-specific representation of digits since
we are filling them with random data anyway.
There are potential issues with weird platforms were not
all bits of a fp_digit are used (padding bits), plus it
makes it harder to do reproducible testing of algorithms.
Copy link
Member

@sjaeckel sjaeckel left a comment

Choose a reason for hiding this comment

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

Thanks for picking up this PR and doing the work, you're right, it should be merged.

src/headers/tfm.h Show resolved Hide resolved
@sjaeckel sjaeckel merged commit 5602f64 into libtom:develop Sep 19, 2024
63 checks passed
@levitte levitte deleted the bugfix_gen_prime branch September 19, 2024 15:43
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