Skip to main content

binxgcd_step

Function binxgcd_step 

Source
const fn binxgcd_step<const LIMBS: usize, const MATRIX_LIMBS: usize>(
    a: &mut Uint<LIMBS>,
    b: &mut Uint<LIMBS>,
    matrix: &mut DividedPatternMatrix<MATRIX_LIMBS>,
    halt_at_zero: Choice,
) -> Word
Expand description

Binary XGCD update step.

This is a condensed, constant time execution of the following algorithm:

if a mod 2 == 1
   if a < b
       (a, b) ← (b, a)
       (f0, g0, f1, g1) ← (f1, g1, f0, g0)
   a ← a - b
   (f0, g0) ← (f0 - f1, g0 - g1)
if a > 0
    a ← a/2
    (f1, g1) ← (2f1, 2g1)

where matrix represents

 (f0 g0)
 (f1 g1).

Note: this algorithm assumes b to be an odd integer. The algorithm will likely not yield the correct result when this is not the case.

Ref: Pornin, Algorithm 2, L8-17, https://eprint.iacr.org/2020/972.pdf.