Skip to content

Commit f48500c

Browse files
committed
multi_scalar.c: tolerate infinity points in ptype##s_precompute_wbits.
Infinity points are considered incompatible with sound applications, but tend to appear in synthetic tests.
1 parent 7c535f1 commit f48500c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/multi_scalar.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,23 @@ POINTS_TO_AFFINE_IMPL(blst_p2, POINTonE2, 384x, fp2)
8080

8181
#define SCRATCH_SZ(ptype) (sizeof(ptype)==sizeof(POINTonE1) ? 8192 : 4096)
8282

83+
/* The intermediate infinity points are encoded as [0, 0, 1]. */
84+
8385
#define PRECOMPUTE_WBITS_IMPL(prefix, ptype, bits, field, one) \
8486
static void ptype##_precompute_row_wbits(ptype row[], size_t wbits, \
8587
const ptype##_affine *point) \
8688
{ \
8789
size_t i, j, n = (size_t)1 << (wbits-1); \
90+
bool_t inf = vec_is_zero(point, sizeof(*point)); \
8891
/* row[-1] is implicit infinity */\
8992
vec_copy(&row[0], point, sizeof(*point)); /* row[0]=p*1 */\
9093
vec_copy(&row[0].Z, one, sizeof(row[0].Z)); \
9194
ptype##_double(&row[1], &row[0]); /* row[1]=p*(1+1) */\
95+
vec_select(&row[1].Z, one, &row[1].Z, sizeof(row[1].Z), inf); \
9296
for (i = 2, j = 1; i < n; i += 2, j++) \
9397
ptype##_add_affine(&row[i], &row[i-1], point), /* row[2]=p*(2+1) */\
94-
ptype##_double(&row[i+1], &row[j]); /* row[3]=p*(2+2) */\
98+
ptype##_double(&row[i+1], &row[j]), /* row[3]=p*(2+2) */\
99+
vec_select(&row[i+1].Z, one, &row[i+1].Z, sizeof(row[i+1].Z), inf); \
95100
} /* row[4] ... */\
96101
\
97102
static void ptype##s_to_affine_row_wbits(ptype##_affine dst[], ptype src[], \

0 commit comments

Comments
 (0)