EC crypto: Equivalent of EC_POINT_invert() in go?

118 views
Skip to first unread message

Anatol Pomozov

unread,
Sep 25, 2020, 1:35:21 PM9/25/20
to golang-nuts
Hi

I am trying to port some of EC crypto code to golang. And I have a call in C

            if (EC_POINT_invert(grp, p, bnc) < 0)
                return NULL;

that I need to port to golang. I checked the crypto lib docs and did not find any mention of EC point inversion operation.

Could anyone point me to the right direction on how to achieve the inversion in Go?

Joop Kiefte

unread,
Sep 25, 2020, 1:52:54 PM9/25/20
to anatol....@gmail.com, golan...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/3be55ce9-d6e5-46e7-84cc-3866e7d9b591n%40googlegroups.com.

Anatol Pomozov

unread,
Sep 25, 2020, 2:01:49 PM9/25/20
to Joop Kiefte, golan...@googlegroups.com
Hi

On Fri, Sep 25, 2020 at 10:51 AM Joop Kiefte <iko...@gmail.com> wrote:


But I want to avoid implementing parts of EC encryption myself and looking for a standard Golang way to achieve my goal.

Shouldn't this inversion operation be part of the standard library?

Conrado P. L. Gouvêa

unread,
Sep 28, 2020, 7:46:27 AM9/28/20
to Anatol Pomozov, Joop Kiefte, golang-nuts

On Fri, Sep 25, 2020 at 3:01 PM Anatol Pomozov <anatol....@gmail.com> wrote:
> Or more precisely it calls this code https://boringssl.googlesource.com/boringssl/+/master/crypto/fipsmodule/ec/felem.c#57
>
> But I want to avoid implementing parts of EC encryption myself and looking for a standard Golang way to achieve my goal.
>
> Shouldn't this inversion operation be part of the standard library?
>

My understanding is that the Go standard library prefers that the entire underlying logic of ECC should be hidden from the user, like in "crypto/ed25519".

However, they can't get rid of elliptic.CryptoParams due to compatibility. It's not a good idea in a general sense to use CryptoParams because it uses big.Int which is not side-channel resistant. For these reasons I don't think it's likely they'all add point inversion.

If you do want to go on... you can "invert" a point ("negate" would be a better term...) by simply setting y = n - y, for example:

y := new(big.Int).Sub(curveParams.Params().N, y)


Best regards,
Conrado




Anatol Pomozov

unread,
Sep 30, 2020, 1:05:02 PM9/30/20
to Conrado P. L. Gouvêa, Joop Kiefte, golang-nuts
Hi
Thank you. I end up with following code for calculating "A - B" expression:

x, y = ecCurve.Add(a.X, a.Y, b.X, new(big.Int).Neg(b.Y))

And it seems to work the same as the openssl version I posted above.
Thank you for your help.

Though having a function in the standard library (either "Sub()" or
"Negate()") would make such code cleaner and easier to follow.
Reply all
Reply to author
Forward
0 new messages