From 13b205b18a2b2ef3c5452d1fec14424dc4d31399 Mon Sep 17 00:00:00 2001 From: Loup Vaillant Date: Thu, 6 Dec 2018 00:46:07 +0100 Subject: [PATCH] Inlined window caching --- src/monocypher.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/monocypher.c b/src/monocypher.c index 49b0312..97ab01c 100644 --- a/src/monocypher.c +++ b/src/monocypher.c @@ -1678,25 +1678,19 @@ static void slide(size_t width, i8 *adds, const u8 scalar[32]) } } -// Look up table for sliding windows -static void ge_precompute(ge_cached lut[WINDOW_SIZE], const ge *P1) -{ - ge P2, tmp; - ge_double(&P2, P1, &tmp); - ge_cache(&lut[0], P1); - FOR (i, 0, (WINDOW_SIZE)-1) { - ge_add(&tmp, &P2, &lut[i]); - ge_cache(&lut[i+1], &tmp); - } -} - // Variable time! P, sP, and sB must not be secret! static void ge_double_scalarmult_vartime(ge *sum, const ge *P, u8 p[32], u8 b[32]) { // cache P window for addition ge_cached cP[WINDOW_SIZE]; - ge_precompute(cP, P); + ge P2, tmp; + ge_double(&P2, P, &tmp); + ge_cache(&cP[0], P); + FOR (i, 0, (WINDOW_SIZE)-1) { + ge_add(&tmp, &P2, &cP[i]); + ge_cache(&cP[i+1], &tmp); + } // Compute the indices for the windows i8 p_adds[253 + WINDOW_WIDTH]; slide(WINDOW_WIDTH, p_adds, p); -- 2.47.3