|
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.
|
inline |
Precondition: the sum fits in the fixed-width representation.
Definition at line 361 of file numeric.hpp.
Referenced by purify::BigUInt< 4 >::from_bytes_be().
|
inline |
Definition at line 489 of file numeric.hpp.
|
inline |
Definition at line 474 of file numeric.hpp.
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.
Referenced by purify::BigUInt< 4 >::operator<(), purify::BigUInt< 4 >::operator>=(), purify::random_below(), and purify::try_divmod_same().
|
inline |
Definition at line 604 of file numeric.hpp.
Referenced by purify::BigUInt< 4 >::to_decimal().
|
inlinestatic |
Definition at line 235 of file numeric.hpp.
|
inlinestatic |
Call try_from_hex() when the input may be user-controlled.
Definition at line 280 of file numeric.hpp.
|
inlinestatic |
Definition at line 224 of file numeric.hpp.
|
inline |
Definition at line 287 of file numeric.hpp.
Referenced by purify::random_below(), purify::BigUInt< 4 >::to_decimal(), and purify::try_divmod_same().
|
inline |
Definition at line 586 of file numeric.hpp.
Referenced by purify::random_below().
|
inline |
Precondition: the product fits in the fixed-width representation.
Definition at line 395 of file numeric.hpp.
Referenced by purify::BigUInt< 4 >::from_bytes_be().
|
inlinestatic |
Definition at line 213 of file numeric.hpp.
|
inline |
Definition at line 322 of file numeric.hpp.
|
inline |
Definition at line 326 of file numeric.hpp.
|
inline |
Definition at line 318 of file numeric.hpp.
|
inline |
Definition at line 330 of file numeric.hpp.
|
inline |
Precondition: index < Words * 64.
Definition at line 522 of file numeric.hpp.
|
inline |
Definition at line 574 of file numeric.hpp.
Referenced by purify::try_divmod_same().
|
inline |
Definition at line 529 of file numeric.hpp.
Referenced by purify::try_divmod_same().
|
inline |
Definition at line 552 of file numeric.hpp.
|
inline |
Precondition: *this >= other.
Definition at line 467 of file numeric.hpp.
Referenced by purify::capi_detail::secp256k1_order_minus_one().
|
inline |
Definition at line 621 of file numeric.hpp.
Referenced by purify::derive_bip340_key(), purify::eval(), purify::BigUInt< 4 >::to_hex(), purify::FieldElement::try_from_uint256(), and purify::capi_detail::write_uint512().
|
inline |
Definition at line 658 of file numeric.hpp.
Referenced by purify::FieldElement::to_decimal().
|
inline |
Definition at line 638 of file numeric.hpp.
Referenced by purify::FieldElement::to_hex().
|
inline |
Definition at line 402 of file numeric.hpp.
Referenced by purify::BigUInt< 4 >::add_assign().
|
inline |
Definition at line 335 of file numeric.hpp.
Referenced by purify::BigUInt< 4 >::add_small(), and purify::BigUInt< 4 >::try_from_hex().
|
inlinestatic |
Definition at line 249 of file numeric.hpp.
Referenced by purify::BigUInt< 4 >::from_hex().
|
inline |
Definition at line 368 of file numeric.hpp.
Referenced by purify::BigUInt< 4 >::mul_small(), and purify::BigUInt< 4 >::try_from_hex().
|
inline |
Definition at line 503 of file numeric.hpp.
Referenced by purify::BigUInt< 4 >::set_bit(), and purify::try_divmod_same().
|
inline |
Definition at line 438 of file numeric.hpp.
Referenced by purify::BigUInt< 4 >::sub_assign(), and purify::try_divmod_same().
|
inlinestatic |
Definition at line 204 of file numeric.hpp.
| std::array<std::uint64_t, Words> purify::BigUInt< Words >::limbs {} |
Definition at line 201 of file numeric.hpp.
Referenced by purify::BigUInt< 4 >::compare(), purify::BigUInt< 4 >::from_bytes_be(), purify::BigUInt< 4 >::from_u64(), purify::is_valid_public_key(), purify::is_valid_secret_key(), purify::key_to_bits(), purify::EllipticCurve::mul(), purify::EllipticCurve::mul_secret_affine(), purify::multiply(), purify::BigUInt< 4 >::one(), purify::BigUInt< 4 >::operator==(), purify::pack_public(), purify::FieldElement::pow(), purify::BigUInt< 4 >::shifted_left(), purify::BigUInt< 4 >::shifted_right(), purify::BigUInt< 4 >::try_add_assign(), purify::BigUInt< 4 >::try_add_small(), purify::try_divmod_same(), purify::BigUInt< 4 >::try_mul_small(), purify::try_narrow(), purify::BigUInt< 4 >::try_sub_assign(), purify::unpack_public(), purify::unpack_secret(), purify::widen(), and purify::BigUInt< 4 >::zero().