herumi / mcl

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

Go binding: maybe `SetHashOf` should compare with 0 not 1 #15

Closed helinwang closed 6 years ago

helinwang commented 6 years ago

Thanks for the great library!

Maybe https://github.com/herumi/mcl/blob/d798881e3bcc634afd718b8a7fc62e3060dda6f5/ffi/go/mcl/mcl.go#L148-L151

Should compare with 0, not 1? E.g.,

func (x *Fr) SetHashOf(buf []byte) bool {
    // #nosec
    return C.mclBnFr_setHashOf(x.getPointer(), unsafe.Pointer(&buf[0]), C.size_t(len(buf))) == 0
}

Since the success value seems to be 0, and the failure value seems to be -1: https://github.com/herumi/mcl/blob/e6c316cbbd2e75a158578aed0f592141e85bf754/src/bn_c_impl.hpp#L193

herumi commented 6 years ago

Thank you for your verification. I fixed it.

helinwang commented 6 years ago

Thank you! Btw, same issue with "github.com/dfinity/go-dfinity-crypto/bls" if you also maintains it: https://github.com/dfinity/go-dfinity-crypto/blob/master/bls/mcl.go#L136

helinwang commented 6 years ago

@herumi if you don't mind, maybe rename err to success for clarity:

success := x.SetHashOf([]byte("abc"))
if !success {
  t.Error(err)
}