]> Cypherpunks.ru repositories - gogost.git/blobdiff - src/cypherpunks.ru/gogost/gost3410/private.go
Make private key length validation working
[gogost.git] / src / cypherpunks.ru / gogost / gost3410 / private.go
index d4c5c1e9e7d8015bf67c38c39d50373063ab6596..ced3b89527e86a6568fe85d1497f1446e5eb6869 100644 (file)
@@ -1,5 +1,5 @@
 // GoGOST -- Pure Go GOST cryptographic functions library
-// Copyright (C) 2015-2016 Sergey Matveev <stargrave@stargrave.org>
+// Copyright (C) 2015-2019 Sergey Matveev <stargrave@stargrave.org>
 //
 // 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
@@ -30,11 +30,12 @@ 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))
-       copy(key, raw)
-       reverse(key)
+       for i := 0; i < len(key); i++ {
+               key[i] = raw[len(raw)-i-1]
+       }
        k := bytes2big(key)
        if k.Cmp(zero) == 0 {
                return nil, errors.New("Zero private key")