]> Cypherpunks.ru repositories - gogost.git/blob - src/cypherpunks.ru/gogost/gost3410/vko2001_test.go
85745baf1524ac8467516f56b77a2076e1e9e307
[gogost.git] / src / cypherpunks.ru / gogost / gost3410 / vko2001_test.go
1 // GoGOST -- Pure Go GOST cryptographic functions library
2 // Copyright (C) 2015-2019 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, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 package gost3410
18
19 import (
20         "bytes"
21         "encoding/hex"
22         "testing"
23         "testing/quick"
24 )
25
26 func TestVKO2001(t *testing.T) {
27         c, _ := NewCurveFromParams(CurveParamsGostR34102001Test)
28         ukmRaw, _ := hex.DecodeString("5172be25f852a233")
29         ukm := NewUKM(ukmRaw)
30         prvRaw1, _ := hex.DecodeString("1df129e43dab345b68f6a852f4162dc69f36b2f84717d08755cc5c44150bf928")
31         prvRaw2, _ := hex.DecodeString("5b9356c6474f913f1e83885ea0edd5df1a43fd9d799d219093241157ac9ed473")
32         kek, _ := hex.DecodeString("ee4618a0dbb10cb31777b4b86a53d9e7ef6cb3e400101410f0c0f2af46c494a6")
33         prv1, _ := NewPrivateKey(c, Mode2001, prvRaw1)
34         prv2, _ := NewPrivateKey(c, Mode2001, 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 {
40                 t.FailNow()
41         }
42         if bytes.Compare(kek1, kek) != 0 {
43                 t.FailNow()
44         }
45 }
46
47 func TestRandomVKO2001(t *testing.T) {
48         c, _ := NewCurveFromParams(CurveParamsGostR34102001Test)
49         f := func(prvRaw1 [32]byte, prvRaw2 [32]byte, ukmRaw [8]byte) bool {
50                 prv1, err := NewPrivateKey(c, Mode2001, prvRaw1[:])
51                 if err != nil {
52                         return false
53                 }
54                 prv2, err := NewPrivateKey(c, Mode2001, prvRaw2[:])
55                 if err != nil {
56                         return false
57                 }
58                 pub1, _ := prv1.PublicKey()
59                 pub2, _ := prv2.PublicKey()
60                 ukm := NewUKM(ukmRaw[:])
61                 kek1, _ := prv1.KEK2001(pub2, ukm)
62                 kek2, _ := prv2.KEK2001(pub1, ukm)
63                 return bytes.Compare(kek1, kek2) == 0
64         }
65         if err := quick.Check(f, nil); err != nil {
66                 t.Error(err)
67         }
68 }