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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
## Math

The Cryptimeleon Math library provides the mathematical foundation for the other Cryptimeleon libraries.
It provides basics such as mathematical groups, rings and fields, e.g. Zn, as well as implementations of cryptographic pairings.
Furthermore, it provides serialization support for the implemented structures.
It implements basics such as mathematical groups, rings and fields, e.g. Zn, as well as implementations of cryptographic pairings.
Furthermore, it offers serialization support for the implemented structures.

## Security Disclaimer
**WARNING: This library is meant to be used for prototyping and as a research tool *only*. It has not been sufficiently vetted for use in security-critical production environments. All implementations are to be considered experimental.**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.cryptimeleon.math.serialization.converter.JSONConverter;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
Expand Down Expand Up @@ -67,12 +68,18 @@ public Object recreateRepresentable() {
if (c.isEnum()) {
return Enum.valueOf((Class<? extends Enum>) c, representation.str().get());
}
return c.getConstructor(Representation.class).newInstance(representation);
} catch (NoSuchMethodException e) { //no constructor with single Representation paramenter
if (representation == null) //no representation necessary. Try default constructor
return c.getConstructor(new Class<?>[]{}).newInstance();
else
Constructor<?> constructor = c.getConstructor(Representation.class);
constructor.setAccessible(true);
return constructor.newInstance(representation);
} catch (NoSuchMethodException e) { //no constructor with single Representation parameter
if (representation == null) {
// no representation necessary. Try default constructor
Constructor<?> constructor = c.getConstructor(new Class<?>[]{});
constructor.setAccessible(true);
return constructor.newInstance();
} else {
throw e;
}
}
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Cannot find class " + representedTypeName, e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package org.cryptimeleon.math.serialization.annotations.internal;
package org.cryptimeleon.math.serialization.annotations;

import org.cryptimeleon.math.serialization.ListRepresentation;
import org.cryptimeleon.math.serialization.Representation;
import org.cryptimeleon.math.serialization.annotations.RepresentationRestorer;

