Skip to content

Commit

Permalink
Add inversion numbers to remaining rings
Browse files Browse the repository at this point in the history
  • Loading branch information
rheitjoh committed May 3, 2021
1 parent 2156c1a commit 5a8c6a1
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ public RingElement getElement(BigInteger i) {
return i.mod(BigInteger.valueOf(2)).equals(BigInteger.ZERO) ? BooleanElement.FALSE : BooleanElement.TRUE;
}

@Override
public double estimateCostInvPerOp() {
return 1;
}

@Override
public double estimateCostNegPerOp() {
return 1;
}

@Override
public boolean isCommutative() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ public RingElement getElement(BigInteger i) {

@Override
public double estimateCostInvPerOp() {
return Arrays.stream(rings).map(Ring::estimateCostInvPerOp).reduce(0.0, Double::sum);
// Calculate average inversion cost
return Arrays.stream(rings).map(Ring::estimateCostInvPerOp).reduce(0.0, Double::sum) / rings.length;
}

@Override
public double estimateCostNegPerOp() {
return Arrays.stream(rings).map(Ring::estimateCostNegPerOp).reduce(0.0, Double::sum);
// Calculate average negation cost
return Arrays.stream(rings).map(Ring::estimateCostNegPerOp).reduce(0.0, Double::sum) / rings.length;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,17 @@ public ExtensionFieldElement getElement(long i) {
return getElement(BigInteger.valueOf(i));
}

@Override
public double estimateCostInvPerOp() {
// Tested with base field Zp(741618179)
return 0.3;
}

@Override
public double estimateCostNegPerOp() {
return constant.getStructure().estimateCostNegPerOp();
}

/**
* Map an integer b to an element in this field.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ public IntegerElement getElement(BigInteger i) {
return new IntegerElement(i);
}

@Override
public double estimateCostInvPerOp() {
return 6;
}

@Override
public double estimateCostNegPerOp() {
return 2;
}

@Override
public IntegerElement restoreElement(Representation repr) {
return new IntegerElement(repr.bigInt().get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ public Polynomial getElement(BigInteger i) {
return new Polynomial(baseRing.getElement(i));
}

@Override
public double estimateCostInvPerOp() {
// Can only invert polynomials of degree zero
return baseRing.estimateCostInvPerOp();
}

@Override
public double estimateCostNegPerOp() {
return baseRing.estimateCostNegPerOp();
}

/**
* Returns the base ring.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.cryptimeleon.math.serialization.standalone.params;

import org.cryptimeleon.math.serialization.standalone.StandaloneReprSubTest;
import org.cryptimeleon.math.structures.groups.RingAdditiveGroupImpl;
import org.cryptimeleon.math.structures.groups.RingUnitGroupImpl;
import org.cryptimeleon.math.structures.groups.basic.BasicBilinearGroup;
import org.cryptimeleon.math.structures.groups.cartesian.ProductGroup;
import org.cryptimeleon.math.structures.groups.debug.DebugBilinearGroup;
Expand Down Expand Up @@ -45,6 +43,25 @@ public void testBilinearGroup(BilinearGroup bilGroup) {
} catch (UnsupportedOperationException ignored) {}
}

public void testBilinearGroupImpl(BilinearGroupImpl bilGroup) {
test(bilGroup);
test(bilGroup.getG1());
test(bilGroup.getG2());
test(bilGroup.getGT());
try {
test(bilGroup.getHashIntoG1());
} catch (UnsupportedOperationException ignored) {}
try {
test(bilGroup.getHashIntoG2());
} catch (UnsupportedOperationException ignored) {}
try {
test(bilGroup.getHashIntoGT());
} catch (UnsupportedOperationException ignored) {}
try {
test(bilGroup.getHomomorphismG2toG1());
} catch (UnsupportedOperationException ignored) {}
}

public void testBarretoNaehrig() {
testBilinearGroup(new BarretoNaehrigBasicBilinearGroup(80));
testBilinearGroup(new BarretoNaehrigBilinearGroup(80));
Expand All @@ -64,6 +81,7 @@ public void testLazyAndBasicGroup() {

public void testDebugGroup() {
testBilinearGroup(new DebugBilinearGroup(128, BilinearGroup.Type.TYPE_1));
testBilinearGroupImpl(new DebugBilinearGroupImpl(128, BilinearGroup.Type.TYPE_1));
}

public void testExtensionField() {
Expand All @@ -86,8 +104,6 @@ public void testProductStructures() {
public void testRingGroups() {
test(zp.asUnitGroup());
test(zp.asAdditiveGroup());
test(new RingUnitGroupImpl(zp));
test(new RingAdditiveGroupImpl(zp));
}

public void testRings() {
Expand Down

0 comments on commit 5a8c6a1

Please sign in to comment.