]> Cypherpunks.ru repositories - gogost.git/commitdiff
Do not alter ukm in gost3410.KEK* v5.1.0
authorSergey Matveev <stargrave@stargrave.org>
Wed, 7 Oct 2020 12:09:49 +0000 (15:09 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Wed, 7 Oct 2020 12:13:05 +0000 (15:13 +0300)
gogost.go
gost3410/vko.go
gost3410/vko2001_test.go
news.texi

index 90c3bb7ab83acec2c5c3d18e7706c772d8e57c97..1d798a9dd2c3036d667135c3ed8ed95c33e43285 100644 (file)
--- a/gogost.go
+++ b/gogost.go
@@ -1,4 +1,4 @@
 // Pure Go GOST cryptographic functions library.
 package gogost
 
-const Version = "5.0.2"
+const Version = "5.1.0"
index fdf3a2f5cb191312f678297696745d75964049f6..a6df7f402b415ddfca6126c265a2973ecb2004be 100644 (file)
@@ -24,9 +24,9 @@ func (prv *PrivateKey) KEK(pub *PublicKey, ukm *big.Int) ([]byte, error) {
        if err != nil {
                return nil, err
        }
-       ukm = ukm.Mul(ukm, prv.C.Co)
-       if ukm.Cmp(bigInt1) != 0 {
-               keyX, keyY, err = prv.C.Exp(ukm, keyX, keyY)
+       u := big.NewInt(0).Set(ukm).Mul(ukm, prv.C.Co)
+       if u.Cmp(bigInt1) != 0 {
+               keyX, keyY, err = prv.C.Exp(u, keyX, keyY)
                if err != nil {
                        return nil, err
                }
index 3f807338cca2432c141e69f049a2b232c384dfc5..80e30ad3a9c435f96719c374e81f156f51678aa8 100644 (file)
@@ -18,6 +18,7 @@ package gost3410
 import (
        "bytes"
        "encoding/hex"
+       "math/big"
        "testing"
        "testing/quick"
 )
@@ -43,6 +44,26 @@ func TestVKO2001(t *testing.T) {
        }
 }
 
+func TestVKOUKMAltering(t *testing.T) {
+       c := CurveIdtc26gost34102012256paramSetA()
+       ukm := big.NewInt(1)
+       prv, err := NewPrivateKey(c, bytes.Repeat([]byte{0x12}, 32))
+       if err != nil {
+               panic(err)
+       }
+       pub, err := prv.PublicKey()
+       if err != nil {
+               panic(err)
+       }
+       _, err = prv.KEK(pub, ukm)
+       if err != nil {
+               panic(err)
+       }
+       if ukm.Cmp(big.NewInt(1)) != 0 {
+               t.FailNow()
+       }
+}
+
 func TestRandomVKO2001(t *testing.T) {
        c := CurveIdGostR34102001TestParamSet()
        f := func(prvRaw1 [32]byte, prvRaw2 [32]byte, ukmRaw [8]byte) bool {
index 350ac077bda2980fb57b4a7f908304e1ce19d5fb..5db2e91d4b94c096883c769f888b2300c48d8f59 100644 (file)
--- a/news.texi
+++ b/news.texi
@@ -3,6 +3,11 @@
 
 @table @strong
 
+@anchor{Release 5.1.0}
+@item 5.1.0
+    @code{gost3410/KEK*} functions do not alter @code{ukm} argument.
+    It is safe to reuse now.
+
 @anchor{Release 5.0.0}
 @item 5.0.0
     Backward incompatible remove of excess misleading @code{gost3410.Mode}