From: Sergey Matveev Date: Tue, 17 Aug 2021 13:23:40 +0000 (+0300) Subject: gost3410.PublicKey.Equal method, necessary for Go 1.17 X-Git-Tag: v5.7.0^0 X-Git-Url: http://www.git.cypherpunks.ru/?p=gogost.git;a=commitdiff_plain;h=6bb01904f8685018353233727eafceeb5a05ec64 gost3410.PublicKey.Equal method, necessary for Go 1.17 --- diff --git a/gogost.go b/gogost.go index 068a449..6af0a23 100644 --- a/gogost.go +++ b/gogost.go @@ -1,4 +1,4 @@ // Pure Go GOST cryptographic functions library. package gogost -const Version = "5.6.0" +const Version = "5.7.0" diff --git a/gost3410/curve.go b/gost3410/curve.go index 9ec14de..1aa783c 100644 --- a/gost3410/curve.go +++ b/gost3410/curve.go @@ -159,3 +159,15 @@ func (c *Curve) Exp(degree, xS, yS *big.Int) (*big.Int, *big.Int, error) { } return tx, ty, nil } + +func (our *Curve) Equal(their *Curve) bool { + return our.P.Cmp(their.P) == 0 && + our.Q.Cmp(their.Q) == 0 && + our.A.Cmp(their.A) == 0 && + our.B.Cmp(their.B) == 0 && + our.X.Cmp(their.X) == 0 && + our.Y.Cmp(their.Y) == 0 && + ((our.E == nil && their.E == nil) || our.E.Cmp(their.E) == 0) && + ((our.D == nil && their.D == nil) || our.D.Cmp(their.D) == 0) && + our.Co.Cmp(their.Co) == 0 +} diff --git a/gost3410/public.go b/gost3410/public.go index 79f00f4..8642a27 100644 --- a/gost3410/public.go +++ b/gost3410/public.go @@ -16,6 +16,7 @@ package gost3410 import ( + "crypto" "fmt" "math/big" ) @@ -107,3 +108,11 @@ func (pub *PublicKey) VerifyDigest(digest, signature []byte) (bool, error) { lm.Mod(lm, pub.C.Q) return lm.Cmp(r) == 0, nil } + +func (our *PublicKey) Equal(theirKey crypto.PublicKey) bool { + their, ok := theirKey.(*PublicKey) + if !ok { + return false + } + return our.X.Cmp(their.X) == 0 && our.X.Cmp(their.Y) == 0 && our.C.Equal(their.C) +} diff --git a/news.texi b/news.texi index a5aabeb..b91a0f1 100644 --- a/news.texi +++ b/news.texi @@ -3,6 +3,10 @@ @table @strong +@anchor{Release 5.7.0} +@item 5.7.0 +Go 1.17 requires @code{gost3410.PublicKey} to have @code{Equal} method. + @anchor{Release 5.6.0} @item 5.6.0 @itemize