aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/crypto.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-01-23 01:12:05 +0800
committerobscuren <geffobscura@gmail.com>2015-01-23 01:12:05 +0800
commitd4cc2d3503ce7497ef0cb39456a332b25e0999b9 (patch)
tree7eefc6366630a571eeaf724d4be5972cc7e06302 /crypto/crypto.go
parentb777d6aa3f0e771ca8465924820db1848bc47402 (diff)
downloaddexon-d4cc2d3503ce7497ef0cb39456a332b25e0999b9.tar.gz
dexon-d4cc2d3503ce7497ef0cb39456a332b25e0999b9.tar.zst
dexon-d4cc2d3503ce7497ef0cb39456a332b25e0999b9.zip
Pad private key when signing & length check for hashes in sign
Diffstat (limited to 'crypto/crypto.go')
-rw-r--r--crypto/crypto.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/crypto/crypto.go b/crypto/crypto.go
index ac84c6204..3da69ea94 100644
--- a/crypto/crypto.go
+++ b/crypto/crypto.go
@@ -5,6 +5,7 @@ import (
"crypto/elliptic"
"crypto/rand"
"crypto/sha256"
+ "fmt"
"code.google.com/p/go.crypto/ripemd160"
"github.com/ethereum/go-ethereum/crypto/secp256k1"
@@ -101,7 +102,11 @@ func SigToPub(hash, sig []byte) *ecdsa.PublicKey {
}
func Sign(hash []byte, prv *ecdsa.PrivateKey) (sig []byte, err error) {
- sig, err = secp256k1.Sign(hash, prv.D.Bytes())
+ if len(hash) != 32 {
+ return nil, fmt.Errorf("hash is required to be exactly 32 bytes (%d)", len(hash))
+ }
+
+ sig, err = secp256k1.Sign(hash, ethutil.LeftPadBytes(prv.D.Bytes(), 32))
return
}