예제 #1
0
파일: api.go 프로젝트: dedis/cothority
// ProposeVote calls the 'accept'-vote on the current propose-configuration
func (i *Identity) ProposeVote(accept bool) onet.ClientError {
	log.Lvl3("Voting proposal")
	if i.Proposed == nil {
		return onet.NewClientErrorCode(ErrorConfigMissing, "No proposed config")
	}
	log.Lvlf3("Voting %t on %s", accept, i.Proposed.Device)
	if !accept {
		return nil
	}
	hash, err := i.Proposed.Hash()
	if err != nil {
		return onet.NewClientErrorCode(ErrorOnet, err.Error())
	}
	sig, err := crypto.SignSchnorr(network.Suite, i.Private, hash)
	if err != nil {
		return onet.NewClientErrorCode(ErrorOnet, err.Error())
	}
	pvr := &ProposeVoteReply{}
	cerr := i.Client.SendProtobuf(i.Cothority.RandomServerIdentity(), &ProposeVote{
		ID:        i.ID,
		Signer:    i.DeviceName,
		Signature: &sig,
	}, pvr)
	if cerr != nil {
		return cerr
	}
	if pvr.Data != nil {
		log.Lvl2("Threshold reached and signed")
		i.Config = i.Proposed
		i.Proposed = nil
	} else {
		log.Lvl2("Threshold not reached")
	}
	return nil
}
예제 #2
0
파일: ntree.go 프로젝트: dedis/cothority
// HandleSignRequest is a handler for incoming sign-requests. It's registered as
// a handler in the onet.Node.
func (p *Protocol) HandleSignRequest(msg structMessage) error {
	p.Message = msg.Msg
	p.verifySignature = msg.VerifySignature
	signature, err := crypto.SignSchnorr(network.Suite, p.Private(), p.Message)
	if err != nil {
		return err
	}
	// fill our own signature
	p.signature = &SignatureReply{
		Sig:   signature,
		Index: p.TreeNode().RosterIndex}
	if !p.IsLeaf() {
		for _, c := range p.Children() {
			err := p.SendTo(c, &msg.Message)
			if err != nil {
				return err
			}
		}
	} else {
		err := p.SendTo(p.Parent(), &SignatureBundle{ChildSig: p.signature})
		p.Done()
		return err
	}
	return nil
}
예제 #3
0
파일: ntree.go 프로젝트: dedis/cothority
// computeBlockSignature compute the signature out of the block.
func (nt *Ntree) computeBlockSignature() {
	// wait the end of verification of the block
	ok := <-nt.verifyBlockChan
	//marshal the blck
	marshalled, err := json.Marshal(nt.block)
	if err != nil {
		log.Error(err)
		return
	}

	// if stg is wrong, we put exceptions
	if !ok {
		nt.tempBlockSig.Exceptions = append(nt.tempBlockSig.Exceptions, Exception{nt.TreeNode().ID})
	} else { // we put signature
		schnorr, _ := crypto.SignSchnorr(nt.Suite(), nt.Private(), marshalled)
		nt.tempBlockSig.Sigs = append(nt.tempBlockSig.Sigs, schnorr)
	}
	log.Lvl3(nt.Name(), "Block Signature Computed")
}
예제 #4
0
파일: ntree.go 프로젝트: dedis/cothority
// computeSignatureResponse will compute the response out of the signature
// request. It's the final signature.
func (nt *Ntree) computeSignatureResponse() {
	// wait for the verification to be done
	ok := <-nt.verifySignatureRequestChan
	if !ok {
		nt.tempSignatureResponse.Exceptions = append(nt.tempSignatureResponse.Exceptions, Exception{nt.TreeNode().ID})
	} else {
		// compute the message out of the previous signature
		// marshal only the header here (so signature between the two phases are
		// garanteed to be different)
		marshalled, err := json.Marshal(nt.block.Header)
		if err != nil {
			log.Error(err)
			return
		}
		sig, err := crypto.SignSchnorr(nt.Suite(), nt.Private(), marshalled)
		if err != nil {
			return
		}
		nt.tempSignatureResponse.Sigs = append(nt.tempSignatureResponse.Sigs, sig)
	}
}
예제 #5
0
func signSchnorr(suite abstract.Suite, key abstract.Scalar, m interface{}) error {

	// Reset signature field
	reflect.ValueOf(m).Elem().FieldByName("Sig").Set(reflect.ValueOf(crypto.SchnorrSig{})) // XXX: hack

	// Marshal message
	mb, err := network.MarshalRegisteredType(m)
	if err != nil {
		return err
	}

	// Sign message
	sig, err := crypto.SignSchnorr(suite, key, mb)
	if err != nil {
		return err
	}

	// Store signature
	reflect.ValueOf(m).Elem().FieldByName("Sig").Set(reflect.ValueOf(sig)) // XXX: hack

	return nil
}