Class GF2mField
- java.lang.Object
-
- org.bouncycastle.pqc.math.linearalgebra.GF2mField
-
public class GF2mField extends java.lang.ObjectThis 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
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intadd(int a, int b)Return sum of two elementsjava.lang.StringelementToStr(int a)booleanequals(java.lang.Object other)checks if given object is equal to this field.intexp(int a, int k)compute exponentiation a^kintgetDegree()return degree of the fieldbyte[]getEncoded()return the encoded form of this fieldintgetPolynomial()return the field polynomialintgetRandomElement(java.security.SecureRandom sr)create a random field element using PRNG srintgetRandomNonZeroElement()create a random non-zero field elementintgetRandomNonZeroElement(java.security.SecureRandom sr)create a random non-zero field element using PRNG srinthashCode()intinverse(int a)compute the multiplicative inverse of abooleanisElementOfThisField(int e)intmult(int a, int b)Return product of two elementsintsqRoot(int a)compute the square root of an integerjava.lang.StringtoString()Returns a human readable form of this field.
-
-
-
Constructor Detail
-
GF2mField
public GF2mField(int degree)
create a finite field GF(2^m)- Parameters:
degree- the degree of the field
-
GF2mField
public GF2mField(int degree, int poly)create a finite field GF(2^m) with the fixed field polynomial- Parameters:
degree- the degree of the fieldpoly- the field polynomial
-
GF2mField
public GF2mField(byte[] enc)
-
GF2mField
public GF2mField(GF2mField field)
-
-
Method Detail
-
getDegree
public int getDegree()
return degree of the field- Returns:
- degree of the field
-
getPolynomial
public int getPolynomial()
return the field polynomial- Returns:
- the field polynomial
-
getEncoded
public byte[] getEncoded()
return the encoded form of this field- Returns:
- the field in byte array form
-
add
public int add(int a, int b)Return sum of two elements- Parameters:
a-b-- Returns:
- a+b
-
mult
public int mult(int a, int b)Return product of two elements- Parameters:
a-b-- Returns:
- a*b
-
exp
public int exp(int a, int k)compute exponentiation a^k- Parameters:
a- a field element ak- k degree- Returns:
- a^k
-
inverse
public int inverse(int a)
compute the multiplicative inverse of a- Parameters:
a- a field element a- Returns:
- a-1
-
sqRoot
public int sqRoot(int a)
compute the square root of an integer- Parameters:
a- a field element a- Returns:
- a1/2
-
getRandomElement
public int getRandomElement(java.security.SecureRandom sr)
create a random field element using PRNG sr- Parameters:
sr- SecureRandom- Returns:
- a random element
-
getRandomNonZeroElement
public int getRandomNonZeroElement()
create a random non-zero field element- Returns:
- a random element
-
getRandomNonZeroElement
public int getRandomNonZeroElement(java.security.SecureRandom sr)
create a random non-zero field element using PRNG sr- Parameters:
sr- SecureRandom- Returns:
- a random non-zero element
-
isElementOfThisField
public boolean isElementOfThisField(int e)
- Returns:
- true if e is encoded element of this field and false otherwise
-
elementToStr
public java.lang.String elementToStr(int a)
-
equals
public boolean equals(java.lang.Object other)
checks if given object is equal to this field.The method returns false whenever the given object is not GF2m.
- Overrides:
equalsin classjava.lang.Object- Parameters:
other- object- Returns:
- true or false
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
Returns a human readable form of this field.- Overrides:
toStringin classjava.lang.Object- Returns:
- a human readable form of this field.
-
-