HFE
Class Field2_n

java.lang.Object
  |
  +--HFE.Field2_n

final class Field2_n
extends java.lang.Object

This class encapsulates the operations for a finite field with 2^n elements.
The generating polynomials are

Version:
0.1

Field Summary
static int degree
          Degree of the underlying irreducible polynomial.
(package private) static Field2_n div_A
          static registers for division
(package private) static Field2_n div_B
          static registers for division
(package private) static Field2_n div_tmp
          static register for division
(package private) static Field2_n div_V
          static registers for division
private static Field2_n mul_tmp
          static register for multiplication
private  int[] number
          Allocats memory for elements of this class
static int reductionTerm
          Stores the reduction term as bit vector.
static int size
          determinates the size of elements of this class.
 
Constructor Summary
(package private) Field2_n()
          Standart Constructor to obtain an element with all bits = 0
(package private) Field2_n(Field2_n father)
          Constructor to produce a copy of another Field2_n element
(package private) Field2_n(int init)
          Constructor to obtain an element with least significant integer set and the rest being 0
(package private) Field2_n(java.util.Random rnd)
          Constructor to obtain a random element
 
Method Summary
 void add(Field2_n ter)
          this += ter Adds two numbers using the xor function for intergers.
 void add(Field2_n ter1, Field2_n ter2)
          this = ter1 + ter2 Adds two numbers using the xor function for intergers.
private  void addModul()
          this += generating polynomial Adds the modul to this.
 void addOne()
          this += 1 - adds one to this
private  boolean checkBit(int where)
          Checks if the bit at position where is set.
private  void clearBit(int where)
          Clears bit at position where.
private  int cntDegree()
          find the degree of this - i.e.
 void copy(Field2_n father)
          this = ter - copies father integerwise into this
 void div(Field2_n fac)
          this /= fac - divides this by fac usind finite field arithmetic in GF(2^n) and stores the result in this.
 void div(Field2_n whom, Field2_n by)
          this = whom / by in GF(2^n) - divides two numbers using finite field arithmetic in GF(2^n).
 boolean even()
          Checks if bit[0] is _not_ set, i.e.
 void getElement(int[] bitVec)
          copies this to a bit vector
private  boolean isElement()
          Checks if the current element is from Field2_n
static boolean isElement(Field2_n elem)
          Checks if a given integer is within the range of a GF(2^n) element.
static boolean isElement(Field2_n[] elems)
          Checks if a given vector consists only of Field2_n elements.
static boolean isElement(Field2_n[][] elems)
          Checks if a given matrix consists only of Field2_n elements.
 boolean isEqual(Field2_n who)
          Checks if this and who are bitwise equal
 boolean isZero()
          Checks if the element is the zero element
static void main(java.lang.String[] args)
          Tests everything in this class
 void mul(Field2_n fac)
          this *= fac - multiplies two numbers using finite field arithmetic in GF(2^n) and stores the result in this.
 void mul(Field2_n fac1, Field2_n fac2)
          this = fac1 * fac2 - multiplies two numbers using finite field arithmetic in GF(2^n) and stores the result in this.
 void mulX()
          this *= x assumes that there is no reduction necessary
 void rnd(java.util.Random rnd)
          sets this to a random element from Field2_2.
static int rndBit(java.util.Random rnd)
          returns a random position within current Field2_n
private  void setBit(int where)
          Sets bit at position where.
 void setElement(int[] bitVec)
          sets field element regarding to a bit vector.
 void setOne()
          sets this to 1
 void setZero()
          sets this to zero
private  void shiftL()
          this <<= 1 - therefore computes a left shift of this by one bit.
private  void shiftLMod()
          this <<= 1 % i(t) - therefore computes a left shift of this by one bit and reduces the result by the generating polynomials i(t).
private  void shiftR()
          this >>= 1 - therefore computes a right shift of this by one bit.
 java.lang.String stringIt()
          converts this to a string
 void sub(Field2_n ter)
          this -= ter Adds two numbers using the xor function for intergers.
 void sub(Field2_n ter1, Field2_n ter2)
          this = ter1 - ter2 Subtracts two numbers using the xor function for intergers.
static void testIt()
          Tests the functionality of the whole class.
private  void xorBit(int where)
          xors the bit at position where.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

degree

public static final int degree
Degree of the underlying irreducible polynomial. Value comes from class HFE2_n

size

public static final int size
determinates the size of elements of this class. The assumption is that one integer has 32 bits.

reductionTerm

public static final int reductionTerm
Stores the reduction term as bit vector. The assumption is that - apart from x^degree - the other factors have degree less than 32

number

private int[] number
Allocats memory for elements of this class

mul_tmp

private static Field2_n mul_tmp
static register for multiplication

div_A

static Field2_n div_A
static registers for division

div_B

static Field2_n div_B
static registers for division

div_V

static Field2_n div_V
static registers for division

div_tmp

static Field2_n div_tmp
static register for division
Constructor Detail

Field2_n

Field2_n()
Standart Constructor to obtain an element with all bits = 0

Field2_n

Field2_n(Field2_n father)
Constructor to produce a copy of another Field2_n element

Field2_n

Field2_n(int init)
Constructor to obtain an element with least significant integer set and the rest being 0

Field2_n

Field2_n(java.util.Random rnd)
Constructor to obtain a random element
Method Detail

even

public boolean even()
Checks if bit[0] is _not_ set, i.e. if the number is even
Returns:
true iff bit[0] is 0

isZero

public boolean isZero()
Checks if the element is the zero element
Returns:
true iff the element is zero

checkBit

