math/scaf.c: Fix conditional subtractions in `scaf_reduce'.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 10 May 2017 20:19:32 +0000 (21:19 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 14 May 2017 13:58:40 +0000 (14:58 +0100)
So that they actually subtract the right thing.  Obvious blunder.  The
big surprise is that none of the literally thousands of Ed25519 tests
which have hammered on that code caught it.  (Found during development
of Ed448, coming later.)

math/scaf.c

index 778e5e3..84ef3de 100644 (file)
@@ -269,7 +269,7 @@ void scaf_reduce(scaf_piece *z, const scaf_dblpiece *x,
       u += z[j] + (l[j] ^ m);
       t[j] = u&m; u >>= piecewd;
     }
-    for (j = 0, u = -u; j < npiece; j++) z[i] = (t[i]&u) | (z[i]&~u);
+    for (j = 0, u = -u; j < npiece; j++) z[j] = (t[j]&u) | (z[j]&~u);
   }
 }