mkp224o/ed25519/ref10/fe_batchinvert.c
2019-01-19 15:45:25 +00:00

27 lines
403 B
C

#include "fe.h"
// tmp MUST != out
// in MAY == out
void fe_batchinvert(fe *out[],fe tmp[],fe * const in[], size_t num)
{
fe acc;
fe tmpacc;
size_t i;
fe_1(acc);
for (i = 0;i < num;++i) {
fe_copy(tmp[i],acc);
fe_mul(acc,acc,*in[i]);
}
fe_invert(acc,acc);
i = num;
while (i--) {
fe_mul(tmpacc,acc,*in[i]);
fe_mul(*out[i],acc,tmp[i]);
fe_copy(acc,tmpacc);
}
}