From cbc766ff85fa15c0ada69b9880b9ac5e4bf40891 Mon Sep 17 00:00:00 2001 From: Miha Marolt Date: Tue, 26 Apr 2016 11:20:31 +0200 Subject: [PATCH] Don't put result of 'neg_GF()' back into the same variable. See issue #2. Instead of using the same variable, use some other temporary variable. Care was taken to choose such temporary variable that writing into it doesn't affect the rest of the function (either variable is not used after that or it gets some new value written into it before the next read). --- gfp2.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gfp2.c b/gfp2.c index 4f97374..4dd2479 100644 --- a/gfp2.c +++ b/gfp2.c @@ -520,8 +520,8 @@ void shamir(GF* Rx, GF* Ry, GF* Rz, mul_GF(&tmp[7], tmp[6], tmp[1]); init_GF(&PQy, field); mul_GF(&PQy, tmp[7], tmp[8]); // PQy = (1+E)(D - a C) / (1-E^2) - neg_GF(&tmp[6], tmp[6]); - add_GF_ui(&tmp[6], tmp[6], 2); + neg_GF(&tmp[1], tmp[6]); + add_GF_ui(&tmp[6], tmp[1], 2); mul_GF(&tmp[1], tmp[0], tmp[2]); sub_GF(&tmp[3], tmp[1], tmp[4]); sub_GF(&tmp[1], tmp[3], tmp[5]); @@ -809,8 +809,8 @@ void iso4_apply(GF* X, GF* Y, GF* Z, mul_GF(Y, y, tmp[8]); // Y = y C D sqr_GF(&tmp[6], tmp[4]); sub_GF_ui(&tmp[7], iso.Ap2, 4); - neg_GF(&tmp[7], tmp[7]); - mul_GF(&tmp[8], tmp[6], tmp[7]); + neg_GF(&tmp[0], tmp[7]); + mul_GF(&tmp[8], tmp[6], tmp[0]); mul_GF(Z, z, tmp[8]); // Z = z B^2 (4 - Ap2) } else { sub_GF(&tmp[4], tmp[3], tmp[2]);