private boolean checkBit(int where)
Checks if the bit at position where is set.
Parameters:
where - position in this which should be checked
Returns:
true iff bit is 1

setBit

private void setBit(int where)
Sets bit at position where.
Parameters:
where - position in this which should be set

clearBit

private void clearBit(int where)
Clears bit at position where.
Parameters:
where - position in this which should be cleared

xorBit

private void xorBit(int where)
xors the bit at position where.
Parameters:
where - position in this which should be xored

copy

public final void copy(Field2_n father)
this = ter - copies father integerwise into this
Parameters:
father - element of Field2_n

shiftL

private void shiftL()
this <<= 1 - therefore computes a left shift of this by one bit. Does not assume that the highest significant integer is valid (i.e. only the bits less the degree of the generating polynomial can seen to be valid).

shiftLMod

private void shiftLMod()
this <<= 1 % i(t) - therefore computes a left shift of this by one bit and reduces the result by the generating polynomials i(t). This left-shift is equivalent to multiplication with t. Assumes that this is valid before and after this computation.

shiftR

private void shiftR()
this >>= 1 - therefore computes a right shift of this by one bit. Assumes that bit[0] is 0, i.e. this is even. For the implementation platform (x86, Linux, Java 1.3) it turned out that >>= 1 keeps the sign bit untouched. The workaround it to delete the sign flag manually (required a second step...)

isElement

private boolean isElement()
Checks if the current element is from Field2_n
Returns:
true iff this is a valid element from Field2_n

isElement

public static boolean isElement(Field2_n elem)
Checks if a given integer is within the range of a GF(2^n) element.
Returns:
is elem in the range of an Field2_n element

isElement

public static boolean isElement(Field2_n[] elems)
Checks if a given vector consists only of Field2_n elements.
Returns:
true iff all elements of the vector are Field2_n elements.

isElement

public static boolean isElement(Field2_n[][] elems)
Checks if a given matrix consists only of Field2_n elements.
Returns:
true iff all elements of the matrix are Field2_n elements.

isEqual

public boolean isEqual(Field2_n who)
Checks if this and who are bitwise equal
Returns:
true iff this == who

setZero

public void setZero()
sets this to zero

setOne

public void setOne()
sets this to 1

addOne

public void addOne()
this += 1 - adds one to this

setElement

public void setElement(int[] bitVec)
sets field element regarding to a bit vector. this is overwritten.
Parameters:
bitVec - elements from GF(2) for field elements

getElement

public void getElement(int[] bitVec)
copies this to a bit vector
Parameters:
bitVec - element in form of bit vector

cntDegree

private int cntDegree()
find the degree of this - i.e. the position of the highest bit which is not zero. If all bits are zero, this function returns -1
Returns:
position of the first bit which is not zero. Range: -1, .., degree-1

add

public final void add(Field2_n ter1,
                      Field2_n ter2)
this = ter1 + ter2 Adds two numbers using the xor function for intergers. Note: This works for any extionsion field over p=2. The result is stored in this.
Parameters:
ter1 - element of Field2_n
ter2 - element of Field2_n

add

public final void add(Field2_n ter)
this += ter Adds two numbers using the xor function for intergers. Note: This works for any extionsion field over p=2. The result is stored in this.
Parameters:
ter - element of Field2_n

addModul

private final void addModul()
this += generating polynomial Adds the modul to this. Exploits the fact that generating polynomial only changes two integers in our representation. Assumes that this is a valid element of GF(2^n)

sub

public final void sub(Field2_n ter1,
                      Field2_n ter2)
this = ter1 - ter2 Subtracts two numbers using the xor function for intergers. Note: This works for any extionsion field over p=2. The result is stored in this. Please note that add = sub for p=2.
Parameters:
ter1 - element of Field2_n
ter2 - element of Field2_n

sub

public final void sub(Field2_n ter)
this -= ter Adds two numbers using the xor function for intergers. Note: This works for any extionsion field over p=2. The result is stored in this. Please note that add = sub for p=2.
Parameters:
ter - element of Field2_n

mul

public final void mul(Field2_n fac1,
                      Field2_n fac2)
this = fac1 * fac2 - multiplies two numbers using finite field arithmetic in GF(2^n) and stores the result in this.
Parameters:
fac1 - element of GF(2^n)
fac2 - element of GF(2^n)

mulX

public final void mulX()
this *= x assumes that there is no reduction necessary

mul

public final void mul(Field2_n fac)
this *= fac - multiplies two numbers using finite field arithmetic in GF(2^n) and stores the result in this. Uses a static variable to store the result of multiplication
Parameters:
fac - element of GF(2^n)

div

public final void div(Field2_n whom,
                      Field2_n by)
this = whom / by in GF(2^n) - divides two numbers using finite field arithmetic in GF(2^n). Implements "Gread Divide" from Sheueling Chang Shantz. The result (register U) is stored in this. Makes use of three static registers, namely div_A, div_B, div_V.
Parameters:
whom - which number should be divised
by - which number divides

div

public final void div(Field2_n fac)
this /= fac - divides this by fac usind finite field arithmetic in GF(2^n) and stores the result in this. Uses a static variable to store the result of multiplication
Parameters:
fac - element of GF(2^n)

rnd

public final void rnd(java.util.Random rnd)
sets this to a random element from Field2_2.

rndBit

public static final int rndBit(java.util.Random rnd)
returns a random position within current Field2_n

stringIt

public java.lang.String stringIt()
converts this to a string

testIt

public static final void testIt()
Tests the functionality of the whole class. If there occurs any error it will be printed on stdout.

main

public static void main(java.lang.String[] args)
Tests everything in this class
See Also:
testIt()