File tree Expand file tree Collapse file tree 2 files changed +36
-39
lines changed Expand file tree Collapse file tree 2 files changed +36
-39
lines changed Original file line number Diff line number Diff line change @@ -389,55 +389,52 @@ impl Invert for Scalar {
389389 fn invert_vartime ( & self ) -> CtOption < Self > {
390390 #[ cfg( all( target_os = "zkvm" , target_arch = "riscv32" ) ) ]
391391 {
392- self . invert ( )
392+ return self . invert ( ) ;
393393 }
394394
395- #[ cfg( not( all( target_os = "zkvm" , target_arch = "riscv32" ) ) ) ]
396- {
397- let mut u = * self ;
398- let mut v = Self ( MODULUS ) ;
399- let mut A = Self :: ONE ;
400- let mut C = Self :: ZERO ;
401-
402- while !bool:: from ( u. is_zero ( ) ) {
403- // u-loop
404- while bool:: from ( u. is_even ( ) ) {
405- u >>= 1 ;
406-
407- let was_odd: bool = A . is_odd ( ) . into ( ) ;
408- A >>= 1 ;
409-
410- if was_odd {
411- A += FRAC_MODULUS_2 ;
412- A += Self :: ONE ;
413- }
414- }
395+ let mut u = * self ;
396+ let mut v = Self ( MODULUS ) ;
397+ let mut A = Self :: ONE ;
398+ let mut C = Self :: ZERO ;
415399
416- // v-loop
417- while bool:: from ( v. is_even ( ) ) {
418- v >>= 1 ;
400+ while !bool:: from ( u. is_zero ( ) ) {
401+ // u-loop
402+ while bool:: from ( u. is_even ( ) ) {
403+ u >>= 1 ;
419404
420- let was_odd: bool = C . is_odd ( ) . into ( ) ;
421- C >>= 1 ;
405+ let was_odd: bool = A . is_odd ( ) . into ( ) ;
406+ A >>= 1 ;
422407
423- if was_odd {
424- C += FRAC_MODULUS_2 ;
425- C += Self :: ONE ;
426- }
408+ if was_odd {
409+ A += FRAC_MODULUS_2 ;
410+ A += Self :: ONE ;
427411 }
412+ }
413+
414+ // v-loop
415+ while bool:: from ( v. is_even ( ) ) {
416+ v >>= 1 ;
428417
429- // sub-step
430- if u >= v {
431- u -= & v;
432- A -= & C ;
433- } else {
434- v -= & u;
435- C -= & A ;
418+ let was_odd: bool = C . is_odd ( ) . into ( ) ;
419+ C >>= 1 ;
420+
421+ if was_odd {
422+ C += FRAC_MODULUS_2 ;
423+ C += Self :: ONE ;
436424 }
437425 }
438426
439- CtOption :: new ( C , !self . is_zero ( ) )
427+ // sub-step
428+ if u >= v {
429+ u -= & v;
430+ A -= & C ;
431+ } else {
432+ v -= & u;
433+ C -= & A ;
434+ }
440435 }
436+
437+ CtOption :: new ( C , !self . is_zero ( ) )
441438 }
442439}
443440
Original file line number Diff line number Diff line change 1- // #![no_std]
1+ #![ no_std]
22#![ cfg_attr( docsrs, feature( doc_auto_cfg) ) ]
33#![ doc = include_str ! ( "../README.md" ) ]
44#![ doc(
You can’t perform that action at this time.
0 commit comments