sign

package
v0.0.0-...-3b8f57b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2015 License: GPL-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Default Signature involves creating Merkle Trees
	MerkleTree = iota
	// Basic Signature removes all Merkle Trees
	// Collective public keys are still created and can be used
	PubKey
	// Basic Signature on aggregated votes
	Voter
)
View Source
const FIRST_ROUND int = 1 // start counting rounds at 1

Variables

View Source
var ChangingViewError error = errors.New("In the process of changing view")
View Source
var DEBUG bool // to avoid verifying paths and signatures all the time
View Source
var ErrImposedFailure error = errors.New("failure imposed")
View Source
var ErrPastRound error = errors.New("round number already passed")
View Source
var ErrUnknownMessageType error = errors.New("received message of unknown type")
View Source
var ErrViewRejected error = errors.New("view Rejected: not all nodes accepted view")
View Source
var GOSSIP_TIME time.Duration = 3 * ROUND_TIME
View Source
var HEARTBEAT = ROUND_TIME + ROUND_TIME/2
View Source
var MAX_WILLING_TO_WAIT time.Duration = 50 * time.Second
View Source
var ROUND_TIME time.Duration = 1 * time.Second

Constants we expect might be used by other packages TODO: can this be replaced by the application using the signer?

Functions

func ElGamalVerify

func ElGamalVerify(suite abstract.Suite, message []byte, publicKey abstract.Point,
	sig BasicSig) error

func NewSigningMessage

func NewSigningMessage() interface{}

Types

type AddVote

type AddVote struct {
	View   int    // view number when we want add to take place
	Name   string // who we want to add
	Parent string // our parent currently
}

type AnnouncementMessage

type AnnouncementMessage struct {
	LogTest []byte // TODO: change LogTest to Messg
	Round   int

	// VoteRequest *VoteRequest
	Vote *Vote // Vote Request (propose)
}

Broadcasted message initiated and signed by proposer

type BasicSig

type BasicSig struct {
	C abstract.Secret // challenge
	R abstract.Secret // response
}

A basic, verifiable signature

func ElGamalSign

func ElGamalSign(suite abstract.Suite, random cipher.Stream, message []byte,
	privateKey abstract.Secret) BasicSig

This simplified implementation of ElGamal Signatures is based on crypto/anon/sig.go

type ByVoteResponse

type ByVoteResponse []*VoteResponse

for sorting arrays of VoteResponse

func (ByVoteResponse) Len

func (vr ByVoteResponse) Len() int

func (ByVoteResponse) Less

func (vr ByVoteResponse) Less(i, j int) bool

func (ByVoteResponse) Swap

func (vr ByVoteResponse) Swap(i, j int)

type CatchUpRequest

type CatchUpRequest struct {
	Index int // index of requested vote
}

type CatchUpResponse

type CatchUpResponse struct {
	Vote *Vote
}

type ChallengeMessage

type ChallengeMessage struct {
	C abstract.Secret // challenge

	// Depth  byte
	MTRoot hashid.HashId // the very root of the big Merkle Tree
	Proof  proof.Proof   // Merkle Path of Proofs from root to us

	// CountedVotes *CountedVotes //  CountedVotes contains the whole tree's votes
	Vote *Vote // Vote Confirmerd/ Rejected (accept)

	Round int
}

type CommitFunc

type CommitFunc func(view int) []byte

Returns commitment contribution for a round

type CommitmentMessage

type CommitmentMessage struct {
	V     abstract.Point // commitment Point
	V_hat abstract.Point // product of subtree participating nodes' commitment points
	X_hat abstract.Point // product of subtree participating nodes' public keys

	MTRoot hashid.HashId // root of Merkle (sub)Tree

	// public keys of children servers that did not respond to
	// annoucement from root
	ExceptionList []abstract.Point

	// CountedVotes *CountedVotes // CountedVotes contains a subtree's votes
	Vote *Vote // Vote Response (promise)

	Round int
}

type Count

type Count struct {
	Responses []*VoteResponse // vote responses from descendants
	For       int             // number of votes for
	Against   int             // number of votes against
}

