aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/signature_cgo.go
diff options
context:
space:
mode:
authorJanos Guljas <janos@resenje.org>2017-12-13 17:23:11 +0800
committerJanos Guljas <janos@resenje.org>2017-12-13 17:40:39 +0800
commit19982f946735948478b6b7e7706f1b615f171d0d (patch)
treecbacbdb6f9e6e731c2ebc17bad74e875f4d8ea8b /crypto/signature_cgo.go
parent1dc19de5da64962a98a37bbc7b93a3895d2eb6e6 (diff)
parent32516c768ec09e2a71cab5983d2c8b8ae5d92fc7 (diff)
downloaddexon-19982f946735948478b6b7e7706f1b615f171d0d.tar
dexon-19982f946735948478b6b7e7706f1b615f171d0d.tar.gz
dexon-19982f946735948478b6b7e7706f1b615f171d0d.tar.bz2
dexon-19982f946735948478b6b7e7706f1b615f171d0d.tar.lz
dexon-19982f946735948478b6b7e7706f1b615f171d0d.tar.xz
dexon-19982f946735948478b6b7e7706f1b615f171d0d.tar.zst
dexon-19982f946735948478b6b7e7706f1b615f171d0d.zip
swarm, cmd/swarm: Merge branch 'master' into multiple-ens-endpoints
Merge with changes that implement config file PR #15548. Field *EnsApi string* in swarm/api.Config is replaced with *EnsAPIs []string*. A new field *EnsDisabled bool* is added to swarm/api.Config for easy way to disable ENS resolving with config file. Signature of function swarm.NewSwarm is changed and simplified.
Diffstat (limited to 'crypto/signature_cgo.go')
-rw-r--r--crypto/signature_cgo.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/crypto/signature_cgo.go b/crypto/signature_cgo.go
index feec5e7be..381d8a1bb 100644
--- a/crypto/signature_cgo.go
+++ b/crypto/signature_cgo.go
@@ -27,10 +27,12 @@ import (
"github.com/ethereum/go-ethereum/crypto/secp256k1"
)
+// Ecrecover returns the uncompressed public key that created the given signature.
func Ecrecover(hash, sig []byte) ([]byte, error) {
return secp256k1.RecoverPubkey(hash, sig)
}
+// SigToPub returns the public key that created the given signature.
func SigToPub(hash, sig []byte) (*ecdsa.PublicKey, error) {
s, err := Ecrecover(hash, sig)
if err != nil {
@@ -58,6 +60,22 @@ func Sign(hash []byte, prv *ecdsa.PrivateKey) (sig []byte, err error) {
return secp256k1.Sign(hash, seckey)
}
+// VerifySignature checks that the given public key created signature over hash.
+// The public key should be in compressed (33 bytes) or uncompressed (65 bytes) format.
+// The signature should have the 64 byte [R || S] format.
+func VerifySignature(pubkey, hash, signature []byte) bool {
+ return secp256k1.VerifySignature(pubkey, hash, signature)
+}
+
+// DecompressPubkey parses a public key in the 33-byte compressed format.
+func DecompressPubkey(pubkey []byte) (*ecdsa.PublicKey, error) {
+ x, y := secp256k1.DecompressPubkey(pubkey)
+ if x == nil {
+ return nil, fmt.Errorf("invalid public key")
+ }
+ return &ecdsa.PublicKey{X: x, Y: y, Curve: S256()}, nil
+}
+
// S256 returns an instance of the secp256k1 curve.
func S256() elliptic.Curve {
return secp256k1.S256()