From f4ba21a41a1b3ffe18ea8778d40ce64f33f74076 Mon Sep 17 00:00:00 2001
From: Roman Khimov <roman@nspcc.ru>
Date: Wed, 25 Aug 2021 20:03:40 +0300
Subject: [PATCH] keys: use (*Int).FillBytes where appropriate

Allows to avoid some allocations. Refs. #1319.
---
 pkg/crypto/keys/private_key.go | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/pkg/crypto/keys/private_key.go b/pkg/crypto/keys/private_key.go
index 3f72a6d42..6cded1914 100644
--- a/pkg/crypto/keys/private_key.go
+++ b/pkg/crypto/keys/private_key.go
@@ -155,10 +155,9 @@ func (p *PrivateKey) SignHashable(net uint32, hh hash.Hashable) []byte {
 func getSignatureSlice(curve elliptic.Curve, r, s *big.Int) []byte {
 	params := curve.Params()
 	curveOrderByteSize := params.P.BitLen() / 8
-	rBytes, sBytes := r.Bytes(), s.Bytes()
 	signature := make([]byte, curveOrderByteSize*2)
-	copy(signature[curveOrderByteSize-len(rBytes):], rBytes)
-	copy(signature[curveOrderByteSize*2-len(sBytes):], sBytes)
+	_ = r.FillBytes(signature[:curveOrderByteSize])
+	_ = s.FillBytes(signature[curveOrderByteSize:])
 
 	return signature
 }
@@ -170,9 +169,8 @@ func (p *PrivateKey) String() string {
 
 // Bytes returns the underlying bytes of the PrivateKey.
 func (p *PrivateKey) Bytes() []byte {
-	bytes := p.D.Bytes()
 	result := make([]byte, 32)
-	copy(result[32-len(bytes):], bytes)
+	_ = p.D.FillBytes(result)
 
 	return result
 }