Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public CustomRepresentationRestorer(Function<? super Representation, ?> restorer
}

@Override
public Object recreateFromRepresentation(Type type, Representation repr) {
public Object restoreFromRepresentation(Type type, Representation repr) {
return restorer.apply(repr);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public interface RepresentationRestorer {
*
* @param type tells the restorer which type the restored object should have
* @param repr the representation to restore the object from
* @return the recreated object
* @return the restored object
* @throws IllegalArgumentException if the restorer is unable to handle the given type
*/
Object recreateFromRepresentation(Type type, Representation repr) throws IllegalArgumentException;
Object restoreFromRepresentation(Type type, Representation repr) throws IllegalArgumentException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static boolean canHandle(Type type) {

@Override
public Object deserializeFromRepresentation(Representation repr, Function<String, RepresentationRestorer> getRegisteredRestorer) {
return getRegisteredRestorer.apply(restorerString).recreateFromRepresentation(typeToRestore, repr);
return getRegisteredRestorer.apply(restorerString).restoreFromRepresentation(typeToRestore, repr);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ default boolean hasPrimeSize() {
* @param repr the {@code Representation} returned by {@link Element#getRepresentation()}
* @return the decoded element corresponding to the representation
*/
Element getElement(Representation repr);
Element restoreElement(Representation repr);

/**
* Returns the number of bytes returned by this structure's {@link Element#getUniqueByteRepresentation()},
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/org/cryptimeleon/math/structures/groups/Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ default GroupElementVector getUniformlyRandomNonNeutrals(int n) {
}

@Override
GroupElement getElement(Representation repr);
GroupElement restoreElement(Representation repr);

/**
* Recreates a {@link GroupElementVector} containing group elements from this {@code Group} from a
* Restores a {@link GroupElementVector} containing group elements from this {@code Group} from a
* {@code Representation} of that vector.
*
* @param repr a representation of a {@code GroupElementVector}
* (obtained via {@link GroupElementVector#getRepresentation()}).
*/
default GroupElementVector getVector(Representation repr) {
return GroupElementVector.fromStream(repr.list().stream().map(this::getElement));
default GroupElementVector restoreVector(Representation repr) {
return GroupElementVector.fromStream(repr.list().stream().map(this::restoreElement));
}

/**
Expand Down Expand Up @@ -91,11 +91,11 @@ default GroupElementExpression expr() {
}

@Override
default Object recreateFromRepresentation(Type type, Representation repr) {
default Object restoreFromRepresentation(Type type, Representation repr) {
if (type instanceof Class && GroupElement.class.isAssignableFrom((Class) type))
return getElement(repr);
return restoreElement(repr);
if (type instanceof Class && GroupElementVector.class.isAssignableFrom((Class) type))
return getVector(repr);
return restoreVector(repr);

throw new IllegalArgumentException("Group cannot recreate type "+type.getTypeName()+" from representation");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ default GroupElementImpl getUniformlyRandomNonNeutral() throws UnsupportedOperat
}

/**
* Recreates a group element from its representation.
* Restores a group element from its representation.
*/
GroupElementImpl getElement(Representation repr);
GroupElementImpl restoreElement(Representation repr);

/**
* Returns any generator of this group if the group is cyclic and it's feasible to compute a generator.
Expand Down Expand Up @@ -124,11 +124,11 @@ default GroupElementImpl multiexp(Multiexponentiation mexp) {
double estimateCostInvPerOp();

@Override
default GroupElementImpl recreateFromRepresentation(Type type, Representation repr) {
default GroupElementImpl restoreFromRepresentation(Type type, Representation repr) {
if (!(type instanceof Class && GroupElementImpl.class.isAssignableFrom((Class) type)))
throw new IllegalArgumentException("Group cannot recreate type "+type.getTypeName()+" from representation");

return getElement(repr);
return restoreElement(repr);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ public ByteAccumulator updateAccumulator(ByteAccumulator accumulator) {
}

@Override
public RingAdditiveGroupElementImpl getElement(Representation repr) {
return new RingAdditiveGroupElementImpl(ring.getElement(repr));
public RingAdditiveGroupElementImpl restoreElement(Representation repr) {
return new RingAdditiveGroupElementImpl(ring.restoreElement(repr));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ public ByteAccumulator updateAccumulator(ByteAccumulator accumulator) {
}

@Override
public RingUnitGroupElementImpl getElement(Representation repr) {
return new RingUnitGroupElementImpl(ring.getElement(repr));
public RingUnitGroupElementImpl restoreElement(Representation repr) {
return new RingUnitGroupElementImpl(ring.restoreElement(repr));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public GroupElement getUniformlyRandomNonNeutral() {
}

@Override
public GroupElement getElement(Representation repr) {
return wrap(impl.getElement(repr));
public GroupElement restoreElement(Representation repr) {
return wrap(impl.restoreElement(repr));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public GroupElement getUniformlyRandomElement() throws UnsupportedOperationExcep
}

@Override
public GroupElement getElement(Representation repr) {
public GroupElement restoreElement(Representation repr) {
return new ProductGroupElement(repr);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public ProductGroupElement(GroupElement... elems) {
public ProductGroupElement(Representation repr) {
this.elems = new GroupElement[repr.list().size()];
for (int i=0;i<repr.list().size();i++)
this.elems[i] = elems[i].getStructure().getElement(repr.list().get(i));
this.elems[i] = elems[i].getStructure().restoreElement(repr.list().get(i));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public GroupElement getUniformlyRandomElement() throws UnsupportedOperationExcep
}

@Override
public GroupElement getElement(Representation repr) {
public GroupElement restoreElement(Representation repr) {
return new CountingGroupElement(this, repr);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public CountingGroupElement(CountingGroup group, LazyGroupElement elemTotal, Laz
public CountingGroupElement(CountingGroup group, Representation repr) {
ObjectRepresentation objRepr = repr.obj();
this.group = group;
elemTotal = (LazyGroupElement) group.groupTotal.getElement(objRepr.get("elemTotal"));
elemExpMultiExp = (LazyGroupElement) group.groupExpMultiExp.getElement(objRepr.get("elemExpMultiExp"));
elemTotal = (LazyGroupElement) group.groupTotal.restoreElement(objRepr.get("elemTotal"));
elemExpMultiExp = (LazyGroupElement) group.groupExpMultiExp.restoreElement(objRepr.get("elemExpMultiExp"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ public GroupElementImpl getUniformlyRandomNonNeutral() throws UnsupportedOperati
}

@Override
public GroupElementImpl getElement(Representation repr) {
return wrap(zn.getElement(repr));
public GroupElementImpl restoreElement(Representation repr) {
return wrap(zn.restoreElement(repr));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public AbstractEllipticCurvePoint(WeierstrassCurve curve, FieldElement x, FieldE
}

public AbstractEllipticCurvePoint(WeierstrassCurve curve, Representation repr) {
this(curve, curve.getFieldOfDefinition().getElement(repr.obj().get("x")),
curve.getFieldOfDefinition().getElement(repr.obj().get("y")),
curve.getFieldOfDefinition().getElement(repr.obj().get("z")));
this(curve, curve.getFieldOfDefinition().restoreElement(repr.obj().get("x")),
curve.getFieldOfDefinition().restoreElement(repr.obj().get("y")),
curve.getFieldOfDefinition().restoreElement(repr.obj().get("z")));
}

public Field getFieldOfDefinition() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ public PairingSourceGroupImpl(Representation repr) {
this.size = ((BigIntegerRepresentation) or.get("size")).get();
this.cofactor = ((BigIntegerRepresentation) or.get("cofactor")).get();
this.field = (Field) ((RepresentableRepresentation) or.get("field")).recreateRepresentable();
this.a1 = this.field.getElement(or.get("a1"));
this.a2 = this.field.getElement(or.get("a2"));
this.a3 = this.field.getElement(or.get("a3"));
this.a4 = this.field.getElement(or.get("a4"));
this.a6 = this.field.getElement(or.get("a6"));
this.a1 = this.field.restoreElement(or.get("a1"));
this.a2 = this.field.restoreElement(or.get("a2"));
this.a3 = this.field.restoreElement(or.get("a3"));
this.a4 = this.field.restoreElement(or.get("a4"));
this.a6 = this.field.restoreElement(or.get("a6"));

this.setGenerator(this.getElement(or.get("generator")));
this.setGenerator(this.restoreElement(or.get("generator")));
}

@Override
Expand Down Expand Up @@ -211,11 +211,11 @@ public PairingSourceGroupElement getUniformlyRandomElement() throws UnsupportedO
}

@Override
public PairingSourceGroupElement getElement(Representation repr) {
public PairingSourceGroupElement restoreElement(Representation repr) {
ObjectRepresentation or = (ObjectRepresentation) repr;
FieldElement x = getFieldOfDefinition().getElement(or.get("x"));
FieldElement y = getFieldOfDefinition().getElement(or.get("y"));
FieldElement z = getFieldOfDefinition().getElement(or.get("z"));
FieldElement x = getFieldOfDefinition().restoreElement(or.get("x"));
FieldElement y = getFieldOfDefinition().restoreElement(or.get("y"));
FieldElement z = getFieldOfDefinition().restoreElement(or.get("z"));
if (z.isZero())
return (PairingSourceGroupElement) getNeutralElement();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ public PairingTargetGroupElementImpl getGenerator() {
}

@Override
public PairingTargetGroupElementImpl getElement(Representation repr) {
return getElement((ExtensionFieldElement) fieldOfDefinition.getElement(repr));
public PairingTargetGroupElementImpl restoreElement(Representation repr) {
return getElement((ExtensionFieldElement) fieldOfDefinition.restoreElement(repr));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public GroupElementImpl getUniformlyRandomElement() throws UnsupportedOperationE
}

@Override
public GroupElementImpl getElement(Representation repr) {
public GroupElementImpl restoreElement(Representation repr) {
return new AffineEllipticCurvePoint(this, repr);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ public GroupElement getUniformlyRandomNonNeutral() throws UnsupportedOperationEx
}

@Override
public GroupElement getElement(Representation repr) {
return wrap(impl.getElement(repr));
public GroupElement restoreElement(Representation repr) {
return wrap(impl.restoreElement(repr));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public SnElementImpl getUniformlyRandomElement() throws UnsupportedOperationExce
}

@Override
public SnElementImpl getElement(Representation repr) {
public SnElementImpl restoreElement(Representation repr) {
return new SnElementImpl(repr);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ default BigInteger sizeUnitGroup() {
FieldElement getOneElement();

@Override
FieldElement getElement(Representation repr);
FieldElement restoreElement(Representation repr);

@Override
FieldElement getElement(BigInteger i);
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/org/cryptimeleon/math/structures/rings/Ring.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,25 @@ default RingGroup asUnitGroup() {
RingElement getOneElement();

@Override
RingElement getElement(Representation repr);
RingElement restoreElement(Representation repr);

/**
* Recreates a {@link RingElementVector} containing ring elements from this {@code Ring} from a
* Restores a {@link RingElementVector} containing ring elements from this {@code Ring} from a
* {@code Representation} of that vector.
*
* @param repr a representation of a {@code RingElementVector}
* (obtained via {@link RingElementVector#getRepresentation()}).
*/
default RingElementVector getVector(Representation repr) {
return RingElementVector.fromStream(repr.list().stream().map(this::getElement));
default RingElementVector restoreVector(Representation repr) {
return RingElementVector.fromStream(repr.list().stream().map(this::restoreElement));
}

@Override
default Object recreateFromRepresentation(Type type, Representation repr) {
default Object restoreFromRepresentation(Type type, Representation repr) {
if (type instanceof Class && RingElement.class.isAssignableFrom((Class) type))
return getElement(repr);
return restoreElement(repr);
if (type instanceof Class && RingElementVector.class.isAssignableFrom((Class) type))
return getVector(repr);
return restoreVector(repr);

throw new IllegalArgumentException("Group cannot recreate type "+type.getTypeName()+" from representation");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public RingElement getOneElement() {
}

@Override
public RingElement getElement(Representation repr) {
public RingElement restoreElement(Representation repr) {
return new BooleanElement(repr);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public RingElement getOneElement() {
}

@Override
public RingElement getElement(Representation repr) {
public RingElement restoreElement(Representation repr) {
return new ProductRingElement(repr);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public ProductRingElement(RingElement... elems) {
public ProductRingElement(Representation repr) {
this.elems = new RingElement[repr.list().size()];
for (int i=0;i<repr.list().size();i++)
this.elems[i] = elems[i].getStructure().getElement(repr.list().get(i));
this.elems[i] = elems[i].getStructure().restoreElement(repr.list().get(i));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ public ExtensionField(Representation r) {
Field baseField = (Field) ((RepresentableRepresentation) o.get("baseField")).recreateRepresentable();


init(baseField.getElement(o.get("constant")), o.get("extensionDegree").bigInt().get().intValueExact());
init(baseField.restoreElement(o.get("constant")), o.get("extensionDegree").bigInt().get().intValueExact());

if (o.get("cubeRoot") != null)
this.setCubeRoot(this.getElement(o.get("cubeRoot")));
this.setCubeRoot(this.restoreElement(o.get("cubeRoot")));
}


Expand Down Expand Up @@ -295,11 +295,11 @@ public ExtensionFieldElement getOneElement() {
}

@Override
public ExtensionFieldElement getElement(Representation repr) {
public ExtensionFieldElement restoreElement(Representation repr) {
ListRepresentation lr = (ListRepresentation) repr;
FieldElement[] coefficients = new FieldElement[lr.size()];
for (int i = 0; i < lr.size(); i++)
coefficients[i] = this.getBaseField().getElement(lr.get(i));
coefficients[i] = this.getBaseField().restoreElement(lr.get(i));

return this.createElement(coefficients);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public IntegerElement getElement(BigInteger i) {
}

@Override
public IntegerElement getElement(Representation repr) {
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 @@ -82,11 +82,11 @@ public Ring getBaseRing() {
}

@Override
public Polynomial getElement(Representation arg) {
public Polynomial restoreElement(Representation arg) {
ListRepresentation repr = (ListRepresentation) arg;
RingElement[] coefficients = new RingElement[repr.size()];
for (int i = 0; i < repr.size(); i++)
coefficients[i] = baseRing.getElement(repr.get(i));
coefficients[i] = baseRing.restoreElement(repr.get(i));

return new Polynomial(coefficients);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public Representation getRepresentation() {
}

@Override
public ZnElement getElement(Representation repr) {
public ZnElement restoreElement(Representation repr) {
return createZnElement(((BigIntegerRepresentation) repr).get());
}

Expand Down
Loading