When sent up in a Committment Message CountedVotes contains a subtree's votes When sent down in a Challenge Message CountedVotes contains the whole tree's votes

type DoneFunc

type DoneFunc func(view int, SNRoot hashid.HashId, LogHash hashid.HashId, p proof.Proof)

Called at the end of a round Allows client of Signer to receive signature, proof, and error via RPC

type ErrorMessage

type ErrorMessage struct {
	Err string
}

type GroupChangedMessage

type GroupChangedMessage struct {
	V *Vote
	// if vote not accepted rest of fields are nil
	HostList []string
}

type MessageType

type MessageType int
const (
	Unset MessageType = iota
	Announcement
	Commitment
	Challenge
	Response
	CatchUpReq
	CatchUpResp
	GroupChange
	GroupChanged
	StatusConnections
	CloseAll
	Default // for internal use
	Error
)

func (MessageType) String

func (m MessageType) String() string

type Node

type Node struct {
	coconet.Host

	// Signing Node will Fail at FailureRate probability
	FailureRate         int
	FailAsRootEvery     int
	FailAsFollowerEvery int

	Rand *rand.Rand

	Type   Type
	Height int

	HostList []string

	PubKey  abstract.Point  // long lasting public key
	PrivKey abstract.Secret // long lasting private key

	Rounds     map[int]*Round
	Round      int // *only* used by Root( by annoucer)
	RoundTypes []RoundType

	LastSeenRound int // largest round number I have seen
	RoundsAsRoot  int // latest continuous streak of rounds with sn root

	AnnounceLock sync.Mutex

	CommitFunc CommitFunc
	DoneFunc   DoneFunc

	LogTest []byte // for testing purposes

	RoundsPerView int

	ChangingView bool // TRUE if node is currently engaged in changing the view

	ViewNo int

	VoteLog         *VoteLog // log of all confirmed votes, useful for replay
	LastSeenVote    int64    // max of all Highest Votes we've seen, and our last commited vote
	LastAppliedVote int64    // last vote we have committed to our log

	Actions map[int][]*Vote
	// contains filtered or unexported fields
}

func NewKeyedNode

func NewKeyedNode(hn coconet.Host, suite abstract.Suite, PrivKey abstract.Secret) *Node

Create new signing node that incorporates a given private key

func NewNode

func NewNode(hn coconet.Host, suite abstract.Suite, random cipher.Stream) *Node

func (*Node) Accept

func (sn *Node) Accept(view int, chm *ChallengeMessage) error

func (*Node) Accepted

func (sn *Node) Accepted(view, Round int, sm *SigningMessage) error

func (*Node) AddAction

func (sn *Node) AddAction(view int, v *Vote)

func (*Node) AddChildrenMerkleRoots

func (sn *Node) AddChildrenMerkleRoots(Round int)

func (*Node) AddLocalMerkleRoot

func (sn *Node) AddLocalMerkleRoot(view, Round int)

func (*Node) AddPeer

func (sn *Node) AddPeer(conn string, PubKey abstract.Point)

func (*Node) AddSelf

func (sn *Node) AddSelf(parent string) error

func (*Node) AddVotes

func (sn *Node) AddVotes(Round int, v *Vote)

Cast on vote for Vote

func (*Node) Announce

func (sn *Node) Announce(view int, am *AnnouncementMessage) error

func (*Node) ApplyAction

func (sn *Node) ApplyAction(view int, v *Vote)

func (*Node) ApplyVote

func (sn *Node) ApplyVote(v *Vote)

func (*Node) ApplyVotes

func (sn *Node) ApplyVotes(ch chan *Vote)

func (*Node) CatchUp

func (sn *Node) CatchUp(vi int, from string)

func (*Node) Challenge

func (sn *Node) Challenge(view int, chm *ChallengeMessage) error

initiated by root, propagated by all others

func (*Node) ChangeView

func (sn *Node) ChangeView(vcv *ViewChangeVote)

func (*Node) Close

