fe_batchinvert.c 643 B

12345678910111213141516171819202122232425262728293031323334
  1. #include "fe.h"
  2. // tmp MUST != out or in
  3. // in MAY == out
  4. void fe_batchinvert(fe *out,fe *in,fe *tmp,size_t num,size_t shift)
  5. {
  6. fe acc;
  7. fe tmpacc;
  8. size_t i;
  9. fe *inp;
  10. fe *outp;
  11. fe_1(acc);
  12. inp = in;
  13. for (i = 0;i < num;++i) {
  14. fe_copy(tmp[i],acc);
  15. fe_mul(acc,acc,*inp);
  16. inp = (fe *)((char *)inp + shift);
  17. }
  18. fe_invert(acc,acc);
  19. i = num;
  20. inp = (fe *)((char *)in + shift * num);
  21. outp = (fe *)((char *)out + shift * num);
  22. while (i--) {
  23. inp = (fe *)((char *)inp - shift);
  24. outp = (fe *)((char *)outp - shift);
  25. fe_mul(tmpacc,acc,*inp);
  26. fe_mul(*outp,acc,tmp[i]);
  27. fe_copy(acc,tmpacc);
  28. }
  29. }