Skip to content

Add BigInt::signum#5519

Open
randombit wants to merge 1 commit intomasterfrom
jack/bigint-signum
Open

Add BigInt::signum#5519
randombit wants to merge 1 commit intomasterfrom
jack/bigint-signum

Conversation

@randombit
Copy link
Copy Markdown
Owner

No description provided.

@randombit randombit force-pushed the jack/bigint-signum branch 3 times, most recently from b863ee5 to 3dfafdd Compare April 4, 2026 00:13
@randombit randombit requested a review from Copilot April 4, 2026 00:28
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 deprecate is_nonzero(), is_negative(), and is_positive() in favor of signum() comparisons.
  • Update numerous math/number theory, EC, RSA, X.509, FFI, codec, tests, and fuzzers to use signum() and is_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.

@randombit randombit force-pushed the jack/bigint-signum branch from 3dfafdd to 404031f Compare April 4, 2026 00:56
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