Skip to content

Commit

Permalink
Cleaned some of the tmp variables
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaoAndreSa committed Mar 12, 2020
1 parent 8563eee commit a4d36eb
Show file tree
Hide file tree
Showing 18 changed files with 121 additions and 125 deletions.
8 changes: 4 additions & 4 deletions app/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,17 @@ func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, group
where = strings.Replace(where, " ", "", -1)
where = strings.Replace(where, "{", "", -1)
where = strings.Replace(where, "}", "", -1)
tmp := strings.Split(where, ",")
whereTokens := strings.Split(where, ",")

whereFinal := make([]libunlynx.WhereQueryAttribute, 0)

var variable string
for i := range tmp {
for i := range whereTokens {
// if is a variable (w1, w2...)
if i%2 == 0 {
variable = tmp[i]
variable = whereTokens[i]
} else { // if it is a value
value, err := strconv.Atoi(tmp[i])
value, err := strconv.Atoi(whereTokens[i])
if err != nil {
return nil, false, nil, "", nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions lib/aggregation/aggregation_proofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,15 @@ func (palp *PublishedAggregationListProof) FromBytes(palpb PublishedAggregationL
for i, papb := range palpb.List {
go func(index int, papb PublishedAggregationProofBytes) {
defer wg.Done()
tmp := PublishedAggregationProof{}
tmpErr := tmp.FromBytes(papb)
pap := PublishedAggregationProof{}
tmpErr := pap.FromBytes(papb)
if tmpErr != nil {
mutex.Lock()
err = tmpErr
mutex.Unlock()
return
}
palp.List[index] = tmp
palp.List[index] = pap
}(i, papb)
}
libunlynx.EndParallelize(wg)
Expand Down
4 changes: 2 additions & 2 deletions lib/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
)

func init() {
tmp, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT"))
timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT"))
if err == nil {
TIMEOUT = tmp
TIMEOUT = timeout
} else {
log.Warn("Couldn't parse MEDCO_TIMEOUT, using default value: ", TIMEOUT.String())
}
Expand Down
3 changes: 1 addition & 2 deletions lib/deterministic_tag/deterministic_tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ func TestDeterministicTagSequence(t *testing.T) {
target := []int64{-8358645081376817152, -8358645081376817152, 2, 3, 2, 5}
cv := *libunlynx.EncryptIntVector(K, target)
for n := 0; n < N; n++ {
tmp := libunlynxdetertag.DeterministicTagSequence(cv, private[n], secretPrivate[n])
cv = tmp
cv = libunlynxdetertag.DeterministicTagSequence(cv, private[n], secretPrivate[n])
}

assert.True(t, cv[0].C.Equal(cv[1].C))
Expand Down
28 changes: 14 additions & 14 deletions lib/shuffle/shuffle.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ func shuffle(pi []int, i int, inputList, outputList []libunlynx.CipherVector, NQ
wg := libunlynx.StartParallelize(NQ)
for j := 0; j < NQ; j++ {
var b kyber.Scalar
var tmpCipher libunlynx.CipherText
var ct libunlynx.CipherText
if len(precomputedPoints[0]) == 0 {
b = beta[index][j]
} else {
tmpCipher = precomputedPoints[index][j]
ct = precomputedPoints[index][j]
}
go func(j int) {
defer wg.Done()
outputList[i][j] = rerandomize(inputList[index], b, b, tmpCipher, g, h, j)
outputList[i][j] = rerandomize(inputList[index], b, b, ct, g, h, j)
}(j)
}
libunlynx.EndParallelize(wg)
Expand All @@ -80,19 +80,19 @@ func shuffle(pi []int, i int, inputList, outputList []libunlynx.CipherVector, NQ
// rerandomize rerandomizes an element in a ciphervector at position j, following the Neff Shuffling algorithm
func rerandomize(cv libunlynx.CipherVector, a, b kyber.Scalar, cipher libunlynx.CipherText, g, h kyber.Point, j int) libunlynx.CipherText {
ct := libunlynx.NewCipherText()
var tmp1, tmp2 kyber.Point
var point1, point2 kyber.Point

if cipher.C == nil {
//no precomputed value
tmp1 = libunlynx.SuiTe.Point().Mul(a, g)
tmp2 = libunlynx.SuiTe.Point().Mul(b, h)
point1 = libunlynx.SuiTe.Point().Mul(a, g)
point2 = libunlynx.SuiTe.Point().Mul(b, h)
} else {
tmp1 = cipher.K
tmp2 = cipher.C
point1 = cipher.K
point2 = cipher.C
}

ct.K = libunlynx.SuiTe.Point().Add(cv[j].K, tmp1)
ct.C = libunlynx.SuiTe.Point().Add(cv[j].C, tmp2)
ct.K = libunlynx.SuiTe.Point().Add(cv[j].K, point1)
ct.C = libunlynx.SuiTe.Point().Add(cv[j].C, point2)
return *ct
}

Expand All @@ -113,12 +113,12 @@ func CreatePrecomputedRandomize(g, h kyber.Point, rand cipher.Stream, lineSize,

for w := range result[i].CipherV {
mutex.Lock()
tmp := libunlynx.SuiTe.Scalar().Pick(rand)
scalar := libunlynx.SuiTe.Scalar().Pick(rand)
mutex.Unlock()

result[i].S[w] = tmp
result[i].CipherV[w].K = libunlynx.SuiTe.Point().Mul(tmp, g)
result[i].CipherV[w].C = libunlynx.SuiTe.Point().Mul(tmp, h)
result[i].S[w] = scalar
result[i].CipherV[w].K = libunlynx.SuiTe.Point().Mul(scalar, g)
result[i].CipherV[w].C = libunlynx.SuiTe.Point().Mul(scalar, h)
}

}(i)
Expand Down
34 changes: 16 additions & 18 deletions lib/shuffle/shuffle_proofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,29 +343,29 @@ func compressCipherVectorMultiple(inputList, outputList []libunlynx.CipherVector
wg := libunlynx.StartParallelize(2)
go func() {
defer wg.Done()
tmp, tmpErr := compressCipherVector(inputList[i], e)
cv, tmpErr := compressCipherVector(inputList[i], e)
if tmpErr != nil {
mutex.Lock()
err = tmpErr
mutex.Unlock()
return
}

Xhat[i] = tmp.K
Yhat[i] = tmp.C
Xhat[i] = cv.K
Yhat[i] = cv.C
}()
go func() {
defer wg.Done()
tmpBar, tmpErr := compressCipherVector(outputList[i], e)
cv, tmpErr := compressCipherVector(outputList[i], e)
if tmpErr != nil {
mutex.Lock()
err = tmpErr
mutex.Unlock()
return
}

XhatBar[i] = tmpBar.K
YhatBar[i] = tmpBar.C
XhatBar[i] = cv.K
YhatBar[i] = cv.C
}()
libunlynx.EndParallelize(wg)

Expand All @@ -388,8 +388,8 @@ func compressBeta(beta [][]kyber.Scalar, e []kyber.Scalar) []kyber.Scalar {
go func(i int) {
defer wg.Done()
for j := 0; j < NQ; j++ {
tmp := libunlynx.SuiTe.Scalar().Mul(beta[i][j], e[j])
betaCompressed[i] = libunlynx.SuiTe.Scalar().Add(betaCompressed[i], tmp)
betaMulE := libunlynx.SuiTe.Scalar().Mul(beta[i][j], e[j])
betaCompressed[i] = libunlynx.SuiTe.Scalar().Add(betaCompressed[i], betaMulE)
}
}(i)
}
Expand All @@ -412,31 +412,31 @@ func (psp *PublishedShufflingProof) ToBytes() (PublishedShufflingProofBytes, err
wg := libunlynx.StartParallelize(3)
go func(data []libunlynx.CipherVector) {
defer wg.Done()
tmp, tmpLength, tmpErr := libunlynx.ArrayCipherVectorToBytes(data)
cvBytes, cvLengthBytes, tmpErr := libunlynx.ArrayCipherVectorToBytes(data)
if tmpErr != nil {
mutex.Lock()
err = tmpErr
mutex.Unlock()
return
}

pspb.OriginalList = &tmp
pspb.OriginalListLength = &tmpLength
pspb.OriginalList = &cvBytes
pspb.OriginalListLength = &cvLengthBytes
}(psp.OriginalList)

// convert ShuffledList
go func(data []libunlynx.CipherVector) {
defer wg.Done()
tmp, tmpLength, tmpErr := libunlynx.ArrayCipherVectorToBytes(data)
cvBytes, cvLengthBytes, tmpErr := libunlynx.ArrayCipherVectorToBytes(data)
if tmpErr != nil {
mutex.Lock()
err = tmpErr
mutex.Unlock()
return
}

pspb.ShuffledList = &tmp
pspb.ShuffledListLength = &tmpLength
pspb.ShuffledList = &cvBytes
pspb.ShuffledListLength = &cvLengthBytes
}(psp.ShuffledList)

// convert 'the rest'
Expand All @@ -450,8 +450,7 @@ func (psp *PublishedShufflingProof) ToBytes() (PublishedShufflingProofBytes, err
mutex.Unlock()
return
}
tmpGBytes := dataG
pspb.G = &tmpGBytes
pspb.G = &dataG

dataH, tmpErr := libunlynx.AbstractPointsToBytes([]kyber.Point{H})
if tmpErr != nil {
Expand All @@ -460,8 +459,7 @@ func (psp *PublishedShufflingProof) ToBytes() (PublishedShufflingProofBytes, err
mutex.Unlock()
return
}
tmpHBytes := dataH
pspb.H = &tmpHBytes
pspb.H = &dataH

pspb.HashProof = psp.HashProof
}(psp.G, psp.H, psp.HashProof)
Expand Down
6 changes: 3 additions & 3 deletions lib/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ func (s *Store) InsertDpResponse(cr libunlynx.DpResponse, proofsB bool, groupBy,
} else {
value, ok := s.DpResponsesAggr[GroupingKeyTuple{libunlynx.Key(clearGrp), libunlynx.Key(clearWhr)}]
if ok {
tmp := libunlynx.NewCipherVector(len(value.AggregatingAttributes))
tmp.Add(value.AggregatingAttributes, newResp.AggregatingAttributes)
cv := libunlynx.NewCipherVector(len(value.AggregatingAttributes))
cv.Add(value.AggregatingAttributes, newResp.AggregatingAttributes)
mapValue := s.DpResponsesAggr[GroupingKeyTuple{libunlynx.Key(clearGrp), libunlynx.Key(clearWhr)}]
mapValue.AggregatingAttributes = *tmp
mapValue.AggregatingAttributes = *cv
s.DpResponsesAggr[GroupingKeyTuple{libunlynx.Key(clearGrp), libunlynx.Key(clearWhr)}] = mapValue

if proofsB {
Expand Down
16 changes: 8 additions & 8 deletions lib/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ func AddInMap(s map[GroupingKey]FilteredResponse, key GroupingKey, added Filtere
if localResult, ok := s[key]; !ok {
s[key] = added
} else {
tmp := NewFilteredResponse(len(added.GroupByEnc), len(added.AggregatingAttributes))
s[key] = *tmp.Add(localResult, added)
nfr := NewFilteredResponse(len(added.GroupByEnc), len(added.AggregatingAttributes))
s[key] = *nfr.Add(localResult, added)
}
}

Expand Down Expand Up @@ -141,9 +141,9 @@ func (crd *FilteredResponseDet) FormatAggregationProofs(res map[GroupingKey][]Ci
} else { // if no elements are in the map yet
container := make([]CipherVector, len(crd.Fr.AggregatingAttributes))
for i, ct := range crd.Fr.AggregatingAttributes {
tmp := make(CipherVector, 0)
tmp = append(tmp, ct)
container[i] = tmp
cv := make(CipherVector, 0)
cv = append(cv, ct)
container[i] = cv
res[crd.DetTagGroupBy] = container
}
}
Expand Down Expand Up @@ -205,7 +205,7 @@ func Key(ga []int64) GroupingKey {
return GroupingKey(strings.Join(key, ""))
}

// UnKey permits to go from a tag non-encrypted grouping attributes to grouping attributes
// UnKey permits to go from a tag non-encrypted grouping attributes to grouping attributes
func UnKey(gk GroupingKey) ([]int64, error) {
tab := make([]int64, 0)
count := 0
Expand All @@ -214,11 +214,11 @@ func UnKey(gk GroupingKey) ([]int64, error) {
if a != ',' {
nbrString[0] = string(a)
} else {
tmp, err := strconv.Atoi(strings.Join(nbrString, ""))
key, err := strconv.Atoi(strings.Join(nbrString, ""))
if err != nil {
return nil, err
}
tab = append(tab, int64(tmp))
tab = append(tab, int64(key))
nbrString = make([]string, 1)
count++
}
Expand Down
6 changes: 3 additions & 3 deletions protocols/collective_aggregation_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@ func (p *CollectiveAggregationProtocol) ascendingAggregationPhase(cvMap map[libu
}

if ok {
tmp := libunlynx.NewCipherVector(len(localAggr.AggregatingAttributes))
tmp.Add(localAggr.AggregatingAttributes, aggr.Fr.AggregatingAttributes)
cv := libunlynx.NewCipherVector(len(localAggr.AggregatingAttributes))
cv.Add(localAggr.AggregatingAttributes, aggr.Fr.AggregatingAttributes)

localAggr.AggregatingAttributes = *tmp
localAggr.AggregatingAttributes = *cv
} else {
localAggr = aggr.Fr
}
Expand Down
4 changes: 2 additions & 2 deletions protocols/collective_aggregation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ func TestCollectiveAggregationSimple(t *testing.T) {
case encryptedResult := <-feedback:
log.Lvl1("Received results:")
resultData := make([]int64, len(encryptedResult.GroupedData[protocolsunlynx.EMPTYKEY].AggregatingAttributes))
tmp := encryptedResult.GroupedData[protocolsunlynx.EMPTYKEY].AggregatingAttributes
resultData = libunlynx.DecryptIntVector(clientPrivate, &tmp)
aggrAttr := encryptedResult.GroupedData[protocolsunlynx.EMPTYKEY].AggregatingAttributes
resultData = libunlynx.DecryptIntVector(clientPrivate, &aggrAttr)
log.Lvl1(resultData)
assert.Equal(t, expectedResults, resultData)
case <-time.After(timeout):
Expand Down
18 changes: 9 additions & 9 deletions protocols/deterministic_tagging_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,17 @@ func (p *DeterministicTaggingProtocol) Dispatch() error {
go func(i int) {
defer wg.Done()
for j := 0; j < libunlynx.VPARALLELIZE && (i+j) < len(deterministicTaggingTargetBef.Data); j++ {
tmp := libunlynx.SuiTe.Point().Add(deterministicTaggingTargetBef.Data[i+j].C, toAdd)
r := libunlynx.SuiTe.Point().Add(deterministicTaggingTargetBef.Data[i+j].C, toAdd)
if p.Proofs {
_, tmpErr := libunlynxdetertag.DeterministicTagAdditionProofCreation(deterministicTaggingTargetBef.Data[i+j].C, *p.SurveySecretKey, toAdd, tmp)
_, tmpErr := libunlynxdetertag.DeterministicTagAdditionProofCreation(deterministicTaggingTargetBef.Data[i+j].C, *p.SurveySecretKey, toAdd, r)
if tmpErr != nil {
mutex.Lock()
err = tmpErr
mutex.Unlock()
return
}
}
deterministicTaggingTargetBef.Data[i+j].C = tmp
deterministicTaggingTargetBef.Data[i+j].C = r
}
}(i)
}
Expand Down Expand Up @@ -233,15 +233,15 @@ func (p *DeterministicTaggingProtocol) Dispatch() error {
if j > len(deterministicTaggingTarget.Data) {
j = len(deterministicTaggingTarget.Data)
}
tmp := deterministicTaggingTarget.Data[i:j]
tmpErr := TaggingDet(&tmp, p.Private(), *p.SurveySecretKey, p.Public(), p.Proofs)
cv := deterministicTaggingTarget.Data[i:j]
tmpErr := TaggingDet(&cv, p.Private(), *p.SurveySecretKey, p.Public(), p.Proofs)
if tmpErr != nil {
mutex.Lock()
err = tmpErr
mutex.Unlock()
return
}
copy(deterministicTaggingTarget.Data[i:j], tmp)
copy(deterministicTaggingTarget.Data[i:j], cv)
}(i)
}
wg.Wait()
Expand Down Expand Up @@ -394,9 +394,9 @@ func (dtm *DeterministicTaggingMessage) FromBytes(data []byte) error {
go func(i int) {
defer wg.Done()
for j := 0; j < elementSize*libunlynx.VPARALLELIZE && i+j < len(data); j += elementSize {
tmp := make([]byte, elementSize)
copy(tmp, data[i+j:i+j+elementSize])
tmpErr := (*dtm).Data[(i+j)/elementSize].FromBytes(tmp)
dataCopy := make([]byte, elementSize)
copy(dataCopy, data[i+j:i+j+elementSize])
tmpErr := (*dtm).Data[(i+j)/elementSize].FromBytes(dataCopy)
if tmpErr != nil {
mutex.Lock()
err = tmpErr
Expand Down
Loading

0 comments on commit a4d36eb

Please sign in to comment.