-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvko2001_test.go
88 lines (83 loc) · 2.46 KB
/
vko2001_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// GoGOST -- Pure Go GOST cryptographic functions library
// Copyright (C) 2015-2024 Sergey Matveev <[email protected]>
//
// 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
// the Free Software Foundation, version 3 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package gost3410
import (
"bytes"
"encoding/hex"
"math/big"
"testing"
"testing/quick"
)
func TestVKO2001(t *testing.T) {
c := CurveIdGostR34102001TestParamSet()
ukmRaw, _ := hex.DecodeString("5172be25f852a233")
ukm := NewUKM(ukmRaw)
prvRaw1, _ := hex.DecodeString("1df129e43dab345b68f6a852f4162dc69f36b2f84717d08755cc5c44150bf928")
prvRaw2, _ := hex.DecodeString("5b9356c6474f913f1e83885ea0edd5df1a43fd9d799d219093241157ac9ed473")
kek, _ := hex.DecodeString("ee4618a0dbb10cb31777b4b86a53d9e7ef6cb3e400101410f0c0f2af46c494a6")
prv1, _ := NewPrivateKey(c, prvRaw1)
prv2, _ := NewPrivateKey(c, prvRaw2)
pub1, _ := prv1.PublicKey()
pub2, _ := prv2.PublicKey()
kek1, _ := prv1.KEK2001(pub2, ukm)
kek2, _ := prv2.KEK2001(pub1, ukm)
if !bytes.Equal(kek1, kek2) {
t.FailNow()
}
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()
}
}
func TestRandomVKO2001(t *testing.T) {
c := CurveIdGostR34102001TestParamSet()
f := func(prvRaw1 [32]byte, prvRaw2 [32]byte, ukmRaw [8]byte) bool {
prv1, err := NewPrivateKey(c, prvRaw1[:])
if err != nil {
return false
}
prv2, err := NewPrivateKey(c, prvRaw2[:])
if err != nil {
return false
}
pub1, _ := prv1.PublicKey()
pub2, _ := prv2.PublicKey()
ukm := NewUKM(ukmRaw[:])
kek1, _ := prv1.KEK2001(pub2, ukm)
kek2, _ := prv2.KEK2001(pub1, ukm)
return bytes.Equal(kek1, kek2)
}
if err := quick.Check(f, nil); err != nil {
t.Error(err)
}
}