Пример #1
0
// Verifies that the Equal method works.
func TestRequestInsuranceEqual(t *testing.T) {
	share := prishares.Share(0)
	msg := new(RequestInsuranceMessage).createMessage(keyPair.Public, 0,
		share, pubCommit)
	msgCopy := msg

	if !msg.Equal(msgCopy) {
		t.Error("Messages should be equal.")
	}

	// Fails if only the public keys are different.
	msg2 := new(RequestInsuranceMessage).createMessage(keyPair2.Public, 0,
		share, pubCommit)
	if msg.Equal(msg2) {
		t.Error("Messages should not be equal.")
	}

	// Fails if only the share number is different.
	msg2 = new(RequestInsuranceMessage).createMessage(keyPair.Public, 1,
		share, pubCommit)
	if msg.Equal(msg2) {
		t.Error("Messages should not be equal.")
	}

	// Fails if only the shares are different.
	msg2 = new(RequestInsuranceMessage).createMessage(keyPair.Public, 0,
		prishares.Share(1), pubCommit)
	if msg.Equal(msg2) {
		t.Error("Messages should not be equal.")
	}

	pripoly2 := new(poly.PriPoly).Pick(INSURE_GROUP, TSHARES, secret,
		random.Stream)
	otherPoly := new(poly.PubPoly)
	otherPoly.Init(INSURE_GROUP, TSHARES, nil)
	otherPoly.Commit(pripoly2, nil)

	// Fails if only the public polynomial is different
	msg2 = new(RequestInsuranceMessage).createMessage(keyPair.Public, 0,
		share, otherPoly)
	if msg.Equal(msg2) {
		t.Error("Messages should not be equal.")
	}
}
Пример #2
0
// Split creates PVSS shares encrypted by the public keys in X and
// provides a NIZK encryption consistency proof for each share.
func (pv *PVSS) Split(X []abstract.Point, secret abstract.Scalar) ([]int, []abstract.Point, []ProofCore, []byte, error) {

	n := len(X)

	// Create secret sharing polynomial
	priPoly := new(poly.PriPoly).Pick(pv.suite, pv.t, secret, random.Stream)

	// Create secret set of shares
	shares := new(poly.PriShares).Split(priPoly, n)

	// Create public polynomial commitments with respect to basis H
	pubPoly := new(poly.PubPoly).Commit(priPoly, pv.h)

	// Prepare data for encryption consistency proofs ...
	share := make([]abstract.Scalar, n)
	H := make([]abstract.Point, n)
	idx := make([]int, n)
	for i := range idx {
		idx[i] = i
		share[i] = shares.Share(i)
		H[i] = pv.h
	}

	// ... and create them
	proof, err := NewProof(pv.suite, H, X, nil)
	if err != nil {
		return nil, nil, nil, nil, err
	}
	_, sX, err := proof.SetupCollective(share...)
	if err != nil {
		return nil, nil, nil, nil, err
	}

	polyBin, err := pubPoly.MarshalBinary()
	if err != nil {
		return nil, nil, nil, nil, err
	}

	return idx, sX, proof.Core, polyBin, nil
}
Пример #3
0
// Commits reconstructs a list of commits from the given polynomials and indices.
func (pv *PVSS) Commits(polyBin [][]byte, index []int) ([]abstract.Point, error) {

	if len(polyBin) != len(index) {
		return nil, errors.New("Inputs have different lengths")
	}

	n := len(polyBin)
	sH := make([]abstract.Point, n)
	for i := range sH {
		P := new(poly.PubPoly)
		P.Init(pv.suite, pv.t, pv.h)
		if err := P.UnmarshalBinary(polyBin[i]); err != nil {
			return nil, err
		}
		sH[i] = P.Eval(index[i])
	}
	return sH, nil
}
Пример #4
0
func (lp *LifePolicy) TakeOutPolicy(serverList []abstract.Point,
	selectInsurers func([]abstract.Point, int) []abstract.Point,
	g abstract.Group, t int, n int) (*LifePolicy, bool) {

	// If n is less than the expected number of shares to reconstruct the
	// secret, fail
	if n < t {
		return lp, false
	}

	// Initialize the policy.

	// If we have no selectInsurers function, use the basic algorithm.
	if selectInsurers == nil {
		selectInsurers = selectInsurersBasic
	}

	lp.insurersList = selectInsurers(serverList, n)
	if lp.insurersList == nil || len(lp.insurersList) < n {
		return lp, false
	}

	//TODO: Use bytes maybe?
	lp.proofList = new(list.List)

	// Create a new polynomial from the private key where t shares are
	// needed to reconstruct the secret. Then, split it into secret shares
	// and create the public polynomial.
	pripoly := new(poly.PriPoly).Pick(g, t, lp.keyPair.Secret, random.Stream)
	prishares := new(poly.PriShares).Split(pripoly, n)
	pubPoly := new(poly.PubPoly)
	pubPoly.Init(g, n, nil)
	pubPoly = new(poly.PubPoly).Commit(pripoly, nil)

	// Mark the policy as being in the setup stage and ready to begin
	// receiving PolicyApproveMessages.
	lp.policyStatus = PolicySetup

	// Send each share off to the appropriate server.
	for i := 0; i < n; i++ {
		requestMsg := new(RequestInsuranceMessage).createMessage(
			lp.keyPair.Public, i, prishares.Share(i), pubPoly)
		lp.cman.Put(lp.insurersList[i],
			new(PolicyMessage).createRIMessage(requestMsg))
	}

	receivedList := make([]bool, len(lp.insurersList))

	// TODO: Add a timeout such that this process will end after a certain
	// time and a new batch of insurers can be picked.

	// TODO: Make it so that it stops as soon as we get R other insurers
	// for t <= r <= n
	for lp.proofList.Len() < n {
		for i := 0; i < n; i++ {
			// If we have already received a certificate for this
			// node, move on.
			if receivedList[i] == true {
				continue
			}

			msg := new(PolicyMessage)
			lp.cman.Get(lp.insurersList[i], msg)
			msgType, err := lp.handlePolicyMessage(msg)

			// Merely for efficiency, to update the receive list.
			if msgType == PolicyApproved {
				receivedList[i] = (err == nil)
			}
		}
	}

	lp.policyStatus = PolicyReady
	return lp, true
}
Пример #5
0
// Used to initialize the public commit polynomial.
func producePubPoly() *poly.PubPoly {
	testPubPoly := new(poly.PubPoly)
	testPubPoly.Init(INSURE_GROUP, n, nil)
	return testPubPoly.Commit(pripoly, nil)
}