1 // GoGOST -- Pure Go GOST cryptographic functions library
2 // Copyright (C) 2015-2023 Sergey Matveev <stargrave@stargrave.org>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, version 3 of the License.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
26 func TestVKO2001(t *testing.T) {
27 c := CurveIdGostR34102001TestParamSet()
28 ukmRaw, _ := hex.DecodeString("5172be25f852a233")
30 prvRaw1, _ := hex.DecodeString("1df129e43dab345b68f6a852f4162dc69f36b2f84717d08755cc5c44150bf928")
31 prvRaw2, _ := hex.DecodeString("5b9356c6474f913f1e83885ea0edd5df1a43fd9d799d219093241157ac9ed473")
32 kek, _ := hex.DecodeString("ee4618a0dbb10cb31777b4b86a53d9e7ef6cb3e400101410f0c0f2af46c494a6")
33 prv1, _ := NewPrivateKey(c, prvRaw1)
34 prv2, _ := NewPrivateKey(c, prvRaw2)
35 pub1, _ := prv1.PublicKey()
36 pub2, _ := prv2.PublicKey()
37 kek1, _ := prv1.KEK2001(pub2, ukm)
38 kek2, _ := prv2.KEK2001(pub1, ukm)
39 if bytes.Compare(kek1, kek2) != 0 {
42 if bytes.Compare(kek1, kek) != 0 {
47 func TestVKOUKMAltering(t *testing.T) {
48 c := CurveIdtc26gost34102012256paramSetA()
50 prv, err := NewPrivateKey(c, bytes.Repeat([]byte{0x12}, 32))
54 pub, err := prv.PublicKey()
58 _, err = prv.KEK(pub, ukm)
62 if ukm.Cmp(big.NewInt(1)) != 0 {
67 func TestRandomVKO2001(t *testing.T) {
68 c := CurveIdGostR34102001TestParamSet()
69 f := func(prvRaw1 [32]byte, prvRaw2 [32]byte, ukmRaw [8]byte) bool {
70 prv1, err := NewPrivateKey(c, prvRaw1[:])
74 prv2, err := NewPrivateKey(c, prvRaw2[:])
78 pub1, _ := prv1.PublicKey()
79 pub2, _ := prv2.PublicKey()
80 ukm := NewUKM(ukmRaw[:])
81 kek1, _ := prv1.KEK2001(pub2, ukm)
82 kek2, _ := prv2.KEK2001(pub1, ukm)
83 return bytes.Compare(kek1, kek2) == 0
85 if err := quick.Check(f, nil); err != nil {