예제 #1
0
파일: jvss.go 프로젝트: nikirill/cothority
// NewJVSS creates a new JVSS protocol instance and returns it.
func NewJVSS(node *sda.TreeNodeInstance) (sda.ProtocolInstance, error) {

	kp := &config.KeyPair{Suite: node.Suite(), Public: node.Public(), Secret: node.Private()}
	n := len(node.List())
	pk := make([]abstract.Point, n)
	for i, tn := range node.List() {
		pk[i] = tn.ServerIdentity.Public
	}
	// NOTE: T <= R <= N (for simplicity we use T = R = N; might change later)
	info := poly.Threshold{T: n, R: n, N: n}

	jv := &JVSS{
		TreeNodeInstance: node,
		keyPair:          kp,
		pubKeys:          pk,
		info:             info,
		schnorr:          new(poly.Schnorr),
		secrets:          make(map[SID]*Secret),
		ltssInit:         false,
		secretsDone:      make(chan bool, 1),
		sigChan:          make(chan *poly.SchnorrSig),
	}

	// Setup message handlers
	h := []interface{}{
		jv.handleSecInit,
		jv.handleSecConf,
		jv.handleSigReq,
		jv.handleSigResp,
	}
	err := jv.RegisterHandlers(h...)

	return jv, err
}
예제 #2
0
// NewBFTCoSiProtocol returns a new bftcosi struct
func NewBFTCoSiProtocol(n *sda.TreeNodeInstance, verify VerificationFunction) (*ProtocolBFTCoSi, error) {
	// initialize the bftcosi node/protocol-instance
	bft := &ProtocolBFTCoSi{
		TreeNodeInstance: n,
		suite:            n.Suite(),
		prepare:          cosi.NewCosi(n.Suite(), n.Private()),
		commit:           cosi.NewCosi(n.Suite(), n.Private()),
		verifyChan:       make(chan bool),
		doneProcessing:   make(chan bool, 2),
		doneSigning:      make(chan bool, 1),
		verificationFun:  verify,
		AggregatedPublic: n.Roster().Aggregate,
		threshold:        int(2.0 * math.Ceil(float64(len(n.Tree().List()))/3.0)),
	}

	// register channels
	if err := n.RegisterChannel(&bft.announceChan); err != nil {
		return nil, err
	}
	if err := n.RegisterChannel(&bft.commitChan); err != nil {
		return nil, err
	}
	if err := n.RegisterChannel(&bft.challengePrepareChan); err != nil {
		return nil, err
	}
	if err := n.RegisterChannel(&bft.challengeCommitChan); err != nil {
		return nil, err
	}
	if err := n.RegisterChannel(&bft.responseChan); err != nil {
		return nil, err
	}

	n.OnDoneCallback(bft.nodeDone)

	return bft, nil
}