func (sn *Node) Close()

func (*Node) CloseAll

func (sn *Node) CloseAll(view int) error

func (*Node) Commit

func (sn *Node) Commit(view, Round int, sm *SigningMessage) error

func (*Node) CommitedFor

func (sn *Node) CommitedFor(round *Round) bool

func (*Node) ComputeCombinedMerkleRoot

func (sn *Node) ComputeCombinedMerkleRoot(view, Round int)

func (*Node) DefaultTimeout

func (sn *Node) DefaultTimeout() time.Duration

func (*Node) Done

func (sn *Node) Done() chan int

func (*Node) FillInWithDefaultMessages

func (sn *Node) FillInWithDefaultMessages(view int, messgs []*SigningMessage) []*SigningMessage

Figure out which kids did not submit messages Add default messages to messgs, one per missing child as to make it easier to identify and add them to exception lists in one place

func (*Node) FinalizeCommits

func (sn *Node) FinalizeCommits(view int, Round int) error

Called *only* by root node after receiving all commits

func (*Node) GenSetPool

func (sn *Node) GenSetPool()

func (*Node) HashLog

func (sn *Node) HashLog(Round int) error

Called when log for round if full and ready to be hashed

func (*Node) Hostlist

func (sn *Node) Hostlist() []string

func (*Node) LastRound

func (sn *Node) LastRound() int

func (*Node) Listen

func (sn *Node) Listen() error

Start listening for messages coming from parent(up)

func (*Node) NotifyOfAction

func (sn *Node) NotifyOfAction(view int, v *Vote)

func (*Node) Promise

func (sn *Node) Promise(view, Round int, sm *SigningMessage) error

func (*Node) Propose

func (sn *Node) Propose(view int, am *AnnouncementMessage, from string) error

A propose for a view change would come on current view + sth when we receive view change message on a future view, we must be caught up, create that view and apply actions on it

func (*Node) PutUpError

func (sn *Node) PutUpError(view int, err error)

func (*Node) ReceivedHeartbeat

func (sn *Node) ReceivedHeartbeat(view int)

func (*Node) RegisterAnnounceFunc

func (sn *Node) RegisterAnnounceFunc(cf CommitFunc)

func (*Node) RegisterDoneFunc

func (sn *Node) RegisterDoneFunc(df DoneFunc)

func (*Node) RemoveSelf

func (sn *Node) RemoveSelf() error

func (*Node) Respond

func (sn *Node) Respond(view, Round int, sm *SigningMessage) error

func (*Node) RootFor

func (sn *Node) RootFor(view int) string

Returns name of node who should be the root for the next view round robin is used on the array of host names to determine the next root

func (*Node) SendChildrenChallenges

func (sn *Node) SendChildrenChallenges(view int, chm *ChallengeMessage) error

Send children challenges

func (*Node) SendChildrenChallengesProofs

func (sn *Node) SendChildrenChallengesProofs(view int, chm *ChallengeMessage) error

Create Personalized Merkle Proofs for children servers Send Personalized Merkle Proofs to children servers

func (*Node) SendLocalMerkleProof

func (sn *Node) SendLocalMerkleProof(view int, chm *ChallengeMessage) error

Create Merkle Proof for local client (timestamp server) Send Merkle Proof to local client (timestamp server)

func (*Node) SeparateProofs

func (sn *Node) SeparateProofs(proofs []proof.Proof, leaves []hashid.HashId, Round int)

Identify which proof corresponds to which leaf Needed given that the leaves are sorted before passed to the function that create the Merkle Tree and its Proofs

func (*Node) SetAccountableRound

func (sn *Node) SetAccountableRound(Round int)

*only* called by root node

func (sn *Node) SetBackLink(Round int)

func (*Node) SetFailureRate

func (sn *Node) SetFailureRate(v int)

func (*Node) SetLastSeenRound

func (sn *Node) SetLastSeenRound(round int)

func (*Node) SetTimeout

func (sn *Node) SetTimeout(t time.Duration)

func (*Node) SetupProposal

