|
Barretenberg
The ZK-SNARK library at the core of Aztec
|
General class for prime fields see Prime field documentation["field documentation"] for general implementation reference. More...
#include <field_declarations.hpp>
Classes | |
| struct | wide_array |
| struct | wnaf_table |
Public Types | |
| using | View = field |
| using | CoefficientAccumulator = field |
| using | Params = Params_ |
| using | in_buf = const uint8_t * |
| using | vec_in_buf = const uint8_t * |
| using | out_buf = uint8_t * |
| using | vec_out_buf = uint8_t ** |
Public Member Functions | |
| field ()=default | |
| constexpr | field (const numeric::uint256_t &input) noexcept |
| constexpr | field (const uint128_t &input) noexcept |
| constexpr | field (const unsigned long input) noexcept |
| constexpr | field (const unsigned int input) noexcept |
| constexpr | field (const unsigned long long input) noexcept |
| constexpr | field (const int input) noexcept |
| constexpr | field (const uint64_t a, const uint64_t b, const uint64_t c, const uint64_t d) noexcept |
| cast four uint64_t as a field | |
| constexpr | field (const uint512_t &input) noexcept |
| Convert a 512-bit big integer into a field element. | |
| constexpr | field (std::string input) noexcept |
| constexpr | operator bool () const |
| constexpr | operator uint8_t () const |
| constexpr | operator uint16_t () const |
| constexpr | operator uint32_t () const |
| constexpr | operator uint64_t () const |
| constexpr | operator uint128_t () const |
| constexpr | operator uint256_t () const noexcept |
| constexpr uint256_t | uint256_t_no_montgomery_conversion () const noexcept |
| constexpr | field (const field &other) noexcept=default |
| constexpr | field (field &&other) noexcept=default |
| constexpr field & | operator= (const field &other) &noexcept=default |
| constexpr field & | operator= (field &&other) &noexcept=default |
| constexpr | ~field () noexcept=default |
| BB_INLINE constexpr field | operator* (const field &other) const noexcept |
| BB_INLINE constexpr field | operator+ (const field &other) const noexcept |
| BB_INLINE constexpr field | operator- (const field &other) const noexcept |
| BB_INLINE constexpr field | operator- () const noexcept |
| constexpr field | operator/ (const field &other) const noexcept |
| BB_INLINE constexpr field | operator++ () noexcept |
| BB_INLINE constexpr field | operator++ (int) noexcept |
| BB_INLINE constexpr field & | operator*= (const field &other) &noexcept |
| BB_INLINE constexpr field & | operator+= (const field &other) &noexcept |
| BB_INLINE constexpr field & | operator-= (const field &other) &noexcept |
| constexpr field & | operator/= (const field &other) &noexcept |
| BB_INLINE constexpr bool | operator> (const field &other) const noexcept |
| Greater-than operator. | |
| BB_INLINE constexpr bool | operator< (const field &other) const noexcept |
| Less-than operator. | |
| BB_INLINE constexpr bool | operator== (const field &other) const noexcept |
| BB_INLINE constexpr bool | operator!= (const field &other) const noexcept |
| BB_INLINE constexpr field | to_montgomery_form () const noexcept |
| BB_INLINE constexpr field | from_montgomery_form () const noexcept |
| BB_INLINE constexpr field | to_montgomery_form_reduced () const noexcept |
| BB_INLINE constexpr field | from_montgomery_form_reduced () const noexcept |
| BB_INLINE constexpr field | sqr () const noexcept |
| BB_INLINE constexpr void | self_sqr () &noexcept |
| BB_INLINE constexpr field | pow (const uint256_t &exponent) const noexcept |
| BB_INLINE constexpr field | pow (uint64_t exponent) const noexcept |
| constexpr field | invert () const noexcept |
| constexpr std::pair< bool, field > | sqrt () const noexcept |
| Compute square root of the field element. | |
| constexpr std::pair< bool, field > | sqrt () const noexcept |
| BB_INLINE constexpr void | self_neg () &noexcept |
| BB_INLINE constexpr void | self_to_montgomery_form () &noexcept |
| BB_INLINE constexpr void | self_from_montgomery_form () &noexcept |
| BB_INLINE constexpr void | self_to_montgomery_form_reduced () &noexcept |
| BB_INLINE constexpr void | self_from_montgomery_form_reduced () &noexcept |
| BB_INLINE constexpr void | self_conditional_negate (uint64_t predicate) &noexcept |
| BB_INLINE constexpr field | reduce_once () const noexcept |
| BB_INLINE constexpr void | self_reduce_once () &noexcept |
| BB_INLINE constexpr void | self_set_msb () &noexcept |
| BB_INLINE constexpr bool | is_msb_set () const noexcept |
| BB_INLINE constexpr uint64_t | is_msb_set_word () const noexcept |
| BB_INLINE constexpr bool | is_zero () const noexcept |
| BB_INLINE std::vector< uint8_t > | to_buffer () const |
| BB_INLINE constexpr wide_array | mul_512 (const field &other) const noexcept |
| BB_INLINE constexpr wide_array | sqr_512 () const noexcept |
| BB_INLINE constexpr field | conditionally_subtract_from_double_modulus (const uint64_t predicate) const noexcept |
| void | msgpack_pack (auto &packer) const |
| void | msgpack_unpack (auto o) |
| void | msgpack_schema (auto &packer) const |
| BB_INLINE constexpr field | reduce () const noexcept |
| reduce once, i.e., if the value is bigger than the modulus, subtract off the modulus once. | |
| BB_INLINE constexpr field | add (const field &other) const noexcept |
| BB_INLINE constexpr field | subtract (const field &other) const noexcept |
| BB_INLINE constexpr field | montgomery_mul (const field &other) const noexcept |
| BB_INLINE constexpr field | montgomery_mul_big (const field &other) const noexcept |
| Mongtomery multiplication for moduli > 2²⁵⁴ | |
| BB_INLINE constexpr field | montgomery_square () const noexcept |
| Squaring via a variant of the Montgomery algorithm, where we roughly take advantage of the repeated terms in the expansion. | |
| constexpr field | tonelli_shanks_sqrt () const noexcept |
| Implements an optimized variant of Tonelli-Shanks via lookup tables. Algorithm taken from https://cr.yp.to/papers/sqroot-20011123-retypeset20220327.pdf "FASTER SQUARE ROOTS IN ANNOYING FINITE FIELDS" by D. Bernstein Page 5 "Accelerated Discrete Logarithm". | |
Static Public Member Functions | |
| static constexpr field | cube_root_of_unity () |
| static constexpr field | zero () |
| static constexpr field | neg_one () |
| static constexpr field | one () |
| static constexpr field | external_coset_generator () |
| static constexpr field | tag_coset_generator () |
| template<size_t idx> | |
| static constexpr field | coset_generator () |
| template<typename C > requires requires(C& c) { { c.size() } -> std::convertible_to<size_t>; { c[0] }; } | |
| static void | batch_invert (C &coeffs) noexcept |
| Batch invert a collection of field elements using Montgomery's trick. | |
| static void | batch_invert (field *coeffs, size_t n) noexcept |
| static void | batch_invert (std::span< field > coeffs) noexcept |
| static constexpr field | get_root_of_unity (size_t subgroup_size) noexcept |
| static void | serialize_to_buffer (const field &value, uint8_t *buffer) |
| static field | serialize_from_buffer (const uint8_t *buffer) |
| template<class V > | |
| static field | reconstruct_from_public (const std::span< const field< V >, PUBLIC_INPUTS_SIZE > &limbs) |
| static void | split_into_endomorphism_scalars (const field &k, field &k1, field &k2) |
| static std::pair< std::array< uint64_t, 2 >, std::array< uint64_t, 2 > > | split_into_endomorphism_scalars (const field &k) |
| static void | split_into_endomorphism_scalars_384 (const field &input, field &k1_out, field &k2_out) |
| static BB_INLINE void | __copy (const field &a, field &r) noexcept |
| static BB_INLINE void | __swap (field &src, field &dest) noexcept |
| static field | random_element (numeric::RNG *engine=nullptr) noexcept |
| static BB_INLINE constexpr void | wasm_madd (uint64_t &left_limb, const std::array< uint64_t, WASM_NUM_LIMBS > &right_limbs, uint64_t &result_0, uint64_t &result_1, uint64_t &result_2, uint64_t &result_3, uint64_t &result_4, uint64_t &result_5, uint64_t &result_6, uint64_t &result_7, uint64_t &result_8) |
| Multiply left limb by a sequence of 9 limbs and accumulate into result variables. | |
| static BB_INLINE constexpr void | wasm_reduce (uint64_t &result_0, uint64_t &result_1, uint64_t &result_2, uint64_t &result_3, uint64_t &result_4, uint64_t &result_5, uint64_t &result_6, uint64_t &result_7, uint64_t &result_8) |
| Perform 29-bit Montgomery reduction on 1 limb (result_0 should be zero modulo 2^29 after calling this method). | |
| static BB_INLINE constexpr void | wasm_reduce_yuval (uint64_t &result_0, uint64_t &result_1, uint64_t &result_2, uint64_t &result_3, uint64_t &result_4, uint64_t &result_5, uint64_t &result_6, uint64_t &result_7, uint64_t &result_8, uint64_t &result_9) |
| Perform 29-bit Montgomery reduction on 1 limb using Yuval's method. | |
| static BB_INLINE constexpr std::array< uint64_t, WASM_NUM_LIMBS > | wasm_convert (const uint64_t *data) |
| Convert 4 64-bit limbs into 9 29-bit limbs. | |
| static BB_INLINE constexpr std::pair< uint64_t, uint64_t > | mul_wide (uint64_t a, uint64_t b) noexcept |
| static BB_INLINE constexpr uint64_t | mac (uint64_t a, uint64_t b, uint64_t c, uint64_t carry_in, uint64_t &carry_out) noexcept |
Compute uint128_t(a * b + c + carry_in), where the inputs are all uint64_t. Return the top 64 bits. | |
| static BB_INLINE constexpr void | mac (uint64_t a, uint64_t b, uint64_t c, uint64_t carry_in, uint64_t &out, uint64_t &carry_out) noexcept |
Compute uint128_t(a * b + c + carry_in), where the inputs are all uint64_t. out is rewritten to the bottom 64 bits and carry_out is rewritten to the top 64 bits. | |
| static BB_INLINE constexpr uint64_t | mac_mini (uint64_t a, uint64_t b, uint64_t c, uint64_t &out) noexcept |
| static BB_INLINE constexpr void | mac_mini (uint64_t a, uint64_t b, uint64_t c, uint64_t &out, uint64_t &carry_out) noexcept |
| static BB_INLINE constexpr uint64_t | mac_discard_lo (uint64_t a, uint64_t b, uint64_t c) noexcept |
| static BB_INLINE constexpr uint64_t | addc (uint64_t a, uint64_t b, uint64_t carry_in, uint64_t &carry_out) noexcept |
unsigned 64-bit add-with-carry that takes in a carry_in and a carry_out bit and rewrites the latter. | |
| static BB_INLINE constexpr uint64_t | sbb (uint64_t a, uint64_t b, uint64_t borrow_in, uint64_t &borrow_out) noexcept |
| unsigned 64-bit subtract-with-borrow that takes in borrow_in value in the size-2 set {0, 2^64 - 1}, which we interpret as {no borrow, yes borrow}, computes (a - b - (borrow_in != 0)). rewrites borrow_out. | |
| static BB_INLINE constexpr uint64_t | square_accumulate (uint64_t a, uint64_t b, uint64_t c, uint64_t carry_in_lo, uint64_t carry_in_hi, uint64_t &carry_lo, uint64_t &carry_hi) noexcept |
| Computes a + 2 * b * c + carry_in_lo + 2^64 * carry_in_hi, in the form of returning a uint64_t and modifying carry_lo and carry_hi. Here, carry_lo represents bits 64 - 127 of the result and carry_hi bits 128-191 of the result. carry_lo can be an arbitrary uint64_t. | |
| static constexpr size_t | primitive_root_log_size () noexcept |
Public Attributes | |
| uint64_t | data [4] |
Static Public Attributes | |
| static constexpr size_t | PUBLIC_INPUTS_SIZE = Params::PUBLIC_INPUTS_SIZE |
| static constexpr uint256_t | modulus |
| static constexpr uint256_t | r_squared_uint |
| static constexpr std::array< uint64_t, 9 > | wasm_modulus |
| static constexpr std::array< uint64_t, 9 > | wasm_r_inv |
| static constexpr uint256_t | modulus_minus_two |
| static constexpr uint256_t | twice_modulus = modulus + modulus |
| static constexpr uint256_t | not_modulus = -modulus |
| static constexpr uint256_t | twice_not_modulus = -twice_modulus |
| static constexpr size_t | COSET_GENERATOR_SIZE = 15 |
Friends | |
| std::ostream & | operator<< (std::ostream &os, const field &a) |
General class for prime fields see Prime field documentation["field documentation"] for general implementation reference.
| Params_ |
Definition at line 55 of file field_declarations.hpp.
Definition at line 58 of file field_declarations.hpp.
| using bb::field< Params_ >::in_buf = const uint8_t* |
Definition at line 60 of file field_declarations.hpp.
| using bb::field< Params_ >::out_buf = uint8_t* |
Definition at line 62 of file field_declarations.hpp.
Definition at line 59 of file field_declarations.hpp.
| using bb::field< Params_ >::vec_in_buf = const uint8_t* |
Definition at line 61 of file field_declarations.hpp.
| using bb::field< Params_ >::vec_out_buf = uint8_t** |
Definition at line 63 of file field_declarations.hpp.
Definition at line 57 of file field_declarations.hpp.
|
default |
|
inlineconstexprnoexcept |
Definition at line 84 of file field_declarations.hpp.
|
inlineconstexprnoexcept |
Definition at line 90 of file field_declarations.hpp.
|
inlineconstexprnoexcept |
Definition at line 95 of file field_declarations.hpp.
|
inlineconstexprnoexcept |
Definition at line 101 of file field_declarations.hpp.
|
inlineconstexprnoexcept |
Definition at line 108 of file field_declarations.hpp.
|
inlineconstexprnoexcept |
Definition at line 114 of file field_declarations.hpp.
|
inlineconstexprnoexcept |
cast four uint64_t as a field
Definition at line 140 of file field_declarations.hpp.
|
inlineexplicitconstexprnoexcept |
Convert a 512-bit big integer into a field element.
Used for deriving field elements from random values. 512-bits prevents biased output as 2^512>>modulus
Definition at line 149 of file field_declarations.hpp.
|
inlineexplicitconstexprnoexcept |
Definition at line 159 of file field_declarations.hpp.
|
constexprdefaultnoexcept |
|
constexprdefaultnoexcept |
|
inlinestaticnoexcept |
Definition at line 612 of file field_declarations.hpp.
|
inlinestaticnoexcept |
Definition at line 613 of file field_declarations.hpp.
|
constexprnoexcept |
Definition at line 260 of file field_impl_generic.hpp.
|
staticconstexprnoexcept |
unsigned 64-bit add-with-carry that takes in a carry_in and a carry_out bit and rewrites the latter.
carry_in starts out in {0, 1}, then after calling this function carry_out is in {0, 1}. In particular, to have the expected semantic meaning, this function tacitly assumes that carry_in is in {0, 1}. Definition at line 125 of file field_impl_generic.hpp.
|
staticnoexcept |
Batch invert a collection of field elements using Montgomery's trick.
This function is intentionally not parallelized. In scenarios involving large computations (e.g., grand_product_library), multithreading is handled at a higher level. For sparse vectors, other optimizations ensure we don't pay excessive costs.
Definition at line 429 of file field_impl.hpp.
|
staticnoexcept |
Definition at line 405 of file field_impl.hpp.
|
staticnoexcept |
Definition at line 410 of file field_impl.hpp.
|
inlineconstexprnoexcept |
Definition at line 434 of file field_declarations.hpp.
|
inlinestaticconstexpr |
Definition at line 318 of file field_declarations.hpp.
|
inlinestaticconstexpr |
Definition at line 250 of file field_declarations.hpp.
|
inlinestaticconstexpr |
Definition at line 276 of file field_declarations.hpp.
|
constexprnoexcept |
Definition at line 303 of file field_impl.hpp.
|
constexprnoexcept |
Definition at line 328 of file field_impl.hpp.
|
staticconstexprnoexcept |
Definition at line 770 of file field_impl.hpp.
Definition at line 397 of file field_impl.hpp.
|
constexprnoexcept |
Definition at line 754 of file field_impl.hpp.
|
constexprnoexcept |
Definition at line 759 of file field_impl.hpp.
|
constexprnoexcept |
Definition at line 764 of file field_impl.hpp.
|
staticconstexprnoexcept |
Compute uint128_t(a * b + c + carry_in), where the inputs are all uint64_t. Return the top 64 bits.
Definition at line 34 of file field_impl_generic.hpp.
|
staticconstexprnoexcept |
Compute uint128_t(a * b + c + carry_in), where the inputs are all uint64_t. out is rewritten to the bottom 64 bits and carry_out is rewritten to the top 64 bits.
Definition at line 56 of file field_impl_generic.hpp.
|
staticconstexprnoexcept |
Definition at line 106 of file field_impl_generic.hpp.
|
staticconstexprnoexcept |
Definition at line 74 of file field_impl_generic.hpp.
|
staticconstexprnoexcept |
Definition at line 90 of file field_impl_generic.hpp.
|
constexprnoexcept |
Definition at line 702 of file field_impl_generic.hpp.
|
constexprnoexcept |
Mongtomery multiplication for moduli > 2²⁵⁴
Explanation of Montgomery form can be found in Introduction to Montgomery form and the difference between WASM and generic versions is explained in Architecture details
Definition at line 370 of file field_impl_generic.hpp.
|
constexprnoexcept |
Squaring via a variant of the Montgomery algorithm, where we roughly take advantage of the repeated terms in the expansion.
montgomery_mul() method. Definition at line 847 of file field_impl_generic.hpp.
Definition at line 809 of file field_impl.hpp.
|
inline |
Definition at line 625 of file field_declarations.hpp.
Definition at line 829 of file field_impl.hpp.
|
constexprnoexcept |
Definition at line 1051 of file field_impl_generic.hpp.
|
staticconstexprnoexcept |
Definition at line 19 of file field_impl_generic.hpp.
|
inlinestaticconstexpr |
Definition at line 273 of file field_declarations.hpp.
Definition at line 274 of file field_declarations.hpp.
|
inlineexplicitconstexpr |
Definition at line 170 of file field_declarations.hpp.
|
inlineexplicitconstexpr |
Definition at line 203 of file field_declarations.hpp.
|
inlineexplicitconstexpr |
Definition at line 185 of file field_declarations.hpp.
|
inlineconstexprnoexcept |
Definition at line 211 of file field_declarations.hpp.
|
inlineexplicitconstexpr |
Definition at line 191 of file field_declarations.hpp.
|
inlineexplicitconstexpr |
Definition at line 197 of file field_declarations.hpp.
|
inlineexplicitconstexpr |
Definition at line 179 of file field_declarations.hpp.
|
constexprnoexcept |
Definition at line 280 of file field_impl.hpp.
|
constexprnoexcept |
Mutiplication
Definition at line 34 of file field_impl.hpp.
|
constexprnoexcept |
Definition at line 48 of file field_impl.hpp.
|
constexprnoexcept |
Addition
Definition at line 101 of file field_impl.hpp.
Definition at line 129 of file field_impl.hpp.
Definition at line 135 of file field_impl.hpp.
|
constexprnoexcept |
Definition at line 114 of file field_impl.hpp.
Definition at line 160 of file field_impl.hpp.
|
constexprnoexcept |
Subtraction
Definition at line 147 of file field_impl.hpp.
|
constexprnoexcept |
Definition at line 188 of file field_impl.hpp.
|
constexprnoexcept |
Definition at line 738 of file field_impl.hpp.
|
constexprnoexcept |
Definition at line 743 of file field_impl.hpp.
|
constexprnoexcept |
Less-than operator.
comparison operators exist so that field is comparible with stl methods that require them. (e.g. std::sort) Finite fields do not have an explicit ordering, these should NEVER be used in algebraic algorithms.
| T |
| other |
Definition at line 264 of file field_impl.hpp.
|
constexprdefaultnoexcept |
|
constexprdefaultnoexcept |
|
constexprnoexcept |
Definition at line 269 of file field_impl.hpp.
|
constexprnoexcept |
Greater-than operator.
comparison operators exist so that field is comparible with stl methods that require them. (e.g. std::sort) Finite fields do not have an explicit ordering, these should NEVER be used in algebraic algorithms.
| T |
| other |
Definition at line 240 of file field_impl.hpp.
|
constexprnoexcept |
Definition at line 372 of file field_impl.hpp.
|
constexprnoexcept |
Definition at line 392 of file field_impl.hpp.
|
staticconstexprnoexcept |
Definition at line 796 of file field_impl.hpp.
|
staticnoexcept |
Definition at line 783 of file field_impl.hpp.
|
static |
reduce once, i.e., if the value is bigger than the modulus, subtract off the modulus once.
data is always in coarse representation, meaning that the underlying uint256_t derived from the limbs is in [0, 2p). Definition at line 223 of file field_impl_generic.hpp.
Definition at line 345 of file field_impl.hpp.
|
staticconstexprnoexcept |
unsigned 64-bit subtract-with-borrow that takes in borrow_in value in the size-2 set {0, 2^64 - 1}, which we interpret as {no borrow, yes borrow}, computes (a - b - (borrow_in != 0)). rewrites borrow_out.
borrow_in is in {0, 2^64 - 1}, then after calling this function, borrow_out is in {0, 2^64 - 1}. In particular, to have the expected semantic meaning, this function tacitly assumes that borrow_in takes on only these two values. Definition at line 152 of file field_impl_generic.hpp.
|
constexprnoexcept |
Definition at line 215 of file field_impl.hpp.
|
constexprnoexcept |
Definition at line 316 of file field_impl.hpp.
|
constexprnoexcept |
Definition at line 339 of file field_impl.hpp.
|
constexprnoexcept |
Definition at line 203 of file field_impl.hpp.
|
constexprnoexcept |
Definition at line 358 of file field_impl.hpp.
|
constexprnoexcept |
Definition at line 749 of file field_impl.hpp.
|
constexprnoexcept |
Definition at line 82 of file field_impl.hpp.
|
constexprnoexcept |
Definition at line 309 of file field_impl.hpp.
|
constexprnoexcept |
Definition at line 333 of file field_impl.hpp.
|
inlinestatic |
Definition at line 422 of file field_declarations.hpp.
|
inlinestatic |
Definition at line 420 of file field_declarations.hpp.
|
inlinestatic |
Definition at line 495 of file field_declarations.hpp.
|
inlinestatic |
For short Weierstrass curves y^2 = x^3 + b mod r, if there exists a cube root of unity mod r, we can take advantage of an enodmorphism to decompose a 254 bit scalar into 2 128 bit scalars. \beta = cube root of 1, mod q (q = order of fq) \lambda = cube root of 1, mod r (r = order of fr)
For a point P1 = (X, Y), where Y^2 = X^3 + b, we know that the point P2 = (X * \beta, Y) is also a point on the curve We can represent P2 as a scalar multiplication of P1, where P2 = \lambda * P1
For a generic multiplication of P1 by a 254 bit scalar k, we can decompose k into 2 127 bit scalars (k1, k2), such that k = k1 - (k2 * \lambda)
We can now represent (k * P1) as (k1 * P1) - (k2 * P2), where P2 = (X * \beta, Y). As k1, k2 have half the bit length of k, we have reduced the number of loop iterations of our scalar multiplication algorithm in half
To find k1, k2, We use the extended euclidean algorithm to find 4 short scalars [a1, a2], [b1, b2] such that modulus = (a1 * b2) - (b1 * a2) We then compute scalars c1 = round(b2 * k / r), c2 = round(b1 * k / r), where k1 = (c1 * a1) + (c2 * a2), k2 = -((c1 * b1) + (c2 * b2)) We pre-compute scalars g1 = (2^256 * b1) / n, g2 = (2^256 * b2) / n, to avoid having to perform long division on 512-bit scalars
Definition at line 469 of file field_declarations.hpp.
|
inlinestatic |
Definition at line 552 of file field_declarations.hpp.
Squaring
Definition at line 69 of file field_impl.hpp.
|
constexprnoexcept |
|
constexprnoexcept |
Compute square root of the field element.
Definition at line 716 of file field_impl.hpp.
|
constexprnoexcept |
|
staticconstexprnoexcept |
Computes a + 2 * b * c + carry_in_lo + 2^64 * carry_in_hi, in the form of returning a uint64_t and modifying carry_lo and carry_hi. Here, carry_lo represents bits 64 - 127 of the result and carry_hi bits 128-191 of the result. carry_lo can be an arbitrary uint64_t.
Definition at line 182 of file field_impl_generic.hpp.
|
constexprnoexcept |
Definition at line 318 of file field_impl_generic.hpp.
|
inlinestaticconstexpr |
Definition at line 297 of file field_declarations.hpp.
|
inline |
Definition at line 426 of file field_declarations.hpp.
|
constexprnoexcept |
Definition at line 296 of file field_impl.hpp.
|
constexprnoexcept |
Definition at line 323 of file field_impl.hpp.
|
constexprnoexcept |
Implements an optimized variant of Tonelli-Shanks via lookup tables. Algorithm taken from https://cr.yp.to/papers/sqroot-20011123-retypeset20220327.pdf "FASTER SQUARE ROOTS IN ANNOYING FINITE FIELDS" by D. Bernstein Page 5 "Accelerated Discrete Logarithm".
| T |
table_bits in the code). CAUTION IF ADDING A NEW FIELD. Definition at line 471 of file field_impl.hpp.
|
inlineconstexprnoexcept |
Definition at line 217 of file field_declarations.hpp.
|
staticconstexpr |
Convert 4 64-bit limbs into 9 29-bit limbs.
Definition at line 689 of file field_impl_generic.hpp.
|
staticconstexpr |
Multiply left limb by a sequence of 9 limbs and accumulate into result variables.
Definition at line 573 of file field_impl_generic.hpp.
|
staticconstexpr |
Perform 29-bit Montgomery reduction on 1 limb (result_0 should be zero modulo 2^29 after calling this method).
Inputs are 9 uint64_t limbs (result_0, ..., result_8), with the assumption that adding a 58-bit number (from a 29-bit × 29-bit multiplication) does NOT cause 64-bit overflow. Let x = \sum_{i=0}^{8} result_i * 2^{29*i} be the value represented before calling this method. After calling this method, the value \sum_{i=1}^{8} result_i * 2^{29*i} is congruent to x / 2^29 modulo p. Moreover, the low 29 bits of result_0 are zero and result_0 can be discarded. The carry information from result_0 is propagated to result_1 via the term (result_0 >> 29). No other carries are propagated, hence the limbs remain in "relaxed form".
Definition at line 617 of file field_impl_generic.hpp.
|
staticconstexpr |
Perform 29-bit Montgomery reduction on 1 limb using Yuval's method.
Given a value x = \sum_{i=0}^{9} result_i * 2^{29i}, we want to compute x / 2^{29} mod p.
Standard Montgomery reduction achieves this by finding k = result_0 * (-p^{-1}) mod 2^{29}, adding k*p to zero out the lowest limb, then shifting. Yuval's method instead directly computes x / 2^{29} mod p by observing:
x / 2^{29} = (x - result_0) / 2^{29} + result_0 * 2^{-29} (mod p)
The first term is just the higher limbs (an integer shift since result_0 contains all low bits). The second term is result_0 * r_inv, where r_inv = 2^{-29} mod p is precomputed as wasm_r_inv.
After calling this method, result_0 is discarded and result_1..result_9 hold x / 2^{29} mod p.
Definition at line 662 of file field_impl_generic.hpp.
|
inlinestaticconstexpr |
Definition at line 272 of file field_declarations.hpp.
|
friend |
Definition at line 602 of file field_declarations.hpp.
|
staticconstexpr |
Definition at line 753 of file field_declarations.hpp.
| uint64_t bb::field< Params_ >::data[4] |
Definition at line 227 of file field_declarations.hpp.
Definition at line 229 of file field_declarations.hpp.
|
staticconstexpr |
Definition at line 378 of file field_declarations.hpp.
|
staticconstexpr |
Definition at line 628 of file field_declarations.hpp.
|
staticconstexpr |
Definition at line 66 of file field_declarations.hpp.
Definition at line 236 of file field_declarations.hpp.
|
staticconstexpr |
Definition at line 627 of file field_declarations.hpp.
|
staticconstexpr |
Definition at line 629 of file field_declarations.hpp.
|
staticconstexpr |
Definition at line 239 of file field_declarations.hpp.
|
staticconstexpr |
Definition at line 244 of file field_declarations.hpp.