herumi / mcl

a portable and fast pairing-based cryptography library
BSD 3-Clause "New" or "Revised" License
458 stars 157 forks source link

why not implement EcT operator*()? #32

Closed huyuguang closed 6 years ago

huyuguang commented 6 years ago

I found Fp has operator+-*/, and EcT hasoperator+-, but does not have operator*, why? Does here have any essential reasons?

herumi commented 6 years ago

I do not make EcT::operator* because the types of arguments of EcT::mul is not same.

huyuguang commented 6 years ago

I found the Operator in operator.hpp:

template<class T, class E = Empty<T> >
struct Operator : public E {
    template<class S> MCL_FORCE_INLINE T& operator+=(const S& rhs) { T::add(static_cast<T&>(*this), static_cast<const T&>(*this), rhs); return static_cast<T&>(*this); }
    template<class S> MCL_FORCE_INLINE T& operator-=(const S& rhs) { T::sub(static_cast<T&>(*this), static_cast<const T&>(*this), rhs); return static_cast<T&>(*this); }
    template<class S> friend MCL_FORCE_INLINE T operator+(const T& a, const S& b) { T c; T::add(c, a, b); return c; }
    template<class S> friend MCL_FORCE_INLINE T operator-(const T& a, const S& b) { T c; T::sub(c, a, b); return c; }
    template<class S> MCL_FORCE_INLINE T& operator*=(const S& rhs) { T::mul(static_cast<T&>(*this), static_cast<const T&>(*this), rhs)

The template<class S> also not same with T.

Why not just use the same code in EcT?

herumi commented 6 years ago

The operator* does not need the same types of arguments

Of course, I know it, but Ec::mul overloads three kinds of integer type and I wait to decide whether to implement both E INT and INT E, and I do not think they are necessary functions.

herumi commented 6 years ago

I added E INT and E= INT. https://github.com/herumi/mcl/commit/bb4735dddc22458abacc4ac9714df79e3aff13ba

herumi commented 6 years ago

Why not just use the same code in EcT?

Operator is for a field class and requires add, sub, mul and div so it can not be applied to EcT, which is an addtive group class.

huyuguang commented 6 years ago

I added E INT and E= INT. bb4735d

Also add E * Fr and E *= Fr, please.

herumi commented 6 years ago

Also add E Fr and E = Fr, please.

https://github.com/herumi/mcl/commit/bb4735dddc22458abacc4ac9714df79e3aff13ba has already supported it.

huyuguang commented 6 years ago

Also add E Fr and E = Fr, please.

bb4735d has already supported it.

The INT is a template type name, very thanks!