Skip to content

Commit c9f37b9

Browse files
author
Jan Bobolz
authored
Merge pull request #135 from cryptimeleon/fix-linearize
Fix linearize
2 parents 7943576 + 047eb18 commit c9f37b9

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

src/main/java/org/cryptimeleon/math/expressions/group/GroupPowExpr.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.cryptimeleon.math.expressions.Expression;
44
import org.cryptimeleon.math.expressions.Substitution;
5+
import org.cryptimeleon.math.expressions.exponent.ExponentEmptyExpr;
56
import org.cryptimeleon.math.expressions.exponent.ExponentExpr;
67
import org.cryptimeleon.math.expressions.exponent.ExponentSumExpr;
78
import org.cryptimeleon.math.structures.groups.GroupElement;
@@ -74,10 +75,16 @@ public GroupOpExpr linearize() throws IllegalArgumentException {
7475

7576
if (baseHasVariables) { //hence exponent doesn't
7677
GroupOpExpr baseLinear = base.linearize();
77-
return new GroupOpExpr(baseLinear.getLhs().pow(exponent), baseLinear.getRhs().pow(exponent));
78+
if (baseLinear.getLhs() instanceof GroupEmptyExpr) //base is linear already, hence this PowExpr is linear
79+
return new GroupOpExpr(new GroupEmptyExpr(base.getGroup()), this);
80+
else //split base into linear and constant part
81+
return new GroupOpExpr(baseLinear.getLhs().pow(exponent), baseLinear.getRhs().pow(exponent));
7882
} else { //exponent has variables, base doesn't.
7983
ExponentSumExpr exponentLinear = exponent.linearize();
80-
return new GroupOpExpr(base.pow(exponentLinear.getLhs()), base.pow(exponentLinear.getRhs()));
84+
if (exponentLinear.getLhs() instanceof ExponentEmptyExpr) //exponent is linear already, hence this PowExpr is linear
85+
return new GroupOpExpr(new GroupEmptyExpr(base.getGroup()), this);
86+
else //split exponent into linear and constant part
87+
return new GroupOpExpr(base.pow(exponentLinear.getLhs()), base.pow(exponentLinear.getRhs()));
8188
}
8289
}
8390

src/main/java/org/cryptimeleon/math/expressions/group/PairingExpr.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,16 @@ public GroupOpExpr linearize() throws IllegalArgumentException {
7373

7474
if (lhsHasVariables) { //hence rhs doesn't
7575
GroupOpExpr lhsLinearized = lhs.linearize();
76-
return new GroupOpExpr(new PairingExpr(map, lhsLinearized.getLhs(), rhs), new PairingExpr(map, lhsLinearized.getRhs(), rhs));
76+
if (lhsLinearized.getLhs() instanceof GroupEmptyExpr) //lhs is already linearized, so this PairingExpr is already linear
77+
return new GroupOpExpr(new GroupEmptyExpr(map.getGT()), this);
78+
else
79+
return new GroupOpExpr(new PairingExpr(map, lhsLinearized.getLhs(), rhs), new PairingExpr(map, lhsLinearized.getRhs(), rhs));
7780
} else { //lhs is constant, rhs isn't
7881
GroupOpExpr rhsLinearized = rhs.linearize();
79-
return new GroupOpExpr(new PairingExpr(map, lhs, rhsLinearized.getLhs()), new PairingExpr(map, lhs, rhsLinearized.getRhs()));
82+
if (rhsLinearized.getLhs() instanceof GroupEmptyExpr) //rhs is already linearized, so this PairingExpr is already linear
83+
return new GroupOpExpr(new GroupEmptyExpr(map.getGT()), this);
84+
else
85+
return new GroupOpExpr(new PairingExpr(map, lhs, rhsLinearized.getLhs()), new PairingExpr(map, lhs, rhsLinearized.getRhs()));
8086
}
8187
}
8288

src/main/java/org/cryptimeleon/math/structures/groups/debug/DebugGroup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ public String formatCounterDataAllBuckets(boolean summaryOnly) {
481481
result.append(formatCounterData(bucketName, false, false));
482482
}
483483
}
484-
return result.append(formatCounterDataAllBuckets(false)).toString();
484+
return result.append(formatCounterDataAllBucketsOnly(false)).toString();
485485
}
486486

487487
/**

0 commit comments

Comments
 (0)