1 // GoGOST -- Pure Go GOST cryptographic functions library
2 // Copyright (C) 2015-2016 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, either version 3 of the License, or
7 // (at your option) any later version.
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.
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/>.
26 func TestVKO2001(t *testing.T) {
27 c, _ := NewCurveFromParams(CurveParamsGostR34102001Test)
28 ukmRaw, _ := hex.DecodeString("5172be25f852a233")
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 {
42 if bytes.Compare(kek1, kek) != 0 {
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[:])
54 prv2, err := NewPrivateKey(c, Mode2001, prvRaw2[:])
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
65 if err := quick.Check(f, nil); err != nil {