Skip to content
This repository has been archived by the owner on Oct 8, 2020. It is now read-only.

Commit

Permalink
Merge pull request #37 from ldsec/multipleKS
Browse files Browse the repository at this point in the history
Changed the AggRequest to accept multiple inpute values
  • Loading branch information
mickmis committed Apr 14, 2020
2 parents b803e90 + eb628c7 commit b1239ae
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
9 changes: 4 additions & 5 deletions services/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (c *API) SendSurveyShuffleRequest(entities *onet.Roster, surveyID SurveyID,
}

// SendSurveyAggRequest sends the encrypted aggregate local results at each node and aggregates these values (result is the same for all nodes)
func (c *API) SendSurveyAggRequest(entities *onet.Roster, surveyID SurveyID, cPK kyber.Point, value libunlynx.CipherText, proofs bool) (*SurveyID, libunlynx.CipherText, TimeResults, error) {
func (c *API) SendSurveyAggRequest(entities *onet.Roster, surveyID SurveyID, cPK kyber.Point, values libunlynx.CipherVector, proofs bool) (*SurveyID, libunlynx.CipherVector, TimeResults, error) {
start := time.Now()
log.Lvl2("Client", c.ClientID, "is creating a Agg survey with ID:", surveyID)

Expand All @@ -117,16 +117,15 @@ func (c *API) SendSurveyAggRequest(entities *onet.Roster, surveyID SurveyID, cPK
Roster: *entities,
Proofs: proofs,
ClientPubKey: cPK,
AggregateTarget: value,
AggregateTarget: values,
}

resp := Result{}
err := c.SendProtobuf(c.entryPoint, &sar, &resp)
if err != nil {

return nil, libunlynx.CipherText{}, TimeResults{}, err
return nil, nil, TimeResults{}, err
}
resp.TR.MapTR[AggrRequestTime] = time.Since(start)
return &surveyID, resp.Result[0], resp.TR, nil
return &surveyID, resp.Result, resp.TR, nil

}
18 changes: 10 additions & 8 deletions services/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func (s *Service) HandleSurveyAggRequest(sar *SurveyAggRequest) (network.Message
if err := emptySurveyID(sar.SurveyID); err != nil {
return nil, xerrors.Errorf("%+v", err)
}
if sar.AggregateTarget.K == nil || sar.AggregateTarget.C == nil {
if sar.AggregateTarget == nil || len(sar.AggregateTarget) == 0 {
return nil, xerrors.Errorf(s.ServerIdentity().String() + " for survey" + string(sar.SurveyID) + "has no data to aggregate")
}
if sar.ClientPubKey == nil {
Expand Down Expand Up @@ -470,7 +470,7 @@ func (s *Service) whatRequest(target string) (bool, libunlynx.CipherVector, kybe
return false, nil, nil, err
}
proofs = surveyAgg.Request.Proofs
data = libunlynx.CipherVector{surveyAgg.Request.KSTarget}
data = surveyAgg.Request.KSTarget
cPubKey = surveyAgg.Request.ClientPubKey

default:
Expand Down Expand Up @@ -619,7 +619,9 @@ func (s *Service) NewProtocol(tn *onet.TreeNodeInstance,
aggr.Proofs = surveyAgg.Request.Proofs

data := make([]libunlynx.CipherText, 0)
data = append(data, surveyAgg.Request.AggregateTarget)
for i := range surveyAgg.Request.AggregateTarget {
data = append(data, surveyAgg.Request.AggregateTarget[i])
}
aggr.SimpleData = &data

case propagateShuffleFromChildren:
Expand Down Expand Up @@ -764,24 +766,24 @@ func (s *Service) TaggingPhase(targetSurvey *SurveyDDTRequest,
}

// CollectiveAggregationPhase performs a collective aggregation between the participating nodes
func (s *Service) CollectiveAggregationPhase(targetSurvey SurveyID, roster *onet.Roster) (libunlynx.CipherText, time.Duration, error) {
func (s *Service) CollectiveAggregationPhase(targetSurvey SurveyID, roster *onet.Roster) (libunlynx.CipherVector, time.Duration, error) {
start := time.Now()
pi, err := s.StartProtocol(protocolsunlynx.CollectiveAggregationProtocolName, "",
ProtocolConfig{targetSurvey, "", nil}, roster)
if err != nil {
return libunlynx.CipherText{}, 0, err
return nil, 0, err
}
select {
case aggregationResult := <-pi.(*protocolsunlynx.CollectiveAggregationProtocol).FeedbackChannel:
// in the resulting map there is only one element
var finalResult libunlynx.CipherText
finalResult := make(libunlynx.CipherVector, 0)
for _, v := range aggregationResult.GroupedData {
finalResult = v.AggregatingAttributes[0]
finalResult = v.AggregatingAttributes
break
}
return finalResult, time.Since(start), nil
case <-time.After(libunlynx.TIMEOUT):
return libunlynx.CipherText{}, 0, fmt.Errorf("couldn't finish collective aggregation protocol in time")
return nil, 0, fmt.Errorf("couldn't finish collective aggregation protocol in time")
}
}

Expand Down
10 changes: 5 additions & 5 deletions services/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ func TestServiceAgg(t *testing.T) {

secKeys := make([]kyber.Scalar, 0)
pubKeys := make([]kyber.Point, 0)
targetData := *libunlynx.EncryptInt(el.Aggregate, int64(1))
results := make([]int64, nbrClients)
targetData := *libunlynx.EncryptIntVector(el.Aggregate, []int64{1})
results := make([][]int64, nbrClients)

for i := 0; i < nbrClients; i++ {
_, sK, pK := libunlynx.GenKeys(1)
Expand All @@ -205,7 +205,7 @@ func TestServiceAgg(t *testing.T) {
_, _, _, err = clients[0].SendSurveyAggRequest(el, "testAggRequest", nil, targetData, proofs)
assert.Error(t, err)
// no terms to aggregate
emptyData := libunlynx.CipherText{}
emptyData := libunlynx.CipherVector{}
_, _, _, err = clients[0].SendSurveyAggRequest(el, "testAggRequest", pubKeys[0], emptyData, proofs)
assert.Error(t, err)

Expand All @@ -221,7 +221,7 @@ func TestServiceAgg(t *testing.T) {
}

mutex.Lock()
results[i] = libunlynx.DecryptInt(secKeys[i], res)
results[i] = libunlynx.DecryptIntVector(secKeys[i], &res)
mutex.Unlock()
log.Lvl1("Time:", tr.MapTR)
}(i, client)
Expand All @@ -230,7 +230,7 @@ func TestServiceAgg(t *testing.T) {

// Check result
for _, res := range results {
assert.Equal(t, res, int64(nbrServers))
assert.Equal(t, res[0], int64(nbrServers))
}
}

Expand Down
4 changes: 2 additions & 2 deletions services/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ type SurveyAggRequest struct {
Proofs bool
ClientPubKey kyber.Point // we need this for the key switching

AggregateTarget libunlynx.CipherText // target results to aggregate. the root node adds the results from the other nodes here
KSTarget libunlynx.CipherText // the final aggregated result to be key switched
AggregateTarget libunlynx.CipherVector // target results to aggregate. the root node adds the results from the other nodes here
KSTarget libunlynx.CipherVector // the final aggregated results to be key switched
}

// SurveyKS is the struct that we persist in the service that contains all the data for the Key Switch request phase
Expand Down

0 comments on commit b1239ae

Please sign in to comment.