mkp224o/ed25519/ref10/fe_batchinvert.c

27 lines
403 B
C
Raw Normal View History

2019-01-19 13:52:13 +00:00
#include "fe.h"
// tmp MUST != out
// in MAY == out
2019-01-19 15:45:25 +00:00
void fe_batchinvert(fe *out[],fe tmp[],fe * const in[], size_t num)
2019-01-19 13:52:13 +00:00
{
fe acc;
fe tmpacc;
size_t i;
fe_1(acc);
for (i = 0;i < num;++i) {
fe_copy(tmp[i],acc);
2019-01-19 14:39:33 +00:00
fe_mul(acc,acc,*in[i]);
2019-01-19 13:52:13 +00:00
}
fe_invert(acc,acc);
i = num;
while (i--) {
2019-01-19 14:39:33 +00:00
fe_mul(tmpacc,acc,*in[i]);
fe_mul(*out[i],acc,tmp[i]);
2019-01-19 13:52:13 +00:00
fe_copy(acc,tmpacc);
}
}