public abstract class AbstractPrimeField extends ECFieldFp implements Field, PrimeCharacteristicField
Fp of
odd characteristic. Although it has been optimized for speed there are still
more specific (i.e. faster) classes, which are part of the addon.
Note that due to reasons of performance the arithmetical methods of this class do not check, whether the inputs are valid elements of this field.
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.
References:
[1] Darrel Hankerson, Alfred J. Menezes and Scott Vanstone. Guide to Elliptic Curve Cryptography. Springer-Verlag New York, Inc. (2003)
[2] Henri Cohen and Gerhard Frey. Handbook of Elliptic and Hyperelliptic Curve Cryptography. Chapman & Hall/CRC (2005)
BinaryField,
PrimeFieldElement,
PrimeFieldByBitLengthFactory,
PrimeFieldByPrimeFactory| Modifier and Type | Field and Description |
|---|---|
static String |
PRIME_FIELD_OID
Object Identifier for a prime field for ASN.1 encoding.
|
| Modifier and Type | Method and Description |
|---|---|
PrimeFieldElement |
add(GenericFieldElement a,
GenericFieldElement b)
Adds
b to a, i.e. |
PrimeFieldElement |
addOutOfPlace(PrimeCharacteristicFieldElement a,
PrimeCharacteristicFieldElement b)
Adds two elements and returns a new object holding the result.
|
PrimeFieldElement |
divide(GenericFieldElement a,
GenericFieldElement b)
Divides
a by b, i.e. |
PrimeFieldElement |
divideBy2(PrimeCharacteristicFieldElement a)
Divides
a by 2. |
boolean |
equals(Object obj) |
PrimeFieldElement |
exponentiate(GenericFieldElement a,
BigInteger n)
Raises
a to the power n, i.e. |
PrimeFieldElement |
exponentiate(GenericFieldElement a,
int n)
Raises
a to the power n, i.e. |
PrimeFieldElement |
exponentiateByPowerOf2(GenericFieldElement a,
int n)
Raises
a to the power 2n. |
AbstractPrimeField |
getBaseField()
Returns the base field of this field.
|
BigInteger |
getCardinality()
Returns the cardinality of this field.
|
FieldTypes |
getFieldType()
Returns the field type of the underlying implementation.
|
PrimeFieldElement |
getOne()
Returns the one element.
|
int |
getQuadraticCharacter(PrimeCharacteristicFieldElement a)
Implements a quadratic character, which returns -1,0,1 depending on whether
the given value
ais a quadratic non-residue modulo the prime
p, a multiple of p, or a quadratic residue. |
PrimeFieldElement |
getUniformlyRandomElement()
Get a uniformly random prime field element.
|
PrimeFieldElement |
getUniformlyRandomNonZeroElement()
Get a uniformly random, non-zero prime field element.
|
PrimeFieldElement |
getZero()
Returns the zero element.
|
int |
hashCode() |
PrimeFieldElement |
invert(GenericFieldElement a)
Inverts
a, i.e. |
GenericFieldElement[] |
invertElements(GenericFieldElement[] elements)
Simultaneously inverts an an array of field elements.
|
boolean |
isQthResidue(PrimeFieldElement element,
int q)
Check if prime field element is a
q-th residue. |
PrimeFieldElement |
multiply(GenericFieldElement a,
BigInteger n)
Multiplies
a by n, i.e. |
PrimeFieldElement |
multiply(GenericFieldElement a,
GenericFieldElement b)
Multiplies
a by b, i.e. |
PrimeFieldElement |
multiplyBy2(PrimeCharacteristicFieldElement a)
Multiplies
a by 2, which is a left-shift. |
PrimeFieldElement |
multiplyBy2OutOfPlace(PrimeCharacteristicFieldElement a)
Multiplies
a by 2, which is a left-shift and
returns a new object holding the result. |
PrimeFieldElement |
multiplyBy3(PrimeCharacteristicFieldElement a)
Multiplies
a by 3, which is a left-shift plus an
addition. |
PrimeFieldElement |
multiplyBy3OutOfPlace(PrimeCharacteristicFieldElement a)
Multiplies
a by 3, which is a left-shift plus an
addition and returns a new object holding the result. |
PrimeFieldElement |
multiplyByPowerOf2(PrimeCharacteristicFieldElement a,
int exponent)
Multiplies
a by a power of 2, which is a
left-shift. |
PrimeFieldElement |
multiplyByPowerOf2OutOfPlace(PrimeCharacteristicFieldElement a,
int exponent)
Multiplies
a by a power of 2, which is a
left-shift and returns a new object holding the result. |
PrimeFieldElement |
multiplyOutOfPlace(GenericFieldElement a,
BigInteger n)
Multiplies
a by n, i.e. |
PrimeFieldElement |
multiplyOutOfPlace(GenericFieldElement a,
GenericFieldElement b)
Multiplies
a by b, i.e. |
PrimeFieldElement |
negate(GenericFieldElement a)
Negates
a, i.e. |
PrimeFieldElement |
negateOutOfPlace(GenericFieldElement a)
Negates
a, i.e. |
PrimeFieldElement |
newElement(BigInteger b)
Creates a new field element from its
BigInteger representation. |
PrimeFieldElement |
newElement(byte[] b)
Creates a new field element from a
byte[]. |
PrimeFieldElement |
square(GenericFieldElement a)
Squares
a, i.e. |
PrimeFieldElement |
squareOutOfPlace(GenericFieldElement a)
Squares
a, i.e. |
PrimeFieldElement |
squareRoot(FieldElement a)
Computes the square root of a field element.
|
PrimeFieldElement |
subtract(GenericFieldElement a,
GenericFieldElement b)
Subtracts
b from a, i.e. |
PrimeFieldElement |
subtractOutOfPlace(GenericFieldElement a,
GenericFieldElement b)
Subtracts
b from this and returns a new object
holding the result. |
iaik.asn1.SEQUENCE |
toASN1Object()
Compiles and returns the ASN.1 representation of this prime field, which
is:
|
byte[] |
toByteArray(FieldElement a)
Converts a field element to its raw
byte[] representation. |
PrimeFieldElement |
toElement(byte[] bytes)
Create new field element from a
byte-array. |
byte[] |
toLEByteArray(FieldElement a)
Converts a field element to its raw
byte[] representation in
little endian. |
String |
toString() |
getFieldSize, getPclone, finalize, getClass, notify, notifyAll, wait, wait, waitgetFieldSizepublic static final String PRIME_FIELD_OID
public final PrimeFieldElement add(GenericFieldElement a, GenericFieldElement b)
GenericFieldb to a, i.e. performs the operation
a += b.add in interface Fieldadd in interface GenericFieldadd in interface PrimeCharacteristicFielda - the first addendb - the second addenda and bpublic final PrimeFieldElement addOutOfPlace(PrimeCharacteristicFieldElement a, PrimeCharacteristicFieldElement b)
PrimeCharacteristicFieldaddOutOfPlace in interface PrimeCharacteristicFielda - first summandb - second summandpublic final PrimeFieldElement subtract(GenericFieldElement a, GenericFieldElement b)
GenericFieldb from a, i.e. performs the operation
a -= b.subtract in interface Fieldsubtract in interface GenericFieldsubtract in interface PrimeCharacteristicFielda - the minuendb - the subtrahenda and bpublic final PrimeFieldElement subtractOutOfPlace(GenericFieldElement a, GenericFieldElement b)
PrimeCharacteristicFieldb from this and returns a new object
holding the result.subtractOutOfPlace in interface PrimeCharacteristicFielda - the minuendb - the subtrahenda and bpublic final PrimeFieldElement negate(GenericFieldElement a)
GenericFielda, i.e. performs the operation b = -b.negate in interface Fieldnegate in interface GenericFieldnegate in interface PrimeCharacteristicFielda - the field elementapublic PrimeFieldElement negateOutOfPlace(GenericFieldElement a)
GenericFielda, i.e. performs the operation b = -b,
where a new object holding the result is created.negateOutOfPlace in interface FieldnegateOutOfPlace in interface GenericFielda - the field elementapublic final PrimeFieldElement divide(GenericFieldElement a, GenericFieldElement b)
a by b, i.e. performs the operation
a /= b.
You have no guarantee that the input arguments remain unchanged.
divide in interface Fielddivide in interface GenericFielddivide in interface PrimeCharacteristicFielda - the dividendb - the divisora and bpublic final PrimeFieldElement divideBy2(PrimeCharacteristicFieldElement a)
PrimeCharacteristicFielda by 2.divideBy2 in interface PrimeCharacteristicFielda - the dividenda and 2.public PrimeFieldElement invert(GenericFieldElement a)
GenericFielda, i.e. performs the operation
a = a^(-1).invert in interface Fieldinvert in interface GenericFieldinvert in interface PrimeCharacteristicFielda - the field elementapublic final GenericFieldElement[] invertElements(GenericFieldElement[] elements)
GenericFieldinvertElements in interface GenericFieldelements - the array of field elementspublic PrimeFieldElement multiply(GenericFieldElement a, GenericFieldElement b)
GenericFielda by b, i.e. performs the operation
a *= b.multiply in interface Fieldmultiply in interface GenericFieldmultiply in interface PrimeCharacteristicFielda - the first factorb - the second factora and bpublic PrimeFieldElement multiplyOutOfPlace(GenericFieldElement a, GenericFieldElement b)
GenericFielda by b, i.e. performs the operation
a *= b, where a new object holding the result is created.multiplyOutOfPlace in interface FieldmultiplyOutOfPlace in interface GenericFielda - the first factorb - the second factora and bpublic PrimeFieldElement multiply(GenericFieldElement a, BigInteger n)
GenericFielda by n, i.e. performs the operation
a *= n.multiply in interface Fieldmultiply in interface GenericFieldmultiply in interface PrimeCharacteristicFielda - the first factorn - the second factora and npublic PrimeFieldElement multiplyOutOfPlace(GenericFieldElement a, BigInteger n)
GenericFielda by n, i.e. performs the operation
a *= n, where a new object holding the result is created.multiplyOutOfPlace in interface FieldmultiplyOutOfPlace in interface GenericFielda - the first factorn - the second factora and npublic final PrimeFieldElement multiplyBy2(PrimeCharacteristicFieldElement a)
PrimeCharacteristicFielda by 2, which is a left-shift. Works in-place.multiplyBy2 in interface PrimeCharacteristicFielda - the element to be shifteda holding the resultpublic final PrimeFieldElement multiplyBy2OutOfPlace(PrimeCharacteristicFieldElement a)
PrimeCharacteristicFielda by 2, which is a left-shift and
returns a new object holding the result.multiplyBy2OutOfPlace in interface PrimeCharacteristicFielda - the element to be shifteda holding the resultpublic final PrimeFieldElement multiplyBy3(PrimeCharacteristicFieldElement a)
PrimeCharacteristicFielda by 3, which is a left-shift plus an
addition. Works in-place.multiplyBy3 in interface PrimeCharacteristicFielda - the element to multiplieda holding the resultpublic final PrimeFieldElement multiplyBy3OutOfPlace(PrimeCharacteristicFieldElement a)
PrimeCharacteristicFielda by 3, which is a left-shift plus an
addition and returns a new object holding the result.multiplyBy3OutOfPlace in interface PrimeCharacteristicFielda - the element to multiplieda holding the resultpublic PrimeFieldElement multiplyByPowerOf2(PrimeCharacteristicFieldElement a, int exponent)
PrimeCharacteristicFielda by a power of 2, which is a
left-shift. Works in-place.multiplyByPowerOf2 in interface PrimeCharacteristicFielda - the element to be shiftedexponent - the power of 2a holding the resultpublic PrimeFieldElement multiplyByPowerOf2OutOfPlace(PrimeCharacteristicFieldElement a, int exponent)
PrimeCharacteristicFielda by a power of 2, which is a
left-shift and returns a new object holding the result.multiplyByPowerOf2OutOfPlace in interface PrimeCharacteristicFielda - the element to be shiftedexponent - the power of 2a holding the resultpublic PrimeFieldElement square(GenericFieldElement a)
GenericFielda, i.e. performs the operation a *= a.square in interface Fieldsquare in interface GenericFieldsquare in interface PrimeCharacteristicFielda - the field elementapublic PrimeFieldElement squareOutOfPlace(GenericFieldElement a)
GenericFielda, i.e. performs the operation a*a,
where a new object holding the result is created.squareOutOfPlace in interface FieldsquareOutOfPlace in interface GenericFielda - the field elementapublic final PrimeFieldElement squareRoot(FieldElement a)
FieldsquareRoot in interface Fielda - the field elementapublic final int getQuadraticCharacter(PrimeCharacteristicFieldElement a)
ais a quadratic non-residue modulo the prime
p, a multiple of p, or a quadratic residue. In
this case this is the Legendre symbol according to [2, Algorithm 11.19].getQuadraticCharacter in interface PrimeCharacteristicFielda - a prime field element(a/p)public PrimeFieldElement getOne()
GenericFieldgetOne in interface FieldgetOne in interface GenericFieldgetOne in interface PrimeCharacteristicFieldpublic PrimeFieldElement getZero()
GenericFieldgetZero in interface FieldgetZero in interface GenericFieldgetZero in interface PrimeCharacteristicFieldpublic final BigInteger getCardinality()
GenericFieldgetCardinality in interface GenericFieldBigInteger holding the cardinalitypublic final PrimeFieldElement newElement(BigInteger b)
FieldBigInteger representation.newElement in interface Fieldb - the BigIntegerpublic final PrimeFieldElement newElement(byte[] b)
Fieldbyte[].newElement in interface FieldnewElement in interface GenericFieldnewElement in interface PrimeCharacteristicFieldb - the element encoded as byte[] in little-endian orderpublic PrimeFieldElement toElement(byte[] bytes)
GenericFieldbyte-array. Unlike
GenericField.newElement(byte[]), this method does not assume the
input to be a valid encoding of a field element.toElement in interface GenericFieldtoElement in interface PrimeCharacteristicFieldbytes - a byte[] in little-endian orderpublic PrimeFieldElement exponentiate(GenericFieldElement a, BigInteger n)
GenericFielda to the power n, i.e. performs the
operation a = a^n.exponentiate in interface Fieldexponentiate in interface GenericFieldexponentiate in interface PrimeCharacteristicFielda - the field elementn - the exponentnth power of
apublic PrimeFieldElement exponentiate(GenericFieldElement a, int n)
GenericFielda to the power n, i.e. performs the
operation a = a^n.exponentiate in interface GenericFielda - the field elementn - the exponentnth power of
apublic final PrimeFieldElement exponentiateByPowerOf2(GenericFieldElement a, int n)
GenericFielda to the power 2n.exponentiateByPowerOf2 in interface FieldexponentiateByPowerOf2 in interface GenericFieldexponentiateByPowerOf2 in interface PrimeCharacteristicFielda - the field elementn - the exponentpublic byte[] toByteArray(FieldElement a)
Fieldbyte[] representation.toByteArray in interface Fielda - the field elementbyte[]public byte[] toLEByteArray(FieldElement a)
byte[] representation in
little endian.a - the field elementbyte[]public final FieldTypes getFieldType()
GenericFieldgetFieldType in interface GenericFieldpublic final AbstractPrimeField getBaseField()
GenericFieldgetBaseField in interface GenericFieldpublic final iaik.asn1.SEQUENCE toASN1Object()
Compiles and returns the ASN.1 representation of this prime field, which is:
FieldID ::= SEQUENCE {
fieldType OBJECT IDENTIFIER,
parameters ANY DEFINED BY fieldType
}
toASN1Object in interface Fieldpublic final boolean equals(Object obj)
equals in interface GenericFieldequals in class ECFieldFppublic final int hashCode()
hashCode in interface GenericFieldhashCode in class ECFieldFppublic final boolean isQthResidue(PrimeFieldElement element, int q)
q-th residue.element - prime field elementq - an integerelement is a q-th residuepublic final PrimeFieldElement getUniformlyRandomElement()
getUniformlyRandomElement in interface PrimeCharacteristicFieldpublic final PrimeFieldElement getUniformlyRandomNonZeroElement()
getUniformlyRandomNonZeroElement in interface PrimeCharacteristicFieldCopyright © 2011–2022 Stiftung SIC. All rights reserved.