Add EC signature validations before call to libsecp256k1

This commit is contained in:
Gustav Simonsson
2015-06-01 20:27:20 +02:00
parent 5b14fdb94b
commit 32e1b104f8
3 changed files with 29 additions and 22 deletions

View File

@ -10,6 +10,7 @@ import (
"fmt"
"io"
"io/ioutil"
"math/big"
"os"
"encoding/hex"
@ -151,6 +152,19 @@ func GenerateKey() (*ecdsa.PrivateKey, error) {
return ecdsa.GenerateKey(S256(), rand.Reader)
}
func ValidateSignatureValues(v byte, r, s *big.Int) bool {
secp256k1n := common.String2Big("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141")
vint := uint32(v)
if r.Cmp(common.Big0) == 0 || s.Cmp(common.Big0) == 0 {
return false
}
if r.Cmp(secp256k1n) < 0 && s.Cmp(secp256k1n) < 0 && (vint == 27 || vint == 28) {
return true
} else {
return false
}
}
func SigToPub(hash, sig []byte) (*ecdsa.PublicKey, error) {
s, err := Ecrecover(hash, sig)
if err != nil {