From 76eca07961961786f0e70d5a5f5b703013a9de2b Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 25 Aug 2021 19:58:01 +0300 Subject: [PATCH] keys: simplify NewPrivateKeyFrom* functions Avoid allocating a slice and doing double calculations. --- pkg/crypto/keys/private_key.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/crypto/keys/private_key.go b/pkg/crypto/keys/private_key.go index f27f92145..3f72a6d42 100644 --- a/pkg/crypto/keys/private_key.go +++ b/pkg/crypto/keys/private_key.go @@ -64,7 +64,7 @@ func NewPrivateKeyFromBytes(b []byte) (*PrivateKey, error) { d = new(big.Int).SetBytes(b) ) - x, y := c.ScalarBaseMult(d.Bytes()) + x, y := c.ScalarBaseMult(b) return &PrivateKey{ ecdsa.PrivateKey{ @@ -85,7 +85,7 @@ func NewPrivateKeyFromASN1(b []byte) (*PrivateKey, error) { if err != nil { return nil, err } - return NewPrivateKeyFromBytes(privkey.D.Bytes()) + return &PrivateKey{*privkey}, nil } // PublicKey derives the public key from the private key.