crypto: correct sig validation, add more unit tests

This commit is contained in:
Gustav Simonsson
2015-09-21 15:48:15 +02:00
parent e40b447fea
commit 3340b56593
2 changed files with 169 additions and 27 deletions

View File

@ -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