From b7084e1c92e4713b20a126a7708c2153c13bb573 Mon Sep 17 00:00:00 2001 From: Oleg Kovalov Date: Fri, 31 Jul 2020 12:59:29 +0200 Subject: [PATCH] Optimize ES --- algo_es.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/algo_es.go b/algo_es.go index 2474fd8..7658530 100644 --- a/algo_es.go +++ b/algo_es.go @@ -70,7 +70,7 @@ func (h esAlg) Algorithm() Algorithm { } func (h esAlg) SignSize() int { - return 2 * h.curveBits + return (h.privateKey.Curve.Params().BitSize + 7) / 4 } func (h esAlg) Sign(payload []byte) ([]byte, error) { @@ -84,11 +84,7 @@ func (h esAlg) Sign(payload []byte) ([]byte, error) { return nil, err } - curveBits := h.privateKey.Curve.Params().BitSize - keyBytes := curveBits / 8 - if curveBits%8 > 0 { - keyBytes++ - } + keyBytes := h.SignSize() / 2 rBytes, sBytes := r.Bytes(), s.Bytes() signature := make([]byte, keyBytes*2)