Skip to content

Commit

Permalink
no_asm.h: don't fall into endless loop in eucl_inverse_mod_n.
Browse files Browse the repository at this point in the history
Even though inverse of zero is formally undefined, it's customary to
return zero.

Reported by Guido Vranken.
  • Loading branch information
dot-asm committed Mar 7, 2021
1 parent 81cd381 commit dd980e7
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/no_asm.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,11 @@ static bool_t eucl_inverse_mod_n(limb_t out[], const limb_t a[],
bool_t ret = 0;
size_t i;

if (vec_is_zero(a, n*sizeof(limb_t))) {
vec_zero(out, n*sizeof(limb_t));
return 0;
}

vec_copy(ux[0], a, sizeof(ux[0]));
if (one != NULL)
vec_copy(ux[1], one, sizeof(ux[1]));
Expand Down

0 comments on commit dd980e7

Please sign in to comment.