public interface GroupElement extends Element, UniqueByteRepresentable
Potential calls here may return immediately and not block.
For example, g.op(h) may immediately return an object representing the
result of the group operation applied to g and h. This object is usable as such.
Internally, however, the actual computation of the group operation may be deferred
until the value is really needed.
This has performance advantages, for example, we can use multi-exponentiation
algorithms for computations of values like g.pow(x).op(h.pow(y)).
You can (but don't have to) call compute() on a group element.
This will start computing its actual value asynchronously in the background.
Example (ElGamal encryption):
c0 = g.pow(r).compute(); // will return immediately, but compute g^r in the background. c1 = h.pow(r).op(m).compute(); // will also start computing (in parallel) c0.getRepresentation(); // will block until the value of c0 is ready. c1.getRepresentation(); // will block until the value of c1 is ready.Without the
compute() calls, the example still produces the same output,
but c0 and c1 will be computed sequentially.
Implementations must properly implement equals() and hashCode().
| Modifier and Type | Method and Description |
|---|---|
GroupElement |
compute()
Hint that the concrete value of this GroupElement will be accessed soon
(e.g., via
getRepresentation() or equals()). |
GroupElement |
computeSync()
Will compute stuff synchronously (this call blocks) so that the next call
requiring the concrete value of this group element can immediately retrieve it.
|
default GroupElementConstantExpr |
expr()
Returns a
GroupElementExpression
containing exactly this group element. |
Group |
getStructure()
Returns the
Structure that this Element belongs to. |
GroupElement |
inv()
Calculates the inverse of this group element.
|
boolean |
isComputed()
Returns true if a concrete value has already been computed.
|
default GroupEqualityExpr |
isEqualTo(GroupElement other)
Returns an expression of the form "this == other".
|
default GroupEqualityExpr |
isEqualTo(GroupElementExpression expr)
Returns an expression of the form "this == expr".
|
default GroupEqualityExpr |
isEqualTo(java.lang.String expr)
Returns an expression of the form "this == expr".
|
default boolean |
isNeutralElement()
Returns true iff this is the neutral element of the group.
|
GroupElement |
op(Element e)
Calculates the result of
this.op(e). |
default GroupElementExpression |
op(GroupElementExpression e) |
default GroupElementExpression |
op(java.lang.String variable) |
GroupElement |
pow(java.math.BigInteger exponent)
Calculates the result of applying the group operation k times.
|
default GroupElementExpression |
pow(ExponentExpr exponent) |
default GroupElement |
pow(long k)
Calculates the result of applying the group operation k times.
|
default GroupElement |
pow(RingElement k)
Calculates the result of applying the group operation k times.
|
default GroupElementExpression |
pow(java.lang.String variable) |
default GroupElementVector |
pow(Vector<? extends RingElement> exponents)
Computes vector
(g.pow(exponents[0]), g.pow(exponents[1]), ...). |
default GroupElement |
pow(Zn.ZnElement k)
Calculates the result of applying the group operation k times.
|
default GroupElement |
precomputePow()
Advises the
GroupElement to prepare it for later pow() calls. |
GroupElement |
precomputePow(int windowSize)
Advises the
GroupElement to prepare it for later pow() calls. |
default GroupElement |
square()
Computes
this.op(this). |
getRepresentationgetUniqueByteRepresentation, updateAccumulatorGroup getStructure()
ElementStructure that this Element belongs to.getStructure in interface ElementGroupElement inv()
x such that x.op(this).equals(getStructure().getNeutralElement())GroupElement op(Element e) throws java.lang.IllegalArgumentException
this.op(e).e - right hand side of the operationjava.lang.IllegalArgumentException - if e is of the wrong typedefault GroupElementExpression op(GroupElementExpression e)
default GroupElementExpression op(java.lang.String variable)
default GroupElement square()
this.op(this).
Useful if this group allows squaring to be more efficiently implemented than general exponentiation as is the case for elliptic curves.
GroupElement pow(java.math.BigInteger exponent)
this.inv().pow(-k).default GroupElement pow(Zn.ZnElement k)
getStructure().size() divides n.default GroupElement pow(RingElement k)
this.getStructure().size() divides k.getStructure().getCharacteristic()
and k.asInteger() doesn't throw an exception.default GroupElement pow(long k)
this.inv().pow(-k).
The caller should be aware that usually, exponents for large groups will not usually
fit into a long value (use pow(BigInteger) or pow(ZnElement)
if your exponent is large).
default GroupElementVector pow(Vector<? extends RingElement> exponents)
(g.pow(exponents[0]), g.pow(exponents[1]), ...).exponents - the exponents to use(g.pow(exponents[0]), g.pow(exponents[1]), ...)default GroupElementExpression pow(ExponentExpr exponent)
default GroupElementExpression pow(java.lang.String variable)
default boolean isNeutralElement()
default GroupElementConstantExpr expr()
GroupElementExpression
containing exactly this group element.default GroupEqualityExpr isEqualTo(GroupElementExpression expr)
GroupElements, just use Element.equals(Object).expr - an expression to compare this group element todefault GroupEqualityExpr isEqualTo(java.lang.String expr)
GroupElements, just use Element.equals(Object).expr - an expression to compare this group element todefault GroupEqualityExpr isEqualTo(GroupElement other)
GroupElements, just use Element.equals(Object).other - another group element to compare this group element todefault GroupElement precomputePow()
GroupElement to prepare it for later pow() calls.
This will take some time and should only be done ahead of time.
That is, the usual usage pattern should be:
//Setting up your encryption scheme (or whatever)
GroupElement g = group.getUniformlyRandomElement().precomputePow();
//Then (maybe even multiple) future calls of
GroupElement encrypt(GroupElement m) {
return m.op(g.pow(sk)).compute();
}
Don't use g.precomputePow().pow(x).compute();
unless you're planning to do more exponentiations of g in the future.
Uses a reasonable default for the memory consumed by this.
Use precomputePow(int) to customize.GroupElement precomputePow(int windowSize)
GroupElement to prepare it for later pow() calls.
This will take some time and should only be done ahead of time.
That is, the usual usage pattern should be:
//Setting up your encryption scheme (or whatever)
GroupElement g = group.getUniformlyRandomElement().precomputePow();
//Then (maybe even multiple) future calls of
GroupElement encrypt(GroupElement m) {
return m.op(g.pow(sk)).compute();
}
Don't use g.precomputePow().pow(x).compute();
unless you're planning to do more exponentiations of g in the future.windowSize - an indicator for how much memory you're willing to invest.
Precomputation will take up space of roughly 2^(windowSize) group elements.GroupElement compute()
getRepresentation() or equals()). Will start computing stuff in the background.GroupElement computeSync()
compute()
which does the same, but asynchronously (i.e. concurrently).boolean isComputed()