示例#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
// 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)
}