Skip to content

Commit

Permalink
Fix pointer aliasing issue in modmul & modsqr
Browse files Browse the repository at this point in the history
  • Loading branch information
smlu committed Dec 29, 2023
1 parent 31d35ae commit 80ad5cd
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions include/ack/bigint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,10 @@ namespace ack {
constexpr bool operator()(bigint& z, const bigint& x, const bigint& y) const
{
bool success = bigint::mul(z, x, y);
return success && bigint::mod(z, z, *pm);
bigint u;
success = success && bigint::mod(u, z, *pm);
z = std::move( u );
return success;
}
};

Expand All @@ -1031,7 +1034,9 @@ namespace ack {
constexpr bool operator()(bigint& y, const bigint& x) const
{
bool success = bigint::sqr(y, x);
success = success && bigint::mod(y, y, *pm);
bigint u; // storing result in temp var avoids pointer aliasing
success = success && bigint::mod(u, y, *pm);
y = std::move( u );
return success;
}
};
Expand Down

0 comments on commit 80ad5cd

Please sign in to comment.