aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/crypto.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-04-15 18:19:46 +0800
committerGitHub <noreply@github.com>2019-04-15 18:19:46 +0800
commit4a8d6480f7ab074bc032d68df6ee8df5876ef3cc (patch)
tree54fdb27d6254ecc56f27b7819e9e554c2b1e9f63 /vendor/github.com/dexon-foundation/dexon-consensus/core/utils/crypto.go
parentd77c1aa22cb6f2b76af3edf4995159b843838441 (diff)
downloaddexon-4a8d6480f7ab074bc032d68df6ee8df5876ef3cc.tar
dexon-4a8d6480f7ab074bc032d68df6ee8df5876ef3cc.tar.gz
dexon-4a8d6480f7ab074bc032d68df6ee8df5876ef3cc.tar.bz2
dexon-4a8d6480f7ab074bc032d68df6ee8df5876ef3cc.tar.lz
dexon-4a8d6480f7ab074bc032d68df6ee8df5876ef3cc.tar.xz
dexon-4a8d6480f7ab074bc032d68df6ee8df5876ef3cc.tar.zst
dexon-4a8d6480f7ab074bc032d68df6ee8df5876ef3cc.zip
core: implement DKG success (#362)
* vendor: sync to latest core * core: implmenet dkg success * cmd: govtool: add DKGSuccess
Diffstat (limited to 'vendor/github.com/dexon-foundation/dexon-consensus/core/utils/crypto.go')
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/utils/crypto.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/crypto.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/crypto.go
index 496944dab..42ee6122e 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/crypto.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/crypto.go
@@ -325,6 +325,19 @@ func hashDKGFinalize(final *typesDKG.Finalize) common.Hash {
)
}
+func hashDKGSuccess(success *typesDKG.Success) common.Hash {
+ binaryRound := make([]byte, 8)
+ binary.LittleEndian.PutUint64(binaryRound, success.Round)
+ binaryReset := make([]byte, 8)
+ binary.LittleEndian.PutUint64(binaryReset, success.Reset)
+
+ return crypto.Keccak256Hash(
+ success.ProposerID.Hash[:],
+ binaryRound,
+ binaryReset,
+ )
+}
+
// VerifyDKGFinalizeSignature verifies DKGFinalize signature.
func VerifyDKGFinalizeSignature(
final *typesDKG.Finalize) (bool, error) {
@@ -339,6 +352,20 @@ func VerifyDKGFinalizeSignature(
return true, nil
}
+// VerifyDKGSuccessSignature verifies DKGSuccess signature.
+func VerifyDKGSuccessSignature(
+ success *typesDKG.Success) (bool, error) {
+ hash := hashDKGSuccess(success)
+ pubKey, err := crypto.SigToPub(hash, success.Signature)
+ if err != nil {
+ return false, err
+ }
+ if success.ProposerID != types.NewNodeID(pubKey) {
+ return false, nil
+ }
+ return true, nil
+}
+
// Rehash hashes the hash again and again and again...
func Rehash(hash common.Hash, count uint) common.Hash {
result := hash