From: Sergey Matveev Date: Wed, 17 Jul 2019 15:00:46 +0000 (+0300) Subject: Make private key length validation working X-Git-Tag: 3.0~7 X-Git-Url: http://www.git.cypherpunks.ru/?p=gogost.git;a=commitdiff_plain;h=3f0105abe94dc598a5aa321abb6437f5b492d675 Make private key length validation working --- diff --git a/src/cypherpunks.ru/gogost/gost3410/2001_test.go b/src/cypherpunks.ru/gogost/gost3410/2001_test.go index c529b89..9e1910d 100644 --- a/src/cypherpunks.ru/gogost/gost3410/2001_test.go +++ b/src/cypherpunks.ru/gogost/gost3410/2001_test.go @@ -161,7 +161,9 @@ func BenchmarkVerify2001(b *testing.B) { func TestPrvEqualsTo1(t *testing.T) { c := CurveIdGostR34102001TestParamSet() - prv, err := NewPrivateKey(c, Mode2001, []byte{0x01}) + prvRaw := make([]byte, int(Mode2001)) + prvRaw[len(prvRaw)-1] = 1 + prv, err := NewPrivateKey(c, Mode2001, prvRaw) if err != nil { t.FailNow() } diff --git a/src/cypherpunks.ru/gogost/gost3410/2012_test.go b/src/cypherpunks.ru/gogost/gost3410/2012_test.go index c2942dd..1814691 100644 --- a/src/cypherpunks.ru/gogost/gost3410/2012_test.go +++ b/src/cypherpunks.ru/gogost/gost3410/2012_test.go @@ -176,11 +176,11 @@ func TestGCL3Vectors(t *testing.T) { func TestRandom2012(t *testing.T) { c := CurveIdtc26gost341012512paramSetA() - f := func(data [31]byte, digest [64]byte) bool { + f := func(prvRaw [64 - 1]byte, digest [64]byte) bool { prv, err := NewPrivateKey( c, Mode2012, - append([]byte{0xde}, data[:]...), + append([]byte{0xde}, prvRaw[:]...), ) if err != nil { return false diff --git a/src/cypherpunks.ru/gogost/gost3410/private.go b/src/cypherpunks.ru/gogost/gost3410/private.go index 5f41ddc..ced3b89 100644 --- a/src/cypherpunks.ru/gogost/gost3410/private.go +++ b/src/cypherpunks.ru/gogost/gost3410/private.go @@ -30,7 +30,7 @@ type PrivateKey struct { func NewPrivateKey(curve *Curve, mode Mode, raw []byte) (*PrivateKey, error) { if len(raw) != int(mode) { - errors.New("Invalid private key length") + return nil, errors.New("Invalid private key length") } key := make([]byte, int(mode)) for i := 0; i < len(key); i++ {