Skip to main content

Module safegcd

Module safegcd 

Source
Expand description

Implementation of Bernstein-Yang modular inversion and GCD algorithm (a.k.a. safegcd) as described in: https://eprint.iacr.org/2019/266.

Adapted from the Apache 2.0+MIT licensed implementation originally from: https://github.com/taikoxyz/halo2curves/pull/2 https://github.com/privacy-scaling-explorations/halo2curves/pull/83

Copyright (c) 2023 Privacy Scaling Explorations Team

Modulesยง

boxed ๐Ÿ”’
Implementation of Bernstein-Yang modular inversion and GCD algorithm (a.k.a. safegcd) as described in: https://eprint.iacr.org/2019/266.

Structsยง

SafeGcdInverter ๐Ÿ”’
Modular multiplicative inverter based on the Bernstein-Yang method.
SignedInt ๐Ÿ”’
A Uint which carries a separate sign in order to maintain the same range.

Constantsยง

GCD_BATCH_SIZE ๐Ÿ”’

Functionsยง

conditional_negate_in_place_wide ๐Ÿ”’
Conditionally negate a wide Uint represented by (lo, hi).
gcd_odd
Calculate the greatest common denominator of odd f, and g.
invert_odd_mod
invert_odd_mod_precomp ๐Ÿ”’
Calculate the multiplicative inverse of a modulo m.
iterations ๐Ÿ”’
Calculate the maximum number of iterations required according to safegcd-bounds: https://github.com/sipa/safegcd-bounds
jump ๐Ÿ”’
Perform batch steps of the gcd reduction process on signed tail values f and g.
jump_step ๐Ÿ”’
Perform one step of the gcd reduction in constant time. This follows the half-delta variant of safegcd-bounds which reduces the round count. https://github.com/sipa/safegcd-bounds
jump_step_vartime ๐Ÿ”’
Perform one step of the gcd reduction in variable time.
shr_in_place_wide ๐Ÿ”’
Right shift a wide Uint represented by (lo, hi) returning any remaining high bits.
update_de ๐Ÿ”’
update_fg ๐Ÿ”’

Type Aliasesยง

Matrix ๐Ÿ”’
Type of the Bernstein-Yang transition matrix multiplied by 2^62