|
purify
C++ Purify implementation with native circuit and BPP support
|
Little-endian fixed-width unsigned integer with simple arithmetic utilities. More...
#include <numeric.hpp>
Public Member Functions | |
| bool | is_zero () const |
| Returns true when all limbs are zero. | |
| int | compare (const BigUInt &other) const |
| Compares two fixed-width integers using unsigned ordering. | |
| bool | operator== (const BigUInt &other) const |
| bool | operator!= (const BigUInt &other) const |
| bool | operator< (const BigUInt &other) const |
| bool | operator>= (const BigUInt &other) const |
| bool | try_add_small (std::uint32_t value) |
| Adds a small unsigned value in place when the result fits. | |
| void | add_small (std::uint32_t value) |
| Adds a small unsigned value in place. | |
| bool | try_mul_small (std::uint32_t value) |
| Multiplies by a small unsigned value in place when the result fits. | |
| void | mul_small (std::uint32_t value) |
| Multiplies by a small unsigned value in place. | |
| bool | try_add_assign (const BigUInt &other) |
| Adds another fixed-width integer when the result fits. | |
| void | add_assign (const BigUInt &other) |
| Adds another fixed-width integer in place. | |
| bool | try_sub_assign (const BigUInt &other) |
| Subtracts another fixed-width integer when the minuend is large enough. | |
| void | sub_assign (const BigUInt &other) |
| Subtracts another fixed-width integer in place. | |
| std::size_t | bit_length () const |
| Returns the index of the highest set bit plus one. | |
| bool | bit (std::size_t index) const |
| Returns the bit at the given little-endian bit index. | |
| bool | try_set_bit (std::size_t index) |
| Sets the bit at the given little-endian bit index when it is in range. | |
| void | set_bit (std::size_t index) |
| Sets the bit at the given little-endian bit index. | |
| BigUInt | shifted_left (std::size_t bits) const |
| Returns a copy shifted left by the requested bit count. | |
| BigUInt | shifted_right (std::size_t bits) const |
| Returns a copy shifted right by the requested bit count. | |
| void | shift_right_one () |
| Shifts the value right by one bit in place. | |
| void | mask_bits (std::size_t bits) |
| Clears all bits above the requested width. | |
| std::uint32_t | divmod_small (std::uint32_t divisor) |
| Divides by a small unsigned value in place and returns the remainder. | |
| std::array< unsigned char, Words *8 > | to_bytes_be () const |
| Serializes the value to a fixed-width big-endian byte array. | |
| std::string | to_hex () const |
| Formats the value as lowercase hexadecimal without leading zero padding. | |
| std::string | to_decimal () const |
| Formats the value as an unsigned decimal string. | |
Static Public Member Functions | |
| static BigUInt | zero () |
| Returns the additive identity. | |
| static BigUInt | one () |
| Returns the multiplicative identity. | |
| static BigUInt | from_u64 (std::uint64_t value) |
| Constructs a value from a single 64-bit limb. | |
| static BigUInt | from_bytes_be (const unsigned char *data, std::size_t size) |
| Parses a big-endian byte string into the fixed-width integer. | |
| static Result< BigUInt > | try_from_hex (std::string_view hex) |
Parses a hexadecimal string, ignoring optional 0x and whitespace. | |
| static BigUInt | from_hex (std::string_view hex) |
| Parses a hexadecimal string with the precondition that the value fits exactly. | |
Data Fields | |
| std::array< std::uint64_t, Words > | limbs {} |
| Words | Number of 64-bit limbs stored in the integer. |
Definition at line 200 of file numeric.hpp.
|
inline |
Precondition: the sum fits in the fixed-width representation.
Definition at line 431 of file numeric.hpp.
References purify::BigUInt< Words >::try_add_assign().
|
inline |
Precondition: the sum fits in the fixed-width representation.
Definition at line 361 of file numeric.hpp.
References purify::BigUInt< Words >::try_add_small().
Referenced by purify::BigUInt< Words >::from_bytes_be().
|
inline |
Definition at line 489 of file numeric.hpp.
References purify::BigUInt< Words >::limbs.
|
inline |
Definition at line 474 of file numeric.hpp.
References purify::detail::bit_length_u64(), and purify::BigUInt< Words >::limbs.
Referenced by purify::circuit_main(), purify::key_to_bits(), purify::random_below(), and purify::try_divmod_same().
|
inline |
Definition at line 301 of file numeric.hpp.
References purify::BigUInt< Words >::limbs.
Referenced by purify::BigUInt< Words >::operator<(), purify::BigUInt< Words >::operator>=(), purify::random_below(), and purify::try_divmod_same().
|
inline |
Definition at line 604 of file numeric.hpp.
References purify::detail::UInt128::divmod_u32(), purify::detail::UInt128::from_words(), and purify::BigUInt< Words >::limbs.
Referenced by purify::BigUInt< Words >::to_decimal().
|
inlinestatic |
Definition at line 235 of file numeric.hpp.
References purify::BigUInt< Words >::add_small(), purify::BigUInt< Words >::limbs, and purify::BigUInt< Words >::mul_small().
|
inlinestatic |
Call try_from_hex() when the input may be user-controlled.
Definition at line 280 of file numeric.hpp.
References purify::Expected< T, E >::has_value(), and purify::BigUInt< Words >::try_from_hex().
|
inlinestatic |
Definition at line 224 of file numeric.hpp.
References purify::BigUInt< Words >::limbs.
|
inline |
Definition at line 287 of file numeric.hpp.
References purify::BigUInt< Words >::limbs.
Referenced by purify::random_below(), purify::BigUInt< Words >::to_decimal(), and purify::try_divmod_same().
|
inline |
Definition at line 586 of file numeric.hpp.
References purify::BigUInt< Words >::limbs.
Referenced by purify::random_below().
|
inline |
Precondition: the product fits in the fixed-width representation.
Definition at line 395 of file numeric.hpp.
References purify::BigUInt< Words >::try_mul_small().
Referenced by purify::BigUInt< Words >::from_bytes_be().
|
inlinestatic |
Definition at line 213 of file numeric.hpp.
References purify::BigUInt< Words >::limbs.
|
inline |
Definition at line 322 of file numeric.hpp.
|
inline |
Definition at line 326 of file numeric.hpp.
References purify::BigUInt< Words >::compare().
|
inline |
Definition at line 318 of file numeric.hpp.
References purify::BigUInt< Words >::limbs.
|
inline |
Definition at line 330 of file numeric.hpp.
References purify::BigUInt< Words >::compare().
|
inline |
Precondition: index < Words * 64.
Definition at line 522 of file numeric.hpp.
References purify::BigUInt< Words >::try_set_bit().
|
inline |
Definition at line 574 of file numeric.hpp.
References purify::BigUInt< Words >::limbs.
Referenced by purify::try_divmod_same().
|
inline |
Definition at line 529 of file numeric.hpp.
References purify::BigUInt< Words >::limbs.
Referenced by purify::try_divmod_same().
|
inline |
Definition at line 552 of file numeric.hpp.
References purify::BigUInt< Words >::limbs.
|
inline |
Precondition: *this >= other.
Definition at line 467 of file numeric.hpp.
References purify::BigUInt< Words >::try_sub_assign().
Referenced by purify::capi_detail::secp256k1_order_minus_one().
|
inline |
Definition at line 621 of file numeric.hpp.
References purify::BigUInt< Words >::limbs.
Referenced by purify::derive_bip340_key(), purify::eval(), purify::puresign_plusplus::PublicKey::serialize(), purify::puresign::PublicKey::serialize(), purify::BigUInt< Words >::to_hex(), purify::FieldElement::try_from_uint256(), and purify::capi_detail::write_uint512().
|
inline |
Definition at line 658 of file numeric.hpp.
References purify::BigUInt< Words >::divmod_small(), and purify::BigUInt< Words >::is_zero().
Referenced by purify::FieldElement::to_decimal().
|
inline |
Definition at line 638 of file numeric.hpp.
References purify::BigUInt< Words >::to_bytes_be().
Referenced by purify::FieldElement::to_hex().
|
inline |
Definition at line 402 of file numeric.hpp.
References purify::BigUInt< Words >::limbs.
Referenced by purify::BigUInt< Words >::add_assign().
|
inline |
Definition at line 335 of file numeric.hpp.
References purify::BigUInt< Words >::limbs.
Referenced by purify::BigUInt< Words >::add_small(), and purify::BigUInt< Words >::try_from_hex().
|
inlinestatic |
Definition at line 249 of file numeric.hpp.
References purify::InvalidHex, purify::Overflow, purify::BigUInt< Words >::try_add_small(), purify::BigUInt< Words >::try_mul_small(), and purify::unexpected_error().
Referenced by purify::BigUInt< Words >::from_hex().
|
inline |
Definition at line 368 of file numeric.hpp.
References purify::detail::UInt128::add_u64(), purify::detail::UInt128::high64(), purify::BigUInt< Words >::limbs, purify::detail::UInt128::low64(), and purify::detail::UInt128::mul_u64().
Referenced by purify::BigUInt< Words >::mul_small(), and purify::BigUInt< Words >::try_from_hex().
|
inline |
Definition at line 503 of file numeric.hpp.
References purify::BigUInt< Words >::limbs.
Referenced by purify::BigUInt< Words >::set_bit(), and purify::try_divmod_same().
|
inline |
Definition at line 438 of file numeric.hpp.
References purify::BigUInt< Words >::limbs.
Referenced by purify::BigUInt< Words >::sub_assign(), and purify::try_divmod_same().
|
inlinestatic |
Definition at line 204 of file numeric.hpp.
References purify::BigUInt< Words >::limbs.
| std::array<std::uint64_t, Words> purify::BigUInt< Words >::limbs {} |
Definition at line 201 of file numeric.hpp.
Referenced by purify::BigUInt< Words >::bit(), purify::BigUInt< Words >::bit_length(), purify::BigUInt< Words >::compare(), purify::BigUInt< Words >::divmod_small(), purify::BigUInt< Words >::from_bytes_be(), purify::BigUInt< Words >::from_u64(), purify::is_valid_public_key(), purify::is_valid_secret_key(), purify::BigUInt< Words >::is_zero(), purify::key_to_bits(), purify::BigUInt< Words >::mask_bits(), purify::multiply(), purify::BigUInt< Words >::one(), purify::BigUInt< Words >::operator==(), purify::pack_public(), purify::FieldElement::pow(), purify::BigUInt< Words >::shift_right_one(), purify::BigUInt< Words >::shifted_left(), purify::BigUInt< Words >::shifted_right(), purify::BigUInt< Words >::to_bytes_be(), purify::BigUInt< Words >::try_add_assign(), purify::BigUInt< Words >::try_add_small(), purify::try_divmod_same(), purify::BigUInt< Words >::try_mul_small(), purify::try_narrow(), purify::BigUInt< Words >::try_set_bit(), purify::BigUInt< Words >::try_sub_assign(), purify::unpack_public(), purify::unpack_secret(), purify::widen(), and purify::BigUInt< Words >::zero().