Top Description Fields Constructors Methods
org.bouncycastle.pqc.legacy.math.linearalgebra

public Class GF2mField

extends Object
Class Inheritance
Imports
java.security.SecureRandom, org.bouncycastle.crypto.CryptoServicesRegistrar

This class describes operations with elements from the finite field F = GF(2^m). ( GF(2^m)= GF(2)[A] where A is a root of irreducible polynomial with degree m, each field element B has a polynomial basis representation, i.e. it is represented by a different binary polynomial of degree less than m, B = poly(A) ) All operations are defined only for field with 1< m <32. For the representation of field elements the map f: F->Z, poly(A)->poly(2) is used, where integers have the binary representation. For example: A^7+A^3+A+1 -> (00...0010001011)=139 Also for elements type Integer is used.
See Also
PolynomialRingGF2

Field Summary

Modifier and TypeField and Description
private int
private int

Constructor Summary

AccessConstructor and Description
public
GF2mField(int
the degree of the field
degree
)

create a finite field GF(2^m)

public
GF2mField(int
the degree of the field
degree
,
int
the field polynomial
poly
)

create a finite field GF(2^m) with the fixed field polynomial

public
GF2mField(byte[] enc)

public

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

a+b
add
(int a, int b)

Return sum of two elements

public String
elementToStr(int a)

public boolean

Returns:

true or false
equals
(Object
object
other
)

Overrides java.lang.Object.equals.

checks if given object is equal to this field.

public int

Returns:

a^k
exp
(int
a field element a
a
,
int
k degree
k
)

compute exponentiation a^k

public int

Returns:

degree of the field
getDegree
()

return degree of the field

public byte[]

Returns:

the field in byte array form
getEncoded
()

return the encoded form of this field

public int

Returns:

the field polynomial
getPolynomial
()

return the field polynomial

public int

Returns:

a random element
getRandomElement
(SecureRandom
SecureRandom
sr
)

create a random field element using PRNG sr

public int

Returns:

a random element
getRandomNonZeroElement
()

create a random non-zero field element

public int

Returns:

a random non-zero element
getRandomNonZeroElement
(SecureRandom
SecureRandom
sr
)

create a random non-zero field element using PRNG sr

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public int

Returns:

a-1
inverse
(int
a field element a
a
)

compute the multiplicative inverse of a

public boolean

Returns:

true if e is encoded element of this field and false otherwise
isElementOfThisField
(int e)

public int

Returns:

a*b
mult
(int a, int b)

Return product of two elements

private static String
polyToString(int p)

public int

Returns:

a1/2
sqRoot
(int
a field element a
a
)

compute the square root of an integer

public String

Returns:

a human readable form of this field.
toString
()

Overrides java.lang.Object.toString.

Returns a human readable form of this field.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

degreeback to summary
private int degree
polynomialback to summary
private int polynomial

Constructor Detail

GF2mFieldback to summary
public GF2mField(int degree)

create a finite field GF(2^m)

Parameters
degree:int

the degree of the field

GF2mFieldback to summary
public GF2mField(int degree, int poly)

create a finite field GF(2^m) with the fixed field polynomial

Parameters
degree:int

the degree of the field

poly:int

the field polynomial

GF2mFieldback to summary
public GF2mField(byte[] enc)
GF2mFieldback to summary
public GF2mField(GF2mField field)

Method Detail

addback to summary
public int add(int a, int b)

Return sum of two elements

Returns:int

a+b

elementToStrback to summary
public String elementToStr(int a)
equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

checks if given object is equal to this field.

The method returns false whenever the given object is not GF2m.

Parameters
other:Object

object

Returns:boolean

true or false

expback to summary
public int exp(int a, int k)

compute exponentiation a^k

Parameters
a:int

a field element a

k:int

k degree

Returns:int

a^k

getDegreeback to summary
public int getDegree()

return degree of the field

Returns:int

degree of the field

getEncodedback to summary
public byte[] getEncoded()

return the encoded form of this field

Returns:byte[]

the field in byte array form

getPolynomialback to summary
public int getPolynomial()

return the field polynomial

Returns:int

the field polynomial

getRandomElementback to summary
public int getRandomElement(SecureRandom sr)

create a random field element using PRNG sr

Parameters
sr:SecureRandom

SecureRandom

Returns:int

a random element

getRandomNonZeroElementback to summary
public int getRandomNonZeroElement()

create a random non-zero field element

Returns:int

a random element

getRandomNonZeroElementback to summary
public int getRandomNonZeroElement(SecureRandom sr)

create a random non-zero field element using PRNG sr

Parameters
sr:SecureRandom

SecureRandom

Returns:int

a random non-zero element

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

inverseback to summary
public int inverse(int a)

compute the multiplicative inverse of a

Parameters
a:int

a field element a

Returns:int

a-1

isElementOfThisFieldback to summary
public boolean isElementOfThisField(int e)
Returns:boolean

true if e is encoded element of this field and false otherwise

multback to summary
public int mult(int a, int b)

Return product of two elements

Returns:int

a*b

polyToStringback to summary
private static String polyToString(int p)
sqRootback to summary
public int sqRoot(int a)

compute the square root of an integer

Parameters
a:int

a field element a

Returns:int

a1/2

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a human readable form of this field.

Returns:String

a human readable form of this field.