Repository navigation
Avoid using BigInt for any DL arithmetic - #6135
Merged
Merged
Conversation
This allows internal code outside of dl_group.cpp to use the group's precomputed values. DL_Group::_data() returns the shared group data.
An internal type for integers modulo the prime p of a DL group, held in Montgomery form at a fixed length. Unlike arithmetic using BigInt, the sizes of intermediate values do not depend on their values. This does not require the group to have a known subgroup order, since SRP6 groups and ElGamal keys loaded via FFI do not have one.
Decryption blinding now uses DL_PrivateKey_Exponentiation, which computes b^x for the private key in Montgomery form with the same squaring and periodic refresh scheme as Blinder. DH will use the same helper.
Key agreement now uses DL_PrivateKey_Exponentiation, so DH no longer uses Blinder or Barrett reduction.
An internal type for integers modulo the prime order q of a DL group, held in Montgomery form at a fixed length, analogous to DL_Element. Inversion uses Fermat's little theorem, avoiding the BigInt range checks of inverse_mod_public_prime. The reduction of g^k mod p modulo q does a fixed amount of work, unlike ct_modulo which depends on the word length of its input. This is only used by DSA, and can be removed along with it.
This removes the last in-tree users of the deprecated DL_Group mod q arithmetic and multi_exponentiate.
Computing these for every group with a known q made constructing groups such as ffdhe/ietf/4096, where q is almost as long as p, 10-16% slower. Only DSA, via DL_Scalar, needs fast arithmetic modulo q, and DSA requires q of at most 256 bits. For larger q the deprecated DL_Group::multiply_mod_q and square_mod_q use ct_modulo instead. Nothing in the library calls them.
These are no longer used within the library. Applications should not need to do arithmetic on DL groups directly.
randombit
force-pushed
the
jack/dl-element
branch
from
November 16, 2026 22:41
da0b4d0 to
b75e3c5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add new (internal) DL_Element and DL_Scalar types which wrap
Montgomery_Int, and use them in DH, ElGamal, and DSA