import java.lang.reflect.Array;
import java.lang.reflect.Type;
Expand All @@ -11,7 +10,7 @@
/**
* A handler for serializing/deserializing arrays.
*/
public class ArrayRepresentationHandler implements RepresentationHandler {
class ArrayRepresentationHandler implements RepresentationHandler {
/**
* Handler for the array elements.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package org.cryptimeleon.math.serialization.annotations.internal;
package org.cryptimeleon.math.serialization.annotations;

import org.cryptimeleon.math.serialization.Representable;
import org.cryptimeleon.math.serialization.Representation;
import org.cryptimeleon.math.serialization.annotations.RepresentationRestorer;

import java.lang.reflect.Type;
import java.util.function.Function;

/**
* Handles representations that depend on some {@link RepresentationRestorer} in order to be recreated.
*/
public class DependentRepresentationHandler implements RepresentationHandler {
class DependentRepresentationHandler implements RepresentationHandler {
/**
* Restorer string indicating the {@code RepresentationRestorer} to use.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package org.cryptimeleon.math.serialization.annotations.internal;
package org.cryptimeleon.math.serialization.annotations;

import org.cryptimeleon.math.serialization.ListRepresentation;
import org.cryptimeleon.math.serialization.Representation;
import org.cryptimeleon.math.serialization.annotations.RepresentationRestorer;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.ParameterizedType;
Expand All @@ -13,7 +12,7 @@
/**
* A handler for serializing/deserializing {@link List} and {@link Set} instances.
*/
public class ListAndSetRepresentationHandler implements RepresentationHandler {
class ListAndSetRepresentationHandler implements RepresentationHandler {
private static final Class<?>[] supportedFallbackClasses = new Class[] {ArrayList.class, HashSet.class};

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package org.cryptimeleon.math.serialization.annotations.internal;
package org.cryptimeleon.math.serialization.annotations;

import org.cryptimeleon.math.serialization.MapRepresentation;
import org.cryptimeleon.math.serialization.Representation;
import org.cryptimeleon.math.serialization.annotations.RepresentationRestorer;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.ParameterizedType;
Expand All @@ -14,7 +13,7 @@
/**
* A handler for serializing/deserializing {@link Map} instances.
*/
public class MapRepresentationHandler implements RepresentationHandler {
class MapRepresentationHandler implements RepresentationHandler {
/**
* Handler for the map's keys.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.cryptimeleon.math.serialization.ObjectRepresentation;
import org.cryptimeleon.math.serialization.Representation;
import org.cryptimeleon.math.serialization.annotations.internal.*;
import org.cryptimeleon.math.structures.groups.elliptic.BilinearGroup;
import org.cryptimeleon.math.structures.groups.elliptic.BilinearMap;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cryptimeleon.math.serialization.annotations.internal;
package org.cryptimeleon.math.serialization.annotations;

import org.cryptimeleon.math.serialization.Representation;
import org.cryptimeleon.math.serialization.annotations.RepresentationRestorer;
Expand All @@ -8,7 +8,7 @@
/**
* Interface for classes that can serialize and deserialize specific types of objects.
*/
public interface RepresentationHandler {
interface RepresentationHandler {
/**
* Deserializes the given representation using the given representation restorers.
* @param repr the representation to deserialize
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.cryptimeleon.math.serialization.annotations.internal;
package org.cryptimeleon.math.serialization.annotations;

import org.cryptimeleon.math.serialization.*;
import org.cryptimeleon.math.serialization.annotations.RepresentationRestorer;

import java.lang.reflect.Type;
import java.math.BigInteger;
Expand All @@ -11,7 +10,7 @@
* Handles serialization/deserialization of the representation of {@link StandaloneRepresentable} implementers
* and some other simple types.
*/
public class StandaloneRepresentationHandler implements RepresentationHandler {
class StandaloneRepresentationHandler implements RepresentationHandler {

// it may be temping to add int.class etc. here, but it doesn't work because the ReprUtil assumes that everything
// that's not null is already set (and int is auto-initialized with 0)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
import java.math.BigInteger;

/**
* Immutable objects representing elements of a group.
* <p>
* Usually wrapped by a {@link GroupElement} to offer additional evaluation capabilities.
* Immutable objects representing elements of a group usually wrapped by a {@link GroupElement} to offer
* additional evaluation capabilities.
* <p>
* Implementations must properly implement {@code equals()} and {@code hashCode()}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
import java.util.Optional;

/**
* A Group. Operations are defined on its elements.
* <p>
* Usually wrapped by a {@link Group} to offer additional evaluation capabilities.
* An algebraic group implementation which can be wrapped by a {@link Group} to offer additional evaluation capabilities.
* Operations are defined on its elements.
*
* @see Group for the wrapper class
* @see GroupElementImpl for the element class
*/
public interface GroupImpl extends StandaloneRepresentable, RepresentationRestorer {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* Allows interpreting a ring as its additive group.
*/
public class RingAdditiveGroupImpl extends RingGroupImpl {
class RingAdditiveGroupImpl extends RingGroupImpl {

/**
* Instantiates this ring additive group.
Expand All @@ -37,9 +37,7 @@ public boolean hasPrimeSize() {

@Override
public double estimateCostInvPerOp() {
// Does not really work here since the numbers depend on the exact ring
// Used Zn(2^128) here
return 1;
return ring.estimateCostNegPerOp();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.cryptimeleon.math.structures.rings.RingElement;

/**
* Represents a group instantiated from either the additive or unit groups from a ring.
* Represents a group instantiated from either the additive or unit group of a ring.
*/
public class RingGroup extends BasicGroup {
protected RingGroup(GroupImpl impl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Common base class for ring subgroups (additive/unit groups).
*/
public abstract class RingGroupImpl implements GroupImpl {
abstract class RingGroupImpl implements GroupImpl {
protected final Ring ring;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* The unit group consists of the set of elements with a multiplicative inverse.
* The group operation is multiplication and the neutral element is called the one element.
*/
public class RingUnitGroupImpl extends RingGroupImpl {
class RingUnitGroupImpl extends RingGroupImpl {
public RingUnitGroupImpl(Ring ring) {
super(ring);
}
Expand All @@ -41,9 +41,7 @@ public boolean hasPrimeSize() {

@Override
public double estimateCostInvPerOp() {
// Does not really work here since the numbers depend on the exact ring
// Used Zn(2^128) here
return 0.1;
return ring.estimateCostInvPerOp();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.cryptimeleon.math.serialization.annotations.Represented;
import org.cryptimeleon.math.structures.groups.Group;
import org.cryptimeleon.math.structures.groups.GroupElement;
import org.cryptimeleon.math.structures.groups.lazy.ConstLazyGroupElement;
import org.cryptimeleon.math.structures.groups.lazy.LazyGroup;
import org.cryptimeleon.math.structures.groups.lazy.LazyGroupElement;
import org.cryptimeleon.math.structures.rings.zn.Zn;
Expand Down Expand Up @@ -104,8 +103,8 @@ public GroupElement restoreElement(Representation repr) {
public DebugGroupElement wrap(Zn.ZnElement elem) {
return new DebugGroupElement(
this,
new ConstLazyGroupElement(groupTotal, ((DebugGroupImpl) groupTotal.getImpl()).wrap(elem)),
new ConstLazyGroupElement(groupExpMultiExp, ((DebugGroupImpl) groupExpMultiExp.getImpl()).wrap(elem))
groupTotal.wrap(((DebugGroupImpl) groupTotal.getImpl()).wrap(elem)),
groupExpMultiExp.wrap(((DebugGroupImpl) groupExpMultiExp.getImpl()).wrap(elem))
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/**
* Contains an implementation of a fast, but insecure, bilinear pairing.
* Also allows for counting group operations and pairings.
* <p>
* The non-impl classes should be preferred unless you specifically need the impl class,
* e.g. for testing a specific {@link org.cryptimeleon.math.structures.groups.Group}.
*/
package org.cryptimeleon.math.structures.groups.debug;
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package org.cryptimeleon.math.structures.groups.elliptic;

import org.cryptimeleon.math.serialization.ObjectRepresentation;
import org.cryptimeleon.math.serialization.RepresentableRepresentation;
import org.cryptimeleon.math.serialization.Representation;
import org.cryptimeleon.math.structures.groups.GroupElementImpl;
import org.cryptimeleon.math.structures.rings.FieldElement;
import org.cryptimeleon.math.structures.rings.extfield.ExtensionField;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public int hashCode() {
}

/**
* A hash function mapping bit strings into the group such that
* A hash function mapping bit strings into Secp256k1.
*/
public static class HashIntoSecp256k1 implements HashIntoGroupImpl {
private final HashIntoZp hash;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.cryptimeleon.math.structures.groups.elliptic.type1.supersingular;

import org.cryptimeleon.math.serialization.Representation;
import org.cryptimeleon.math.structures.groups.basic.BasicBilinearGroup;

/**
* A type 1 supersingular bilinear group where operations are evaluated naively, that is, not lazily.
*
* @see SupersingularBilinearGroup for the version with lazy evaluation
*/
public class SupersingularBasicBilinearGroup extends BasicBilinearGroup {

public SupersingularBasicBilinearGroup(int securityParameter) {
super(new SupersingularTateGroupImpl(securityParameter));
}

public SupersingularBasicBilinearGroup(Representation repr) {
super(repr);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import org.cryptimeleon.math.structures.groups.lazy.LazyBilinearGroup;

/**
* Offers a less verbose way to instantiate a Supersingular bilinear group which uses lazy evaluation.
* A type 1 supersingular bilinear group where operations are evaluated lazily.
* <p>
* Essentially just a {@link LazyBilinearGroup} wrapper around {@link SupersingularTateGroupImpl}.
* Due to lazy evaluation, this group is more efficient than its non-lazy counterpart
* {@link SupersingularBasicBilinearGroup}.
*
* @see SupersingularTateGroupImpl
* @see SupersingularBasicBilinearGroup for the version without lazy evaluation
*/
public class SupersingularBilinearGroup extends LazyBilinearGroup {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @see SupersingularSourceGroupImpl
*/
public class SupersingularSourceGroupElementImpl extends PairingSourceGroupElement {
class SupersingularSourceGroupElementImpl extends PairingSourceGroupElement {

public SupersingularSourceGroupElementImpl(SupersingularSourceGroupImpl curve, FieldElement x, FieldElement y) {
super(curve, x, y);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Let \(E := {(x,y) \in \mathbb{F}_q \times \mathbb{F}_q | y^2 = x^3 - 3x}\) (\(q\) prime and \(q = 3 \mod 4\)).
* Then this class represents E[getSize()], i.e. the subgroup of size getSize().
*/
public class SupersingularSourceGroupImpl extends PairingSourceGroupImpl {
class SupersingularSourceGroupImpl extends PairingSourceGroupImpl {

/**
* Instantiates the group.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.cryptimeleon.math.structures.rings.extfield.ExtensionFieldElement;
import org.cryptimeleon.math.structures.rings.zn.HashIntoZn;

public class SupersingularSourceHash implements HashIntoGroupImpl {
class SupersingularSourceHash implements HashIntoGroupImpl {
private SupersingularSourceGroupImpl codomain;

public SupersingularSourceHash(SupersingularSourceGroupImpl codomain) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* @see PairingTargetGroupElementImpl
*/
public class SupersingularTargetGroupElementImpl extends PairingTargetGroupElementImpl {
class SupersingularTargetGroupElementImpl extends PairingTargetGroupElementImpl {

public SupersingularTargetGroupElementImpl(PairingTargetGroupImpl g, ExtensionFieldElement fe) {
super(g, fe);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* @see PairingTargetGroupImpl
*/
public class SupersingularTargetGroupImpl extends PairingTargetGroupImpl {
class SupersingularTargetGroupImpl extends PairingTargetGroupImpl {

public SupersingularTargetGroupImpl(ExtensionField f, BigInteger size) {
super(f, size);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* The implementation of our supersingular bilinear group.
*/
public class SupersingularTateGroupImpl implements BilinearGroupImpl {
class SupersingularTateGroupImpl implements BilinearGroupImpl {

@Represented
private Integer securityParameter;
Expand Down
Loading