Skip to content

Commit

Permalink
Optimize ES (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg authored May 9, 2020
1 parent 5cd2d23 commit 1e3874f
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions algo_es.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,18 @@ func (h esAlg) Sign(payload []byte) ([]byte, error) {
if err != nil {
return nil, err
}
curveBits := h.privateKey.Curve.Params().BitSize

curveBits := h.privateKey.Curve.Params().BitSize
keyBytes := curveBits / 8
if curveBits%8 > 0 {
keyBytes++
}

// Serialize r and s into big-endian byte slices and round up size to keyBytes.
rb := r.Bytes()
rbPadded := make([]byte, keyBytes)
copy(rbPadded[keyBytes-len(rb):], rb)

sb := s.Bytes()
sbPadded := make([]byte, keyBytes)
copy(sbPadded[keyBytes-len(sb):], sb)

out := append(rbPadded, sbPadded...)

return out, nil
rBytes, sBytes := r.Bytes(), s.Bytes()
signature := make([]byte, keyBytes*2)
copy(signature[keyBytes-len(rBytes):], rBytes)
copy(signature[keyBytes*2-len(sBytes):], sBytes)
return signature, nil
}

func (h esAlg) Verify(payload, signature []byte) error {
Expand Down

0 comments on commit 1e3874f

Please sign in to comment.