func (sn *Node) SetupProposal(view int, am *AnnouncementMessage, from string) error

func (*Node) ShouldIFail

func (sn *Node) ShouldIFail(phase string) bool

func (*Node) StartAnnouncement

func (sn *Node) StartAnnouncement(am *AnnouncementMessage) error

func (*Node) StartGossip

func (sn *Node) StartGossip()

func (*Node) StartSigningRound

func (sn *Node) StartSigningRound() error

func (*Node) StartVotingRound

func (sn *Node) StartVotingRound(v *Vote) error

func (*Node) StatusConnections

func (sn *Node) StatusConnections(view int, am *AnnouncementMessage) error

func (*Node) StopHeartbeat

func (sn *Node) StopHeartbeat()

func (*Node) Suite

func (sn *Node) Suite() abstract.Suite

func (*Node) TimeForViewChange

func (sn *Node) TimeForViewChange() bool

func (*Node) Timeout

func (sn *Node) Timeout() time.Duration

func (*Node) TryFailure

func (sn *Node) TryFailure(view, Round int) error

func (*Node) TryRootFailure

func (sn *Node) TryRootFailure(view, Round int) bool

func (*Node) TryViewChange

func (sn *Node) TryViewChange(view int) error

func (*Node) UpdateTimeout

func (sn *Node) UpdateTimeout(t ...time.Duration)

func (*Node) VerifyAllProofs

func (sn *Node) VerifyAllProofs(view int, chm *ChallengeMessage, proofForClient proof.Proof)

func (*Node) VerifyResponses

func (sn *Node) VerifyResponses(view, Round int) error

Called by every node after receiving aggregate responses from descendants

func (*Node) ViewChangeCh

func (sn *Node) ViewChangeCh() chan string

type RemoveVote

type RemoveVote struct {
	View   int    // view number when we want add to take place
	Name   string // who we want to remove
	Parent string // our parent currently
}

type ResponseMessage

type ResponseMessage struct {
	R_hat abstract.Secret // response

	// public keys of children servers that did not respond to
	// challenge from root
	ExceptionList []abstract.Point
	// cummulative point commits of nodes that failed after commit
	ExceptionV_hat abstract.Point
	// cummulative public keys of nodes that failed after commit
	ExceptionX_hat abstract.Point

	Vote *Vote // Vote Ack/Nack in thr log (ack/nack)

	Round int
}

type Round

type Round struct {
	Log       SNLog // round lasting log structure
	HashedLog []byte

	X_hat abstract.Point // aggregate of public keys

	Commits   []*SigningMessage
	Responses []*SigningMessage

	// own big merkle subtree
	MTRoot     hashid.HashId   // mt root for subtree, passed upwards
	Leaves     []hashid.HashId // leaves used to build the merkle subtre
	LeavesFrom []string        // child names for leaves

	// mtRoot before adding HashedLog
	LocalMTRoot hashid.HashId

	// merkle tree roots of children in strict order
	CMTRoots     []hashid.HashId
	CMTRootNames []string
	Proofs       map[string]proof.Proof

	// round-lasting public keys of children servers that did not
	// respond to latest commit or respond phase, in subtree
	ExceptionList []abstract.Point
	// combined point commits of children servers in subtree
	ChildV_hat map[string]abstract.Point
	// combined public keys of children servers in subtree
	ChildX_hat map[string]abstract.Point

	BackLink hashid.HashId
	AccRound []byte

	Vote *Vote
	// contains filtered or unexported fields
}

func NewRound

func NewRound(suite abstract.Suite) *Round

type RoundType

type RoundType int
const (
	EmptyRT RoundType = iota
	ViewChangeRT
	AddRT
	RemoveRT
	ShutdownRT
	NoOpRT
	SigningRT
)

func (RoundType) String

func (rt RoundType) String() string

type SNLog

type SNLog struct {
	V     abstract.Point // round lasting commitment point
	V_hat abstract.Point // aggregate of commit points

	// merkle tree roots of children in strict order
	CMTRoots hashid.HashId // concatenated hash ids of children
	Suite    abstract.Suite
	// contains filtered or unexported fields
}

