Use schnorr signature for signing the messages

pull/55/head
Rongjian Lan 6 years ago
parent b32dfa211b
commit fe645f16d4
  1. 9
      consensus/consensus.go
  2. 11
      consensus/consensus_leader.go
  3. 4
      consensus/consensus_validator.go

@ -8,6 +8,7 @@ import (
"harmony-benchmark/crypto"
"harmony-benchmark/log"
"harmony-benchmark/p2p"
"kyber/sign/schnorr"
"regexp"
"strconv"
"sync"
@ -145,6 +146,14 @@ func NewConsensus(ip, port, ShardID string, peers []p2p.Peer, leader p2p.Peer) *
return &consensus
}
func (consensus *Consensus) signMessage(message []byte) []byte {
signature, err := schnorr.Sign(crypto.Ed25519Curve, consensus.priKey, message)
if err != nil {
panic("Failed to sign message with Schnorr signature.")
}
return signature
}
// Reset the state of the consensus
func (consensus *Consensus) ResetState() {
consensus.state = FINISHED

@ -2,7 +2,6 @@ package consensus
import (
"bytes"
"crypto/sha256"
"encoding/binary"
"encoding/gob"
"github.com/dedis/kyber"
@ -115,18 +114,12 @@ func (consensus *Consensus) constructAnnounceMessage() []byte {
buffer.Write(fourBytes)
// 64 byte of signature on previous data
signature := signMessage(buffer.Bytes())
signature := consensus.signMessage(buffer.Bytes())
buffer.Write(signature)
return proto_consensus.ConstructConsensusMessage(proto_consensus.ANNOUNCE, buffer.Bytes())
}
func signMessage(message []byte) []byte {
// TODO: implement real ECC signature
mockSignature := sha256.Sum256(message)
return append(mockSignature[:], mockSignature[:]...)
}
// Processes the commit message sent from validators
func (consensus *Consensus) processCommitMessage(payload []byte) {
//#### Read payload data
@ -225,7 +218,7 @@ func (consensus *Consensus) constructChallengeMessage() []byte {
buffer.Write(getChallenge(aggCommitment, consensus.bitmap.AggregatePublic, buffer.Bytes()[:36])) // message contains consensus id and block hash for now.
// 64 byte of signature on previous data
signature := signMessage(buffer.Bytes())
signature := consensus.signMessage(buffer.Bytes())
buffer.Write(signature)
return proto_consensus.ConstructConsensusMessage(proto_consensus.CHALLENGE, buffer.Bytes())

@ -163,7 +163,7 @@ func (consensus *Consensus) constructCommitMessage() (secret kyber.Scalar, commi
commitment.MarshalTo(buffer)
// 64 byte of signature on previous data
signature := signMessage(buffer.Bytes())
signature := consensus.signMessage(buffer.Bytes())
buffer.Write(signature)
return secret, proto_consensus.ConstructConsensusMessage(proto_consensus.COMMIT, buffer.Bytes())
@ -322,7 +322,7 @@ func (consensus *Consensus) constructResponseMessage() []byte {
buffer.Write(response)
// 64 byte of signature on previous data
signature := signMessage(buffer.Bytes())
signature := consensus.signMessage(buffer.Bytes())
buffer.Write(signature)
return proto_consensus.ConstructConsensusMessage(proto_consensus.RESPONSE, buffer.Bytes())

Loading…
Cancel
Save