]> Cypherpunks.ru repositories - gogost.git/blob - gost3410/vko2001_test.go
Raise copyright years
[gogost.git] / gost3410 / vko2001_test.go
1 // GoGOST -- Pure Go GOST cryptographic functions library
2 // Copyright (C) 2015-2020 Sergey Matveev <stargrave@stargrave.org>
3 //
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.
7 //
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.
12 //
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/>.
15
16 package gost3410
17
18 import (
19         "bytes"
20         "encoding/hex"
21         "testing"
22         "testing/quick"
23 )
24
25 func TestVKO2001(t *testing.T) {
26         c := CurveIdGostR34102001TestParamSet()
27         ukmRaw, _ := hex.DecodeString("5172be25f852a233")
28         ukm := NewUKM(ukmRaw)
29         prvRaw1, _ := hex.DecodeString("1df129e43dab345b68f6a852f4162dc69f36b2f84717d08755cc5c44150bf928")
30         prvRaw2, _ := hex.DecodeString("5b9356c6474f913f1e83885ea0edd5df1a43fd9d799d219093241157ac9ed473")
31         kek, _ := hex.DecodeString("ee4618a0dbb10cb31777b4b86a53d9e7ef6cb3e400101410f0c0f2af46c494a6")
32         prv1, _ := NewPrivateKey(c, Mode2001, prvRaw1)
33         prv2, _ := NewPrivateKey(c, Mode2001, prvRaw2)
34         pub1, _ := prv1.PublicKey()
35         pub2, _ := prv2.PublicKey()
36         kek1, _ := prv1.KEK2001(pub2, ukm)
37         kek2, _ := prv2.KEK2001(pub1, ukm)
38         if bytes.Compare(kek1, kek2) != 0 {
39                 t.FailNow()
40         }
41         if bytes.Compare(kek1, kek) != 0 {
42                 t.FailNow()
43         }
44 }
45
46 func TestRandomVKO2001(t *testing.T) {
47         c := CurveIdGostR34102001TestParamSet()
48         f := func(prvRaw1 [32]byte, prvRaw2 [32]byte, ukmRaw [8]byte) bool {
49                 prv1, err := NewPrivateKey(c, Mode2001, prvRaw1[:])
50                 if err != nil {
51                         return false
52                 }
53                 prv2, err := NewPrivateKey(c, Mode2001, prvRaw2[:])
54                 if err != nil {
55                         return false
56                 }
57                 pub1, _ := prv1.PublicKey()
58                 pub2, _ := prv2.PublicKey()
59                 ukm := NewUKM(ukmRaw[:])
60                 kek1, _ := prv1.KEK2001(pub2, ukm)
61                 kek2, _ := prv2.KEK2001(pub1, ukm)
62                 return bytes.Compare(kek1, kek2) == 0
63         }
64         if err := quick.Check(f, nil); err != nil {
65                 t.Error(err)
66         }
67 }