public final class PrimeFieldElement extends Object implements FieldElement, PrimeCharacteristicFieldElement
Also note that (almost) all methods in this class work in-place. So, there is no guarantee that values input to methods in this class will not be overridden. In case of doubt and if values need to be reused, always clone the value, before inputting it to a method.
FieldElement
,
AbstractPrimeField
Modifier and Type | Method and Description |
---|---|
PrimeFieldElement |
add(GenericFieldElement b)
Adds
b to this . |
PrimeFieldElement |
addBase(GenericFieldElement b)
Adds
b to this where b is an element
of the underlying base field. |
PrimeFieldElement |
addOutOfPlace(GenericFieldElement b)
Adds
this with b which is an element of the base
field, where a new object holding the result is created. |
PrimeFieldElement |
addOutOfPlace(PrimeCharacteristicFieldElement b)
Adds two elements and returns a new object holding the result.
|
PrimeFieldElement |
clone()
Clones the value of this field element.
|
PrimeFieldElement |
divide(GenericFieldElement b)
Divides
this and another field elements. |
PrimeFieldElement |
divideBy2()
Divides
this by 2. |
boolean |
equals(Object obj) |
PrimeFieldElement |
exponentiate(BigInteger n)
Raises
this to the power n . |
PrimeFieldElement |
exponentiate(int n)
Raises
this to the power n . |
PrimeFieldElement |
exponentiateByPowerOf2(int n)
Raise
this to the power of 2^n . |
PrimeFieldElement |
exponentiateOutOfPlace(BigInteger n)
Raises
this to the power n . |
PrimeFieldElement |
exponentiateOutOfPlace(int n)
Raises
this to the power n . |
int |
getBit(int index)
Returns the value of a certain bit of
this . |
AbstractPrimeField |
getField()
Returns the associated finite field.
|
int |
getQuadraticCharacter()
Implements a quadratic character, which returns -1,0,1 depending on whether
this is a quadratic non-residue modulo the prime
p , a multiple of the characteristic, or a quadratic residue. |
int |
hashCode() |
PrimeFieldElement |
invert()
Sets
this to its inverse. |
boolean |
isOne()
Determines whether
this is one. |
boolean |
isQthResidue(int q)
Returns whether
this is a q -th residue mod p. |
boolean |
isZero()
Determines whether
this is zero. |
PrimeFieldElement |
multiply(BigInteger n)
Multiples
this by n . |
PrimeFieldElement |
multiply(GenericFieldElement b)
Multiplies
this with b which is an element of the
same field. |
PrimeFieldElement |
multiplyBy2()
Multiplies
this with 2. |
PrimeFieldElement |
multiplyBy2OutOfPlace()
Multiplies
this with 2 and returns a new object holding the
result. |
PrimeFieldElement |
multiplyBy3()
Multiplies
this with 3. |
PrimeFieldElement |
multiplyBy3OutOfPlace()
Multiplies
this with 3 and returns a new object holding the
result. |
PrimeFieldElement |
multiplyByBase(GenericFieldElement b)
Multiplies
this with b which is an element of the
base field. |
PrimeFieldElement |
multiplyByBaseOutOfPlace(GenericFieldElement b)
Multiplies
this with b which is an element of the
base field, where a new object holding the result is created. |
PrimeFieldElement |
multiplyByPowerOf2(int exponent)
Multiplies
this by 2^n . |
PrimeFieldElement |
multiplyByPowerOf2OutOfPlace(int exponent)
Multiplies
this by 2^n and returns a new object
holding the result. |
PrimeFieldElement |
multiplyOutOfPlace(BigInteger n)
Multiples
this by n , where a new object holding
the result is created. |
PrimeFieldElement |
multiplyOutOfPlace(GenericFieldElement b)
Multiplies
this with b which is an element of the
same field, where a new object holding the result is created. |
PrimeFieldElement |
negate()
Returns the negative of
this . |
PrimeFieldElement |
negateOutOfPlace()
Returns the negative of
this , where a new object holding the
result is created. |
PrimeFieldElement |
square()
Computes the square of
this in-place. |
PrimeFieldElement |
squareOutOfPlace()
Computes the square of
this , where a new object holding the
result is created. |
PrimeFieldElement |
squareRoot()
Computes the square root of
this . |
PrimeFieldElement |
squareRoot(boolean checkSquare)
Computes the square root of
this . |
PrimeFieldElement |
subtract(GenericFieldElement b)
Subtracts
b from this . |
PrimeFieldElement |
subtractOutOfPlace(GenericFieldElement b)
Subtracts
b from this which is an element of the
base field, where a new object holding the result is created. |
PrimeFieldElement |
subtractOutOfPlace(PrimeCharacteristicFieldElement b)
Subtracts
b from this and returns a new object
holding the result. |
boolean |
testBit(int index)
Tests whether a certain bit of
this is set. |
BigInteger |
toBigInteger()
Returns the
BigInteger -representation of this instance. |
byte[] |
toByteArray()
Returns the
byte[] representation of this instance. |
byte[] |
toLEByteArray()
Returns the
byte[] representation of this instance in little
endian. |
String |
toString() |
public PrimeFieldElement negate()
GenericFieldElement
this
. This functions works in-place.negate
in interface FieldElement
negate
in interface GenericFieldElement
negate
in interface PrimeCharacteristicFieldElement
this
public PrimeFieldElement negateOutOfPlace()
GenericFieldElement
this
, where a new object holding the
result is created.negateOutOfPlace
in interface GenericFieldElement
negateOutOfPlace
in interface PrimeCharacteristicFieldElement
this
public PrimeFieldElement add(GenericFieldElement b)
GenericFieldElement
b
to this
. This functions works in-place.add
in interface FieldElement
add
in interface GenericFieldElement
add
in interface PrimeCharacteristicFieldElement
b
- the second addendthis
and b
public PrimeFieldElement addOutOfPlace(GenericFieldElement b)
GenericFieldElement
this
with b
which is an element of the base
field, where a new object holding the result is created.addOutOfPlace
in interface GenericFieldElement
addOutOfPlace
in interface PrimeCharacteristicFieldElement
b
- the second factorthis
and b
public PrimeFieldElement addOutOfPlace(PrimeCharacteristicFieldElement b)
PrimeCharacteristicFieldElement
addOutOfPlace
in interface PrimeCharacteristicFieldElement
b
- the other valuepublic PrimeFieldElement addBase(GenericFieldElement b)
GenericFieldElement
b
to this
where b
is an element
of the underlying base field.addBase
in interface FieldElement
addBase
in interface GenericFieldElement
addBase
in interface PrimeCharacteristicFieldElement
b
- the second addendthis
and b
public PrimeFieldElement subtract(GenericFieldElement b)
GenericFieldElement
b
from this
. This functions works in-place.subtract
in interface FieldElement
subtract
in interface GenericFieldElement
subtract
in interface PrimeCharacteristicFieldElement
b
- the subtrahendthis
and b
public PrimeFieldElement subtractOutOfPlace(GenericFieldElement b)
GenericFieldElement
b
from this
which is an element of the
base field, where a new object holding the result is created.subtractOutOfPlace
in interface GenericFieldElement
subtractOutOfPlace
in interface PrimeCharacteristicFieldElement
b
- the second factorthis
and b
public PrimeFieldElement subtractOutOfPlace(PrimeCharacteristicFieldElement b)
PrimeCharacteristicFieldElement
b
from this
and returns a new object
holding the result.subtractOutOfPlace
in interface PrimeCharacteristicFieldElement
b
- the subtrahendthis
and b
public PrimeFieldElement invert()
GenericFieldElement
this
to its inverse.invert
in interface FieldElement
invert
in interface GenericFieldElement
invert
in interface PrimeCharacteristicFieldElement
this
public PrimeFieldElement multiply(GenericFieldElement b)
GenericFieldElement
this
with b
which is an element of the
same field.multiply
in interface FieldElement
multiply
in interface GenericFieldElement
multiply
in interface PrimeCharacteristicFieldElement
b
- the second factorthis
and b
public PrimeFieldElement multiplyOutOfPlace(GenericFieldElement b)
GenericFieldElement
this
with b
which is an element of the
same field, where a new object holding the result is created.multiplyOutOfPlace
in interface FieldElement
multiplyOutOfPlace
in interface GenericFieldElement
multiplyOutOfPlace
in interface PrimeCharacteristicFieldElement
b
- the second factorthis
and b
public PrimeFieldElement multiply(BigInteger n)
GenericFieldElement
this
by n
.multiply
in interface FieldElement
multiply
in interface GenericFieldElement
multiply
in interface PrimeCharacteristicFieldElement
n
- the factorthis
and n
public PrimeFieldElement multiplyOutOfPlace(BigInteger n)
GenericFieldElement
this
by n
, where a new object holding
the result is created.multiplyOutOfPlace
in interface FieldElement
multiplyOutOfPlace
in interface GenericFieldElement
multiplyOutOfPlace
in interface PrimeCharacteristicFieldElement
n
- the factorthis
and n
public PrimeFieldElement multiplyByBase(GenericFieldElement b)
GenericFieldElement
this
with b
which is an element of the
base field.multiplyByBase
in interface FieldElement
multiplyByBase
in interface GenericFieldElement
multiplyByBase
in interface PrimeCharacteristicFieldElement
b
- the second factorthis
and b
public PrimeFieldElement multiplyByBaseOutOfPlace(GenericFieldElement b)
GenericFieldElement
this
with b
which is an element of the
base field, where a new object holding the result is created.multiplyByBaseOutOfPlace
in interface FieldElement
multiplyByBaseOutOfPlace
in interface GenericFieldElement
multiplyByBaseOutOfPlace
in interface PrimeCharacteristicFieldElement
b
- the second factorthis
and b
public PrimeFieldElement multiplyBy2()
PrimeCharacteristicFieldElement
this
with 2.multiplyBy2
in interface PrimeCharacteristicFieldElement
this
and 2public PrimeFieldElement multiplyBy2OutOfPlace()
PrimeCharacteristicFieldElement
this
with 2 and returns a new object holding the
result.multiplyBy2OutOfPlace
in interface PrimeCharacteristicFieldElement
this
and 2public PrimeFieldElement multiplyBy3()
PrimeCharacteristicFieldElement
this
with 3.multiplyBy3
in interface PrimeCharacteristicFieldElement
this
and 3public PrimeFieldElement multiplyBy3OutOfPlace()
PrimeCharacteristicFieldElement
this
with 3 and returns a new object holding the
result.multiplyBy3OutOfPlace
in interface PrimeCharacteristicFieldElement
this
and 3public PrimeFieldElement multiplyByPowerOf2(int exponent)
PrimeCharacteristicFieldElement
this
by 2^n
.multiplyByPowerOf2
in interface PrimeCharacteristicFieldElement
exponent
- the exponentthis
and 2^npublic PrimeFieldElement multiplyByPowerOf2OutOfPlace(int exponent)
PrimeCharacteristicFieldElement
this
by 2^n
and returns a new object
holding the result.multiplyByPowerOf2OutOfPlace
in interface PrimeCharacteristicFieldElement
exponent
- the exponentthis
and 2^npublic PrimeFieldElement divide(GenericFieldElement b)
this
and another field elements.
You have no guarantee that b
remains unchanged.
divide
in interface FieldElement
divide
in interface GenericFieldElement
divide
in interface PrimeCharacteristicFieldElement
b
- the divisorthis
and b
public PrimeFieldElement divideBy2()
PrimeCharacteristicFieldElement
this
by 2.divideBy2
in interface PrimeCharacteristicFieldElement
this
divided by 2.public PrimeFieldElement square()
GenericFieldElement
this
in-place.square
in interface FieldElement
square
in interface GenericFieldElement
square
in interface PrimeCharacteristicFieldElement
this
public PrimeFieldElement squareOutOfPlace()
GenericFieldElement
this
, where a new object holding the
result is created.squareOutOfPlace
in interface FieldElement
squareOutOfPlace
in interface GenericFieldElement
squareOutOfPlace
in interface PrimeCharacteristicFieldElement
this
public AbstractPrimeField getField()
GenericFieldElement
getField
in interface GenericFieldElement
public boolean testBit(int index)
FieldElement
this
is set.testBit
in interface FieldElement
index
- the index of the bitpublic int getBit(int index)
FieldElement
this
.getBit
in interface FieldElement
index
- the index of the bitpublic boolean isOne()
GenericFieldElement
this
is one.isOne
in interface GenericFieldElement
this
is the one elementpublic boolean isZero()
GenericFieldElement
this
is zero.isZero
in interface GenericFieldElement
this
is the zero elementpublic PrimeFieldElement exponentiate(BigInteger n)
GenericFieldElement
this
to the power n
.
Works in-place.exponentiate
in interface FieldElement
exponentiate
in interface GenericFieldElement
exponentiate
in interface PrimeCharacteristicFieldElement
n
- the exponentn
th power of this
public PrimeFieldElement exponentiate(int n)
GenericFieldElement
this
to the power n
.
Works in-place.exponentiate
in interface GenericFieldElement
exponentiate
in interface PrimeCharacteristicFieldElement
n
- the exponentn
th power of this
public PrimeFieldElement exponentiateOutOfPlace(BigInteger n)
GenericFieldElement
this
to the power n
.exponentiateOutOfPlace
in interface GenericFieldElement
n
- the exponentn
th power of this
public PrimeFieldElement exponentiateOutOfPlace(int n)
GenericFieldElement
this
to the power n
.exponentiateOutOfPlace
in interface GenericFieldElement
n
- the exponentn
th power of this
public PrimeFieldElement exponentiateByPowerOf2(int n)
GenericFieldElement
this
to the power of 2^n
.exponentiateByPowerOf2
in interface GenericFieldElement
exponentiateByPowerOf2
in interface PrimeCharacteristicFieldElement
n
- the exponentn
-th power of this
.public PrimeFieldElement squareRoot()
FieldElement
this
.squareRoot
in interface FieldElement
squareRoot
in interface GenericFieldElement
squareRoot
in interface PrimeCharacteristicFieldElement
this
public PrimeFieldElement squareRoot(boolean checkSquare)
PrimeCharacteristicFieldElement
this
.squareRoot
in interface PrimeCharacteristicFieldElement
checkSquare
- check if a
is a square. If true
, the
return value is undefined for non-squares.this
public int getQuadraticCharacter()
this
is a quadratic non-residue modulo the prime
p
, a multiple of the characteristic, or a quadratic residue.
In this case this is the Legendre symbol according to [2, Algorithm 11.19].getQuadraticCharacter
in interface PrimeCharacteristicFieldElement
(this/p)
public BigInteger toBigInteger()
FieldElement
BigInteger
-representation of this instance.toBigInteger
in interface FieldElement
BigInteger
-representationpublic byte[] toByteArray()
GenericFieldElement
byte[]
representation of this instance.toByteArray
in interface GenericFieldElement
byte[]
representationpublic byte[] toLEByteArray()
byte[]
representation of this instance in little
endian.byte[]
representationpublic int hashCode()
hashCode
in interface GenericFieldElement
hashCode
in class Object
public boolean equals(Object obj)
equals
in interface GenericFieldElement
equals
in class Object
public PrimeFieldElement clone()
FieldElement
clone
in interface FieldElement
clone
in interface GenericFieldElement
clone
in interface PrimeCharacteristicFieldElement
clone
in class Object
public String toString()
toString
in interface GenericFieldElement
toString
in class Object
public boolean isQthResidue(int q)
this
is a q
-th residue mod p.q
- the exponenttrue
if this
is a q
-th
residue mod p.Copyright © 2011–2022 Stiftung SIC. All rights reserved.