From 80ad5cdd5fa2097c08647dec37d31c5c230827a1 Mon Sep 17 00:00:00 2001 From: Crt Vavros - smlu Date: Fri, 29 Dec 2023 01:23:16 +0100 Subject: [PATCH] Fix pointer aliasing issue in modmul & modsqr --- include/ack/bigint.hpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/include/ack/bigint.hpp b/include/ack/bigint.hpp index 652639a..112f7e3 100644 --- a/include/ack/bigint.hpp +++ b/include/ack/bigint.hpp @@ -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; } }; @@ -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; } };