pub struct ReductionContext {
pub m: BigNumber,
pub mont: Option<Montgomery>,
/* private fields */
}Expand description
Context for performing modular reduction operations.
Mirrors the TS SDK’s ReductionContext class. Can be constructed with an arbitrary modulus or with the string “k256” to use the secp256k1 prime.
Fields§
§m: BigNumberThe modulus used for reduction.
mont: Option<Montgomery>Optional Montgomery context for the modulus (available for K256).
Implementations§
Source§impl ReductionContext
impl ReductionContext
Sourcepub fn k256() -> Arc<Self>
pub fn k256() -> Arc<Self>
Create a ReductionContext for the secp256k1 field prime (k256). Includes a Montgomery context for use by callers needing Montgomery form.
Sourcepub fn with_prime(prime: Box<dyn MersennePrime>) -> Arc<Self>
pub fn with_prime(prime: Box<dyn MersennePrime>) -> Arc<Self>
Create a new ReductionContext with a Mersenne prime.
Sourcepub fn convert_to(&self, num: &BigNumber) -> BigNumber
pub fn convert_to(&self, num: &BigNumber) -> BigNumber
Convert a BigNumber into this reduction context (reduce mod m).
Sourcepub fn convert_from(&self, num: &BigNumber) -> BigNumber
pub fn convert_from(&self, num: &BigNumber) -> BigNumber
Convert a BigNumber from this reduction context (just clone).
Sourcepub fn mul(&self, a: &BigNumber, b: &BigNumber) -> BigNumber
pub fn mul(&self, a: &BigNumber, b: &BigNumber) -> BigNumber
Multiply two BigNumbers mod m. For K256 with 4-limb operands, uses Karatsuba mul_4x4 followed by limb-level K256 reduction, avoiding all BigNumber temporary allocations.
Sourcepub fn sqr(&self, a: &BigNumber) -> BigNumber
pub fn sqr(&self, a: &BigNumber) -> BigNumber
Square a BigNumber mod m. For K256 with 4-limb operands, uses sqr_4x4 followed by limb-level K256 reduction.