]> Cypherpunks.ru repositories - gogost.git/commitdiff
Make private key length validation working
authorSergey Matveev <stargrave@stargrave.org>
Wed, 17 Jul 2019 15:00:46 +0000 (18:00 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Wed, 17 Jul 2019 15:18:21 +0000 (18:18 +0300)
src/cypherpunks.ru/gogost/gost3410/2001_test.go
src/cypherpunks.ru/gogost/gost3410/2012_test.go
src/cypherpunks.ru/gogost/gost3410/private.go

index c529b89b9cc07e33b2e97b637475765c5aaa8172..9e1910d7825c091503131a3c4d616202dbfdec5e 100644 (file)
@@ -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()
        }
index c2942dd630498ae04f2ee8fd0df69090536062d3..1814691ae210b09e33ef77f10dcb0fb1f0b4a3bc 100644 (file)
@@ -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
index 5f41ddc50b89b9ce805dfb0896509e2d6bd7ff2b..ced3b89527e86a6568fe85d1497f1446e5eb6869 100644 (file)
@@ -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++ {