From: Sergey Matveev Date: Wed, 17 Jul 2019 14:51:46 +0000 (+0300) Subject: Excess copy() usage X-Git-Tag: 3.0~8 X-Git-Url: http://www.git.cypherpunks.ru/?p=gogost.git;a=commitdiff_plain;h=ba18f430469e7aa33807ec53167250035fa890e8 Excess copy() usage --- diff --git a/src/cypherpunks.ru/gogost/gost3410/private.go b/src/cypherpunks.ru/gogost/gost3410/private.go index 2af8a4a..5f41ddc 100644 --- a/src/cypherpunks.ru/gogost/gost3410/private.go +++ b/src/cypherpunks.ru/gogost/gost3410/private.go @@ -33,8 +33,9 @@ func NewPrivateKey(curve *Curve, mode Mode, raw []byte) (*PrivateKey, error) { 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") diff --git a/src/cypherpunks.ru/gogost/gost3410/public.go b/src/cypherpunks.ru/gogost/gost3410/public.go index 6af21af..9589ef8 100644 --- a/src/cypherpunks.ru/gogost/gost3410/public.go +++ b/src/cypherpunks.ru/gogost/gost3410/public.go @@ -29,12 +29,13 @@ type PublicKey struct { } func NewPublicKey(curve *Curve, mode Mode, raw []byte) (*PublicKey, error) { - if len(raw) != 2*int(mode) { + key := make([]byte, 2*int(mode)) + if len(raw) != len(key) { return nil, errors.New("Invalid public key length") } - key := make([]byte, 2*int(mode)) - copy(key, raw) - reverse(key) + for i := 0; i < len(key); i++ { + key[i] = raw[len(raw)-i-1] + } return &PublicKey{ curve, mode, diff --git a/src/cypherpunks.ru/gogost/gost3410/ukm.go b/src/cypherpunks.ru/gogost/gost3410/ukm.go index 4eda4fc..4b04d1c 100644 --- a/src/cypherpunks.ru/gogost/gost3410/ukm.go +++ b/src/cypherpunks.ru/gogost/gost3410/ukm.go @@ -22,7 +22,8 @@ import ( func NewUKM(raw []byte) *big.Int { t := make([]byte, len(raw)) - copy(t, raw) - reverse(t) + for i := 0; i < len(t); i++ { + t[i] = raw[len(raw)-i-1] + } return bytes2big(t) }