Signing Node Log for a round For Marshaling and Unrmarshaling to work smoothly crypto fields must appear first in the structure

func (SNLog) MarshalBinary

func (snLog SNLog) MarshalBinary() ([]byte, error)

func (*SNLog) UnmarshalBinary

func (snLog *SNLog) UnmarshalBinary(data []byte) error

type Signer

type Signer interface {
	Name() string
	IsRoot(view int) bool
	Suite() abstract.Suite
	StartSigningRound() error
	StartVotingRound(v *Vote) error

	LastRound() int       // last round number seen by Signer
	SetLastSeenRound(int) // impose change in round numbering

	Hostlist() []string

	// registers a commitment function to be called
	// at the start of every round
	RegisterAnnounceFunc(cf CommitFunc)

	RegisterDoneFunc(df DoneFunc)

	// Allows user of Signer to inform Signer to run with simulated failures
	// As to test robustness of Signer
	SetFailureRate(val int)

	ViewChangeCh() chan string

	Close()
	Listen() error

	AddSelf(host string) error
	RemoveSelf() error
}

todo: see where Signer should be located

type SigningMessage

type SigningMessage struct {
	Type         MessageType
	Am           *AnnouncementMessage
	Com          *CommitmentMessage
	Chm          *ChallengeMessage
	Rm           *ResponseMessage
	Cureq        *CatchUpRequest
	Curesp       *CatchUpResponse
	Vrm          *VoteRequestMessage
	Gcm          *GroupChangedMessage
	Err          *ErrorMessage
	From         string
	View         int
	LastSeenVote int // highest vote ever seen and commited in log, used for catch-up
}

Signing Messages are used for all communications between servers It is important for encoding/ decoding for type to be kept as first field

func (*SigningMessage) MarshalBinary

func (sm *SigningMessage) MarshalBinary() ([]byte, error)

func (*SigningMessage) UnmarshalBinary

func (sm *SigningMessage) UnmarshalBinary(data []byte) error

type Type

type Type int // used by other modules as coll_sign.Type

type ViewChangeVote

type ViewChangeVote struct {
	View   int    // view number we want to switch to
	Parent string // our parent currently
	Root   string // the root for the new view

}

type Vote

type Vote struct {
	Index int
	View  int
	Round int

	Type VoteType
	Av   *AddVote
	Rv   *RemoveVote
	Vcv  *ViewChangeVote

	Count     *Count
	Confirmed bool
}

Multi-Purpose Vote embeds Action to be voted on, aggregated votes, and decison when embedded in Announce it equals Vote Request (propose) when embedded in Commit it equals Vote Response (promise) when embedded in Challenge it equals Vote Confirmed (accept) when embedded in Response it equals Vote Ack/ Nack (ack/ nack)

func (*Vote) MarshalBinary

func (v *Vote) MarshalBinary() ([]byte, error)

func (*Vote) UnmarshalBinary

func (v *Vote) UnmarshalBinary(data []byte) error

type VoteLog

type VoteLog struct {
	Entries []*Vote
	Last    int // last set entry
	// contains filtered or unexported fields
}

func NewVoteLog

func NewVoteLog() *VoteLog

func (*VoteLog) Get

func (vl *VoteLog) Get(index int) *Vote

func (*VoteLog) Put

func (vl *VoteLog) Put(index int, v *Vote)

func (*VoteLog) Stream

func (vl *VoteLog) Stream() chan *Vote

type VoteRequestMessage

type VoteRequestMessage struct {
	Vote *Vote
}

type VoteResponse

type VoteResponse struct {
	Name     string // name of the responder
	Accepted bool
	// signature proves ownership of vote and
	// shows that it was emitted during a specifc Round
	Sig BasicSig
}

type VoteType

type VoteType int
const (
	DefaultVT VoteType = iota
	ViewChangeVT
	AddVT
	RemoveVT
	ShutdownVT
	NoOpVT
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL