2019-01-19 13:52:13 +00:00
|
|
|
#include "fe.h"
|
|
|
|
|
2020-11-22 10:21:06 +00:00
|
|
|
// tmp MUST != out or in
|
2019-01-19 13:52:13 +00:00
|
|
|
// in MAY == out
|
2020-11-22 10:21:06 +00:00
|
|
|
void fe_batchinvert(fe *out,fe *in,fe *tmp,size_t num,size_t shift)
|
2019-01-19 13:52:13 +00:00
|
|
|
{
|
|
|
|
fe acc;
|
|
|
|
fe tmpacc;
|
|
|
|
size_t i;
|
2020-11-22 10:21:06 +00:00
|
|
|
fe *inp;
|
|
|
|
fe *outp;
|
2019-01-19 13:52:13 +00:00
|
|
|
|
|
|
|
fe_1(acc);
|
|
|
|
|
2020-11-22 10:21:06 +00:00
|
|
|
inp = in;
|
2019-01-19 13:52:13 +00:00
|
|
|
for (i = 0;i < num;++i) {
|
|
|
|
fe_copy(tmp[i],acc);
|
2020-11-22 10:21:06 +00:00
|
|
|
fe_mul(acc,acc,*inp);
|
|
|
|
inp = (fe *)((char *)inp + shift);
|
2019-01-19 13:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fe_invert(acc,acc);
|
|
|
|
|
|
|
|
i = num;
|
2020-11-22 10:21:06 +00:00
|
|
|
inp = (fe *)((char *)in + shift * num);
|
|
|
|
outp = (fe *)((char *)out + shift * num);
|
2019-01-19 13:52:13 +00:00
|
|
|
while (i--) {
|
2020-11-22 10:21:06 +00:00
|
|
|
inp = (fe *)((char *)inp - shift);
|
|
|
|
outp = (fe *)((char *)outp - shift);
|
|
|
|
fe_mul(tmpacc,acc,*inp);
|
|
|
|
fe_mul(*outp,acc,tmp[i]);
|
2019-01-19 13:52:13 +00:00
|
|
|
fe_copy(acc,tmpacc);
|
|
|
|
}
|
|
|
|
}
|