aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/crypto.go
diff options
context:
space:
mode:
authorGustav Simonsson <gustav.simonsson@gmail.com>2015-06-02 02:27:20 +0800
committerGustav Simonsson <gustav.simonsson@gmail.com>2015-06-02 03:06:52 +0800
commit32e1b104f8fbc0f80bf2b6a93492aa01fa323e35 (patch)
treea9725f648bdd47d3e5b72b21ddf728e90656a974 /crypto/crypto.go
parent5b14fdb94b61af9f17f53593766a706c9780a7be (diff)
downloaddexon-32e1b104f8fbc0f80bf2b6a93492aa01fa323e35.tar.gz
dexon-32e1b104f8fbc0f80bf2b6a93492aa01fa323e35.tar.zst
dexon-32e1b104f8fbc0f80bf2b6a93492aa01fa323e35.zip
Add EC signature validations before call to libsecp256k1
Diffstat (limited to 'crypto/crypto.go')
-rw-r--r--crypto/crypto.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/crypto/crypto.go b/crypto/crypto.go
index 4bbd62f7f..d5291fe1d 100644
--- a/crypto/crypto.go
+++ b/crypto/crypto.go
@@ -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 {