Open
Conversation
b863ee5 to
3dfafdd
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces a new BigInt::signum() API and migrates a broad set of call sites across the library, tests, and fuzzers from the legacy is_positive()/is_negative()/is_nonzero() predicates to signum()-based checks. This helps make sign handling less ambiguous (notably around is_positive() historically including zero) and centralizes sign/zero interpretation.
Changes:
- Add
BigInt::signum()and deprecateis_nonzero(),is_negative(), andis_positive()in favor ofsignum()comparisons. - Update numerous math/number theory, EC, RSA, X.509, FFI, codec, tests, and fuzzers to use
signum()andis_zero(). - Tighten/clarify several argument checks and assertions by switching to explicit signum comparisons.
Reviewed changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/lib/math/bigint/bigint.h | Adds signum(), updates operator!, deprecates sign helpers in favor of signum() |
| src/lib/math/bigint/bigint.cpp | Replaces sign checks in comparisons/conversions/reductions with signum() |
| src/lib/math/bigint/divide.cpp | Uses signum() for divisor/operand sign checks and nonzero checks |
| src/lib/math/bigint/big_ops2.cpp | Migrates modular ops and shifts to signum()-based sign/zero handling |
| src/lib/math/bigint/big_ops3.cpp | Migrates division/modulo/shift sign checks to signum() |
| src/lib/math/bigint/big_code.cpp | Uses signum() for string encoding sign handling and positivity checks |
| src/lib/math/bigint/big_rand.cpp | Uses signum() in random integer range validation |
| src/lib/math/numbertheory/barrett.cpp | Updates modulus/argument validation and CT precheck positivity to signum() |
| src/lib/math/numbertheory/primality.cpp | Uses signum() for argument validation and sign flips |
| src/lib/math/numbertheory/numthry.cpp | Uses signum() for modulus negativity checks in power_mod |
| src/lib/math/numbertheory/monty_exp.cpp | Uses signum() to validate multi-exponentiation exponents |
| src/lib/math/numbertheory/mod_inv.cpp | Refactors inverse-mod argument validation and internal nonzero/negative checks to signum() |
| src/lib/math/numbertheory/make_prm.cpp | Migrates coprime validation to signum() checks |
| src/lib/pubkey/rsa/rsa.cpp | Uses signum() for RSA parameter validation |
| src/lib/pubkey/ec_group/ec_group.cpp | Uses signum() for EC parameter validation and clarifies A/B/order constraints |
| src/lib/pubkey/ec_group/ec_apoint.cpp | Uses signum() to validate affine coordinates are non-negative |
| src/lib/pubkey/ec_group/legacy_ec_point/point_mul.cpp | Uses signum() for scalar sign validation and sign comparison |
| src/lib/pubkey/ec_group/legacy_ec_point/ec_point.cpp | Uses signum() for scalar sign in mul; updates internal assert to signum() |
| src/lib/x509/x509cert.cpp | Uses signum() to record serial sign |
| src/lib/asn1/ber_dec.cpp | Uses signum() to reject negative decoded integers |
| src/lib/ffi/ffi_mp.cpp | Updates FFI sign queries to use signum() |
| src/lib/codec/base58/base58.cpp | Switches loop condition to !is_zero() |
| src/tests/test_bigint.cpp | Updates test preconditions to use signum() for sign checks |
| src/fuzzer/invert.cpp | Uses !is_zero() and signum() for loop and sign normalization |
| src/fuzzer/bn_cmp.cpp | Uses signum() assertions instead of deprecated sign/zero helpers |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
3dfafdd to
404031f
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.
No description provided.