diff options
author | Gustav Simonsson <gustav.simonsson@gmail.com> | 2015-09-21 21:48:15 +0800 |
---|---|---|
committer | Gustav Simonsson <gustav.simonsson@gmail.com> | 2015-09-22 23:33:39 +0800 |
commit | 3340b565931e04400029da2ef2a6ac811d7fbad5 (patch) | |
tree | a09ae02a0ff7d2c3c8893b5c0cfc8660c147415b /crypto/crypto.go | |
parent | e40b447fead5ec3c4ccb133418431ea25be3c545 (diff) | |
download | dexon-3340b565931e04400029da2ef2a6ac811d7fbad5.tar dexon-3340b565931e04400029da2ef2a6ac811d7fbad5.tar.gz dexon-3340b565931e04400029da2ef2a6ac811d7fbad5.tar.bz2 dexon-3340b565931e04400029da2ef2a6ac811d7fbad5.tar.lz dexon-3340b565931e04400029da2ef2a6ac811d7fbad5.tar.xz dexon-3340b565931e04400029da2ef2a6ac811d7fbad5.tar.zst dexon-3340b565931e04400029da2ef2a6ac811d7fbad5.zip |
crypto: correct sig validation, add more unit tests
Diffstat (limited to 'crypto/crypto.go')
-rw-r--r-- | crypto/crypto.go | 15 |
1 files changed, 2 insertions, 13 deletions
diff --git a/crypto/crypto.go b/crypto/crypto.go index b3a8d730b..272050106 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -172,10 +172,10 @@ func GenerateKey() (*ecdsa.PrivateKey, error) { } func ValidateSignatureValues(v byte, r, s *big.Int) bool { - vint := uint32(v) - if r.Cmp(common.Big0) == 0 || s.Cmp(common.Big0) == 0 { + if r.Cmp(common.Big1) < 0 || s.Cmp(common.Big1) < 0 { return false } + vint := uint32(v) if r.Cmp(secp256k1n) < 0 && s.Cmp(secp256k1n) < 0 && (vint == 27 || vint == 28) { return true } else { @@ -302,17 +302,6 @@ func aesCBCDecrypt(key, cipherText, iv []byte) ([]byte, error) { } // From https://leanpub.com/gocrypto/read#leanpub-auto-block-cipher-modes -func PKCS7Pad(in []byte) []byte { - padding := 16 - (len(in) % 16) - if padding == 0 { - padding = 16 - } - for i := 0; i < padding; i++ { - in = append(in, byte(padding)) - } - return in -} - func PKCS7Unpad(in []byte) []byte { if len(in) == 0 { return nil |