diff --git a/include/mcl/bn.hpp b/include/mcl/bn.hpp index c8255aa..4951138 100644 --- a/include/mcl/bn.hpp +++ b/include/mcl/bn.hpp @@ -1616,6 +1616,10 @@ inline void makeAdjP(G1& adjP, const G1& P) */ inline void finalExp(Fp12& y, const Fp12& x) { + if (x.isZero()) { + y.clear(); + return; + } #if 1 mapToCyclotomic(y, x); #else diff --git a/include/mcl/fp.hpp b/include/mcl/fp.hpp index a223317..ca32888 100644 --- a/include/mcl/fp.hpp +++ b/include/mcl/fp.hpp @@ -531,7 +531,11 @@ public: if (mulSmallUnit(z, x, y)) return; op_.fp_mulUnit(z.v_, x.v_, y, op_.p); } - static inline void inv(FpT& y, const FpT& x) { op_.fp_invOp(y.v_, x.v_, op_); } + static inline void inv(FpT& y, const FpT& x) + { + assert(!x.isZero()); + op_.fp_invOp(y.v_, x.v_, op_); + } static inline void divBy2(FpT& y, const FpT& x) { #if 0 diff --git a/include/mcl/vint.hpp b/include/mcl/vint.hpp index 1e72600..aed0880 100644 --- a/include/mcl/vint.hpp +++ b/include/mcl/vint.hpp @@ -126,6 +126,7 @@ void divNM(T *q, size_t qn, T *r, const T *x, size_t xn, const T *y, size_t yn); */ inline uint32_t divUnit(uint32_t *pr, uint32_t H, uint32_t L, uint32_t y) { + assert(y != 0); uint64_t t = make64(H, L); uint32_t q = uint32_t(t / y); *pr = uint32_t(t % y); @@ -134,6 +135,7 @@ inline uint32_t divUnit(uint32_t *pr, uint32_t H, uint32_t L, uint32_t y) #if MCL_SIZEOF_UNIT == 8 inline uint64_t divUnit(uint64_t *pr, uint64_t H, uint64_t L, uint64_t y) { + assert(y != 0); #if defined(MCL_VINT_64BIT_PORTABLE) || (defined(_MSC_VER) && _MSC_VER < 1920) uint32_t px[4] = { uint32_t(L), uint32_t(L >> 32), uint32_t(H), uint32_t(H >> 32) }; uint32_t py[2] = { uint32_t(y), uint32_t(y >> 32) };