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
a is 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, getP
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getFieldSize
public static final String PRIME_FIELD_OID
public final PrimeFieldElement add(GenericFieldElement a, GenericFieldElement b)
GenericField
b
to a
, i.e. performs the operation
a += b
.add
in interface Field
add
in interface GenericField
add
in interface PrimeCharacteristicField
a
- the first addendb
- the second addenda
and b
public final PrimeFieldElement addOutOfPlace(PrimeCharacteristicFieldElement a, PrimeCharacteristicFieldElement b)
PrimeCharacteristicField
addOutOfPlace
in interface PrimeCharacteristicField
a
- first summandb
- second summandpublic final PrimeFieldElement subtract(GenericFieldElement a, GenericFieldElement b)
GenericField
b
from a
, i.e. performs the operation
a -= b
.subtract
in interface Field
subtract
in interface GenericField
subtract
in interface PrimeCharacteristicField
a
- the minuendb
- the subtrahenda
and b
public final PrimeFieldElement subtractOutOfPlace(GenericFieldElement a, GenericFieldElement b)
PrimeCharacteristicField
b
from this
and returns a new object
holding the result.subtractOutOfPlace
in interface PrimeCharacteristicField
a
- the minuendb
- the subtrahenda
and b
public final PrimeFieldElement negate(GenericFieldElement a)
GenericField
a
, i.e. performs the operation b = -b
.negate
in interface Field
negate
in interface GenericField
negate
in interface PrimeCharacteristicField
a
- the field elementa
public PrimeFieldElement negateOutOfPlace(GenericFieldElement a)
GenericField
a
, i.e. performs the operation b = -b
,
where a new object holding the result is created.negateOutOfPlace
in interface Field
negateOutOfPlace
in interface GenericField
a
- the field elementa
public 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 Field
divide
in interface GenericField
divide
in interface PrimeCharacteristicField
a
- the dividendb
- the divisora
and b
public final PrimeFieldElement divideBy2(PrimeCharacteristicFieldElement a)
PrimeCharacteristicField
a
by 2.divideBy2
in interface PrimeCharacteristicField
a
- the dividenda
and 2.public PrimeFieldElement invert(GenericFieldElement a)
GenericField
a
, i.e. performs the operation
a = a^(-1)
.invert
in interface Field
invert
in interface GenericField
invert
in interface PrimeCharacteristicField
a
- the field elementa
public final GenericFieldElement[] invertElements(GenericFieldElement[] elements)
GenericField
invertElements
in interface GenericField
elements
- the array of field elementspublic PrimeFieldElement multiply(GenericFieldElement a, GenericFieldElement b)
GenericField
a
by b
, i.e. performs the operation
a *= b
.multiply
in interface Field
multiply
in interface GenericField
multiply
in interface PrimeCharacteristicField
a
- the first factorb
- the second factora
and b
public PrimeFieldElement multiplyOutOfPlace(GenericFieldElement a, GenericFieldElement b)
GenericField
a
by b
, i.e. performs the operation
a *= b
, where a new object holding the result is created.multiplyOutOfPlace
in interface Field
multiplyOutOfPlace
in interface GenericField
a
- the first factorb
- the second factora
and b
public PrimeFieldElement multiply(GenericFieldElement a, BigInteger n)
GenericField
a
by n
, i.e. performs the operation
a *= n
.multiply
in interface Field
multiply
in interface GenericField
multiply
in interface PrimeCharacteristicField
a
- the first factorn
- the second factora
and n
public PrimeFieldElement multiplyOutOfPlace(GenericFieldElement a, BigInteger n)
GenericField
a
by n
, i.e. performs the operation
a *= n
, where a new object holding the result is created.multiplyOutOfPlace
in interface Field
multiplyOutOfPlace
in interface GenericField
a
- the first factorn
- the second factora
and n
public final PrimeFieldElement multiplyBy2(PrimeCharacteristicFieldElement a)
PrimeCharacteristicField
a
by 2
, which is a left-shift. Works in-place.multiplyBy2
in interface PrimeCharacteristicField
a
- the element to be shifteda
holding the resultpublic final PrimeFieldElement multiplyBy2OutOfPlace(PrimeCharacteristicFieldElement a)
PrimeCharacteristicField
a
by 2
, which is a left-shift and
returns a new object holding the result.multiplyBy2OutOfPlace
in interface PrimeCharacteristicField
a
- the element to be shifteda
holding the resultpublic final PrimeFieldElement multiplyBy3(PrimeCharacteristicFieldElement a)
PrimeCharacteristicField
a
by 3
, which is a left-shift plus an
addition. Works in-place.multiplyBy3
in interface PrimeCharacteristicField
a
- the element to multiplieda
holding the resultpublic final PrimeFieldElement multiplyBy3OutOfPlace(PrimeCharacteristicFieldElement a)
PrimeCharacteristicField
a
by 3
, which is a left-shift plus an
addition and returns a new object holding the result.multiplyBy3OutOfPlace
in interface PrimeCharacteristicField
a
- the element to multiplieda
holding the resultpublic PrimeFieldElement multiplyByPowerOf2(PrimeCharacteristicFieldElement a, int exponent)
PrimeCharacteristicField
a
by a power of 2
, which is a
left-shift. Works in-place.multiplyByPowerOf2
in interface PrimeCharacteristicField
a
- the element to be shiftedexponent
- the power of 2a
holding the resultpublic PrimeFieldElement multiplyByPowerOf2OutOfPlace(PrimeCharacteristicFieldElement a, int exponent)
PrimeCharacteristicField
a
by a power of 2
, which is a
left-shift and returns a new object holding the result.multiplyByPowerOf2OutOfPlace
in interface PrimeCharacteristicField
a
- the element to be shiftedexponent
- the power of 2a
holding the resultpublic PrimeFieldElement square(GenericFieldElement a)
GenericField
a
, i.e. performs the operation a *= a
.square
in interface Field
square
in interface GenericField
square
in interface PrimeCharacteristicField
a
- the field elementa
public PrimeFieldElement squareOutOfPlace(GenericFieldElement a)
GenericField
a
, i.e. performs the operation a*a
,
where a new object holding the result is created.squareOutOfPlace
in interface Field
squareOutOfPlace
in interface GenericField
a
- the field elementa
public final PrimeFieldElement squareRoot(FieldElement a)
Field
squareRoot
in interface Field
a
- the field elementa
public final int getQuadraticCharacter(PrimeCharacteristicFieldElement a)
a
is 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 PrimeCharacteristicField
a
- a prime field element(a/p)
public PrimeFieldElement getOne()
GenericField
getOne
in interface Field
getOne
in interface GenericField
getOne
in interface PrimeCharacteristicField
public PrimeFieldElement getZero()
GenericField
getZero
in interface Field
getZero
in interface GenericField
getZero
in interface PrimeCharacteristicField
public final BigInteger getCardinality()
GenericField
getCardinality
in interface GenericField
BigInteger
holding the cardinalitypublic final PrimeFieldElement newElement(BigInteger b)
Field
BigInteger
representation.newElement
in interface Field
b
- the BigInteger
public final PrimeFieldElement newElement(byte[] b)
Field
byte[]
.newElement
in interface Field
newElement
in interface GenericField
newElement
in interface PrimeCharacteristicField
b
- the element encoded as byte[]
in little-endian orderpublic PrimeFieldElement toElement(byte[] bytes)
GenericField
byte
-array. Unlike
GenericField.newElement(byte[])
, this method does not assume the
input to be a valid encoding of a field element.toElement
in interface GenericField
toElement
in interface PrimeCharacteristicField
bytes
- a byte[]
in little-endian orderpublic PrimeFieldElement exponentiate(GenericFieldElement a, BigInteger n)
GenericField
a
to the power n
, i.e. performs the
operation a = a^n
.exponentiate
in interface Field
exponentiate
in interface GenericField
exponentiate
in interface PrimeCharacteristicField
a
- the field elementn
- the exponentn
th power of
a
public PrimeFieldElement exponentiate(GenericFieldElement a, int n)
GenericField
a
to the power n
, i.e. performs the
operation a = a^n
.exponentiate
in interface GenericField
a
- the field elementn
- the exponentn
th power of
a
public final PrimeFieldElement exponentiateByPowerOf2(GenericFieldElement a, int n)
GenericField
a
to the power 2n
.exponentiateByPowerOf2
in interface Field
exponentiateByPowerOf2
in interface GenericField
exponentiateByPowerOf2
in interface PrimeCharacteristicField
a
- the field elementn
- the exponentpublic byte[] toByteArray(FieldElement a)
Field
byte[]
representation.toByteArray
in interface Field
a
- the field elementbyte[]
public byte[] toLEByteArray(FieldElement a)
byte[]
representation in
little endian.a
- the field elementbyte[]
public final FieldTypes getFieldType()
GenericField
getFieldType
in interface GenericField
public final AbstractPrimeField getBaseField()
GenericField
getBaseField
in interface GenericField
public 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 Field
public final boolean equals(Object obj)
equals
in interface GenericField
equals
in class ECFieldFp
public final int hashCode()
hashCode
in interface GenericField
hashCode
in class ECFieldFp
public 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 PrimeCharacteristicField
public final PrimeFieldElement getUniformlyRandomNonZeroElement()
getUniformlyRandomNonZeroElement
in interface PrimeCharacteristicField
Copyright © 2011–2022 Stiftung SIC. All rights reserved.