]> Cypherpunks.ru repositories - gogost.git/blobdiff - gost3410/vko2001_test.go
Download link for 5.14.1 release
[gogost.git] / gost3410 / vko2001_test.go
index 3f807338cca2432c141e69f049a2b232c384dfc5..2e5e91ab56442a4476274a743955793e2872fdb0 100644 (file)
@@ -1,5 +1,5 @@
 // GoGOST -- Pure Go GOST cryptographic functions library
-// Copyright (C) 2015-2020 Sergey Matveev <stargrave@stargrave.org>
+// Copyright (C) 2015-2024 Sergey Matveev <stargrave@stargrave.org>
 //
 // This program is free software: you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -18,6 +18,7 @@ package gost3410
 import (
        "bytes"
        "encoding/hex"
+       "math/big"
        "testing"
        "testing/quick"
 )
@@ -35,10 +36,30 @@ func TestVKO2001(t *testing.T) {
        pub2, _ := prv2.PublicKey()
        kek1, _ := prv1.KEK2001(pub2, ukm)
        kek2, _ := prv2.KEK2001(pub1, ukm)
-       if bytes.Compare(kek1, kek2) != 0 {
+       if !bytes.Equal(kek1, kek2) {
                t.FailNow()
        }
-       if bytes.Compare(kek1, kek) != 0 {
+       if !bytes.Equal(kek1, kek) {
+               t.FailNow()
+       }
+}
+
+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()
        }
 }
@@ -59,7 +80,7 @@ func TestRandomVKO2001(t *testing.T) {
                ukm := NewUKM(ukmRaw[:])
                kek1, _ := prv1.KEK2001(pub2, ukm)
                kek2, _ := prv2.KEK2001(pub1, ukm)
-               return bytes.Compare(kek1, kek2) == 0
+               return bytes.Equal(kek1, kek2)
        }
        if err := quick.Check(f, nil); err != nil {
                t.Error(err)