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

public Class GF2Polynomial

extends Object
Class Inheritance
Imports
java.math.BigInteger, java.util.Random, org.bouncycastle.util.Arrays

This class stores very long strings of bits and does some basic arithmetics. It is used by GF2nField, GF2nPolynomialField and GFnPolynomialElement.
See Also
GF2nPolynomialElement, GF2nField

Field Summary

Modifier and TypeField and Description
private static final int[]
private int
private int
private static final boolean[]
private static Random
private static final int[]
private static final short[]
private int[]

Constructor Summary

AccessConstructor and Description
public
GF2Polynomial(int
the desired number of bits to store
length
)

Creates a new GF2Polynomial of the given length and value zero.

public
GF2Polynomial(int
the desired number of bits to store
length
,
Random
SecureRandom to use for randomization
rand
)

Creates a new GF2Polynomial of the given length and random value.

public
GF2Polynomial(int
the desired number of bits to store
length
,
String
the value described by a String
value
)

Creates a new GF2Polynomial of the given length and value selected by value:

  • ZERO
  • ONE
  • RANDOM
  • X
  • ALL
public
GF2Polynomial(int
the desired number of bits to store
length
,
int[]
contains the desired value, LSB in bs[0]
bs
)

Creates a new GF2Polynomial of the given length using the given int[].

public
GF2Polynomial(int
the intended length of this polynomial
length
,
byte[]
the octet string to assign to this polynomial
os
)

Creates a new GF2Polynomial by converting the given byte[] os according to 1363 and using the given length.

public
GF2Polynomial(int
the intended length of this polynomial
length
,
BigInteger
the FlexiBigInt to assign to this polynomial
bi
)

Creates a new GF2Polynomial by converting the given FlexiBigInt bi according to 1363 and using the given length.

public
GF2Polynomial(GF2Polynomial
the GF2Polynomial to clone
b
)

Creates a new GF2Polynomial by cloneing the given GF2Polynomial b.

Method Summary

Modifier and TypeMethod and Description
public GF2Polynomial

Returns:

a new GF2Polynomial (this + b)
add
(GF2Polynomial
a GF2Polynomial
b
)

Adds two GF2Polynomials, this and b, and returns the result.

public void
addToThis(GF2Polynomial
GF2Polynomial to add to this GF2Polynomial
b
)

Adds b to this GF2Polynomial and assigns the result to this GF2Polynomial.

public void
assignAll()

Sets all Bits to 1.

public void
assignOne()

Sets the LSB to 1 and all other to 0, assigning 'one' to this GF2Polynomial.

public void
assignX()

Sets Bit 1 to 1 and all other to 0, assigning 'x' to this GF2Polynomial.

public void
assignZero()

Resets all bits to zero.

public Object

Returns:

a copy of this GF2Polynomial
clone
()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.
public GF2Polynomial[]

Returns:

a new GF2Polynomial[2] containing quotient and remainder
divide
(GF2Polynomial
GF2Polynomial != 0
g
)

Divides this by g and returns the quotient and remainder in a new GF2Polynomial[2], quotient in [0], remainder in [1].

private void
doShiftBlocksLeft(int
shift amount (in blocks)
b
)

Shifts left this GF2Polynomial's value blockwise b blocks resulting in a shift-left by b*32.

public boolean

Returns:

true if this GF2Polynomial equals b (this == b)
equals
(Object
the other GF2Polynomial
other
)

Overrides java.lang.Object.equals.

Returns true if two GF2Polynomials have the same size and value and thus are equal.
public void
expandN(int
the intended length
i
)

Expands len and int[] value to i.

public GF2Polynomial

Returns:

a new GF2Polynomial gcd(this,g)
gcd
(GF2Polynomial
GF2Polynomial != 0
g
)

Returns the greatest common divisor of this and g in a new GF2Polynomial.

public int

Returns:

the bit at position i if i is a valid position, 0 otherwise.
getBit
(int
int
i
)

Returns the bit at position i.

public int

Returns:

the length of this GF2Polynomial
getLength
()

Returns the length of this GF2Polynomial.

public int

Returns:

the hash code of this polynomial
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public GF2Polynomial

Returns:

this + 1
increase
()

Toggles the LSB of this GF2Polynomial, increasing the value by 'one' and returns the result in a new GF2Polynomial.

public void
increaseThis()

Toggles the LSB of this GF2Polynomial, increasing its value by 'one'.

public boolean

Returns:

true if this is irreducible
isIrreducible
()

Checks if this is irreducible, according to IEEE P1363, A.5.5, p103.

public boolean

Returns:

true if this GF2Polynomial equals 'one' (this == 1)
isOne
()

Tests if all bits are reset to 0 and LSB is set to 1.

public boolean

Returns:

true if this GF2Polynomial equals 'zero' (this == 0)
isZero
()

Tests if all bits equal zero.

private GF2Polynomial
karaMult(GF2Polynomial b)

Does the recursion for Karatzuba multiplication.

private GF2Polynomial

Returns:

a new GF2Polynomial containing the lower k bytes of this GF2Polynomial
lower
(int k)

Returns a new GF2Polynomial containing the lower k bytes of this GF2Polynomial.

private static int[]
mult128(int[] a, int[] b)

4-Integer Version of Karatzuba multiplication.

private static int[]
mult256(int[] a, int[] b)

8-Integer Version of Karatzuba multiplication.

private static int[]
mult32(int a, int b)

4-Byte Version of Karatzuba multiplication.

private static int[]
mult512(int[] a, int[] b)

16-Integer Version of Karatzuba multiplication.

private static int[]
mult64(int[] a, int[] b)

2-Integer Version of Karatzuba multiplication.

public GF2Polynomial

Returns:

a new GF2Polynomial (this * b)
multiply
(GF2Polynomial
a GF2Polynomial
b
)

Multiplies this GF2Polynomial with b and returns the result in a new GF2Polynomial.

public GF2Polynomial

Returns:

a new GF2Polynomial (this * b)
multiplyClassic
(GF2Polynomial
a GF2Polynomial
b
)

Multiplies this GF2Polynomial with b and returns the result in a new GF2Polynomial.

public GF2Polynomial

Returns:

a new GF2Polynomial |_ this / g _|
quotient
(GF2Polynomial
GF2Polynomial != 0
g
)

Returns the absolute quotient of this divided by g in a new GF2Polynomial.

public void
randomize()

Fills all len bits of this GF2Polynomial with random values.

public void
randomize(Random
the source of randomness
rand
)

Fills all len bits of this GF2Polynomial with random values using the specified source of randomness.

public void
reduceN()

Reduces len by finding the most significant bit set to one and reducing len and blocks.

pack-priv void
reducePentanomial(int
the degree of the used field
m
,
int[]
degrees of the middle x's in the pentanomial
pc
)

Reduces this GF2Polynomial using the pentanomial x^m + x^pc[2] + x^pc[1] + x^pc[0] + 1.

pack-priv void
reduceTrinomial(int
the degree of the used field
m
,
int
degree of the middle x in the trinomial
tc
)

Reduces this GF2Polynomial using the trinomial x^m + x^tc + 1.

public GF2Polynomial

Returns:

a new GF2Polynomial (this % g)
remainder
(GF2Polynomial
GF2Polynomial != 0
g
)

Returns the remainder of this divided by g in a new GF2Polynomial.

public void
resetBit(int
int
i
)

Resets the bit at position i.

public void
setBit(int
int
i
)

Sets the bit at position i.

pack-priv void
shiftBlocksLeft()

Shifts-left this GF2Polynomial's value blockwise 1 block resulting in a shift-left by 32.

public GF2Polynomial

Returns:

a new GF2Polynomial (this << 1)
shiftLeft
()

Returns this GF2Polynomial shift-left by 1 in a new GF2Polynomial.

public GF2Polynomial

Returns:

a new GF2Polynomial (this << k)
shiftLeft
(int
int
k
)

Returns this GF2Polynomial shift-left by k in a new GF2Polynomial.

public void
shiftLeftAddThis(GF2Polynomial
GF2Polynomial to shift and add to this
b
,
int
the amount to shift
k
)

Shifts left b and adds the result to Its a fast version of this = add(b.shl(k));

public void
shiftLeftThis()

Shifts-left this by one and enlarges the size of value if necesary.

public GF2Polynomial

Returns:

a new GF2Polynomial (this << 1)
shiftRight
()

Returns this GF2Polynomial shift-right by 1 in a new GF2Polynomial.

public void
shiftRightThis()

Shifts-right this GF2Polynomial by 1.

public void
squareThisBitwise()

Squares this GF2Polynomial and expands it accordingly.

public void
squareThisPreCalc()

Squares this GF2Polynomial by using precomputed values of squaringTable.

public GF2Polynomial

Returns:

a new GF2Polynomial (this - b)
subtract
(GF2Polynomial
a GF2Polynomial
b
)

Subtracts two GF2Polynomials, this and b, and returns the result in a new GF2Polynomial.

public void
subtractFromThis(GF2Polynomial
a GF2Polynomial
b
)

Subtracts b from this GF2Polynomial and assigns the result to this GF2Polynomial.

public boolean

Returns:

true if the bit at position i is set (a(i) == 1). False if (i < 0) || (i > (len - 1))
testBit
(int
the position of the bit to be tested
i
)

Tests the bit at position i.

public byte[]

Returns:

a byte[] representing the value of this polynomial
toByteArray
()

Converts this polynomial to a byte[] (octet string) according to 1363.

public BigInteger

Returns:

a FlexiBigInt representing the value of this polynomial
toFlexiBigInt
()

Converts this polynomial to an integer according to 1363.

public int[]

Returns:

the value of this GF2Polynomial in a new int[], LSB in int[0]
toIntegerArray
()

Returns the value of this GF2Polynomial in an int[].

public String

Returns:

a String representing this GF2Polynomials value.
toString
(int
the radix to use (2 or 16, otherwise 2 is used)
radix
)

Returns a string representing this GF2Polynomials value using hexadecimal or binary radix in MSB-first order.

private GF2Polynomial

Returns:

a new GF2Polynomial containing the upper k bytes of this GF2Polynomial
upper
(int k)

Returns a new GF2Polynomial containing the upper k bytes of this GF2Polynomial.

public boolean

Returns:

this x b as boolean (1->true, 0->false)
vectorMult
(GF2Polynomial
GF2Polynomial
b
)

Does a vector-multiplication modulo 2 and returns the result as boolean.

public GF2Polynomial

Returns:

a new GF2Polynomial (this ^ b)
xor
(GF2Polynomial
GF2Polynomial
b
)

Returns the bitwise exclusive-or of this and b in a new GF2Polynomial.

public void
xorBit(int
int
i
)

Xors the bit at position i.

public void
xorThisBy(GF2Polynomial
GF2Polynomial
b
)

Computes the bitwise exclusive-or of this GF2Polynomial and b and stores the result in this GF2Polynomial.

private void
zeroUnusedBits()

If len is not a multiple of the block size (32), some extra bits of the last block might have been modified during a blockwise operation.

Inherited from java.lang.Object:
finalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

bitMaskback to summary
private static final int[] bitMask
blocksback to summary
private int blocks
lenback to summary
private int len
parityback to summary
private static final boolean[] parity
randback to summary
private static Random rand
reverseRightMaskback to summary
private static final int[] reverseRightMask
squaringTableback to summary
private static final short[] squaringTable
valueback to summary
private int[] value

Constructor Detail

GF2Polynomialback to summary
public GF2Polynomial(int length)

Creates a new GF2Polynomial of the given length and value zero.

Parameters
length:int

the desired number of bits to store

GF2Polynomialback to summary
public GF2Polynomial(int length, Random rand)

Creates a new GF2Polynomial of the given length and random value.

Parameters
length:int

the desired number of bits to store

rand:Random

SecureRandom to use for randomization

GF2Polynomialback to summary
public GF2Polynomial(int length, String value)

Creates a new GF2Polynomial of the given length and value selected by value:

  • ZERO
  • ONE
  • RANDOM
  • X
  • ALL
Parameters
length:int

the desired number of bits to store

value:String

the value described by a String

GF2Polynomialback to summary
public GF2Polynomial(int length, int[] bs)

Creates a new GF2Polynomial of the given length using the given int[]. LSB is contained in bs[0].

Parameters
length:int

the desired number of bits to store

bs:int[]

contains the desired value, LSB in bs[0]

GF2Polynomialback to summary
public GF2Polynomial(int length, byte[] os)

Creates a new GF2Polynomial by converting the given byte[] os according to 1363 and using the given length.

Parameters
length:int

the intended length of this polynomial

os:byte[]

the octet string to assign to this polynomial

See Also
P1363 5.5.2 p22f, OS2BSP
GF2Polynomialback to summary
public GF2Polynomial(int length, BigInteger bi)

Creates a new GF2Polynomial by converting the given FlexiBigInt bi according to 1363 and using the given length.

Parameters
length:int

the intended length of this polynomial

bi:BigInteger

the FlexiBigInt to assign to this polynomial

See Also
P1363 5.5.1 p22, I2BSP
GF2Polynomialback to summary
public GF2Polynomial(GF2Polynomial b)

Creates a new GF2Polynomial by cloneing the given GF2Polynomial b.

Parameters
b:GF2Polynomial

the GF2Polynomial to clone

Method Detail

addback to summary
public GF2Polynomial add(GF2Polynomial b)

Adds two GF2Polynomials, this and b, and returns the result. this and b can be of different size.

Parameters
b:GF2Polynomial

a GF2Polynomial

Returns:GF2Polynomial

a new GF2Polynomial (this + b)

addToThisback to summary
public void addToThis(GF2Polynomial b)

Adds b to this GF2Polynomial and assigns the result to this GF2Polynomial. b can be of different size.

Parameters
b:GF2Polynomial

GF2Polynomial to add to this GF2Polynomial

assignAllback to summary
public void assignAll()

Sets all Bits to 1.

assignOneback to summary
public void assignOne()

Sets the LSB to 1 and all other to 0, assigning 'one' to this GF2Polynomial.

assignXback to summary
public void assignX()

Sets Bit 1 to 1 and all other to 0, assigning 'x' to this GF2Polynomial.

assignZeroback to summary
public void assignZero()

Resets all bits to zero.

cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

Returns:Object

a copy of this GF2Polynomial

divideback to summary
public GF2Polynomial[] divide(GF2Polynomial g) throws RuntimeException

Divides this by g and returns the quotient and remainder in a new GF2Polynomial[2], quotient in [0], remainder in [1].

Parameters
g:GF2Polynomial

GF2Polynomial != 0

Returns:GF2Polynomial[]

a new GF2Polynomial[2] containing quotient and remainder

doShiftBlocksLeftback to summary
private void doShiftBlocksLeft(int b)

Shifts left this GF2Polynomial's value blockwise b blocks resulting in a shift-left by b*32. This method assumes that len and blocks have already been updated to reflect the final state.

Parameters
b:int

shift amount (in blocks)

equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Returns true if two GF2Polynomials have the same size and value and thus are equal.

Parameters
other:Object

the other GF2Polynomial

Returns:boolean

true if this GF2Polynomial equals b (this == b)

expandNback to summary
public void expandN(int i)

Expands len and int[] value to i. This is useful before adding two GF2Polynomials of different size.

Parameters
i:int

the intended length

gcdback to summary
public GF2Polynomial gcd(GF2Polynomial g) throws RuntimeException

Returns the greatest common divisor of this and g in a new GF2Polynomial.

Parameters
g:GF2Polynomial

GF2Polynomial != 0

Returns:GF2Polynomial

a new GF2Polynomial gcd(this,g)

Exceptions
ArithmeticException:
if this and g both are equal to zero
getBitback to summary
public int getBit(int i)

Returns the bit at position i.

Parameters
i:int

int

Returns:int

the bit at position i if i is a valid position, 0 otherwise.

getLengthback to summary
public int getLength()

Returns the length of this GF2Polynomial. The length can be greater than the degree. To get the degree call reduceN() before calling getLength().

Returns:int

the length of this GF2Polynomial

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the 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

the hash code of this polynomial

increaseback to summary
public GF2Polynomial increase()

Toggles the LSB of this GF2Polynomial, increasing the value by 'one' and returns the result in a new GF2Polynomial.

Returns:GF2Polynomial

this + 1

increaseThisback to summary
public void increaseThis()

Toggles the LSB of this GF2Polynomial, increasing its value by 'one'.

isIrreducibleback to summary
public boolean isIrreducible()

Checks if this is irreducible, according to IEEE P1363, A.5.5, p103.

Note

The algorithm from IEEE P1363, A5.5 can be used to check a polynomial with coefficients in GF(2^r) for irreducibility. As this class only represents polynomials with coefficients in GF(2), the algorithm is adapted to the case r=1.

Returns:boolean

true if this is irreducible

See Also
P1363, A.5.5, p103
isOneback to summary
public boolean isOne()

Tests if all bits are reset to 0 and LSB is set to 1.

Returns:boolean

true if this GF2Polynomial equals 'one' (this == 1)

isZeroback to summary
public boolean isZero()

Tests if all bits equal zero.

Returns:boolean

true if this GF2Polynomial equals 'zero' (this == 0)

karaMultback to summary
private GF2Polynomial karaMult(GF2Polynomial b)

Does the recursion for Karatzuba multiplication.

lowerback to summary
private GF2Polynomial lower(int k)

Returns a new GF2Polynomial containing the lower k bytes of this GF2Polynomial.

Returns:GF2Polynomial

a new GF2Polynomial containing the lower k bytes of this GF2Polynomial

See Also
GF2Polynomial#karaMult
mult128back to summary
private static int[] mult128(int[] a, int[] b)

4-Integer Version of Karatzuba multiplication.

mult256back to summary
private static int[] mult256(int[] a, int[] b)

8-Integer Version of Karatzuba multiplication.

mult32back to summary
private static int[] mult32(int a, int b)

4-Byte Version of Karatzuba multiplication. Here the actual work is done.

mult512back to summary
private static int[] mult512(int[] a, int[] b)

16-Integer Version of Karatzuba multiplication.

mult64back to summary
private static int[] mult64(int[] a, int[] b)

2-Integer Version of Karatzuba multiplication.

multiplyback to summary
public GF2Polynomial multiply(GF2Polynomial b)

Multiplies this GF2Polynomial with b and returns the result in a new GF2Polynomial. This method does not reduce the result in GF(2^N). This method uses Karatzuba multiplication.

Parameters
b:GF2Polynomial

a GF2Polynomial

Returns:GF2Polynomial

a new GF2Polynomial (this * b)

multiplyClassicback to summary
public GF2Polynomial multiplyClassic(GF2Polynomial b)

Multiplies this GF2Polynomial with b and returns the result in a new GF2Polynomial. This method does not reduce the result in GF(2^N). This method uses classic multiplication (schoolbook).

Parameters
b:GF2Polynomial

a GF2Polynomial

Returns:GF2Polynomial

a new GF2Polynomial (this * b)

quotientback to summary
public GF2Polynomial quotient(GF2Polynomial g) throws RuntimeException

Returns the absolute quotient of this divided by g in a new GF2Polynomial.

Parameters
g:GF2Polynomial

GF2Polynomial != 0

Returns:GF2Polynomial

a new GF2Polynomial |_ this / g _|

randomizeback to summary
public void randomize()

Fills all len bits of this GF2Polynomial with random values.

randomizeback to summary
public void randomize(Random rand)

Fills all len bits of this GF2Polynomial with random values using the specified source of randomness.

Parameters
rand:Random

the source of randomness

reduceNback to summary
public void reduceN()

Reduces len by finding the most significant bit set to one and reducing len and blocks.

reducePentanomialback to summary
pack-priv void reducePentanomial(int m, int[] pc)

Reduces this GF2Polynomial using the pentanomial x^m + x^pc[2] + x^pc[1] + x^pc[0] + 1.

Parameters
m:int

the degree of the used field

pc:int[]

degrees of the middle x's in the pentanomial

reduceTrinomialback to summary
pack-priv void reduceTrinomial(int m, int tc)

Reduces this GF2Polynomial using the trinomial x^m + x^tc + 1.

Parameters
m:int

the degree of the used field

tc:int

degree of the middle x in the trinomial

remainderback to summary
public GF2Polynomial remainder(GF2Polynomial g) throws RuntimeException

Returns the remainder of this divided by g in a new GF2Polynomial.

Parameters
g:GF2Polynomial

GF2Polynomial != 0

Returns:GF2Polynomial

a new GF2Polynomial (this % g)

resetBitback to summary
public void resetBit(int i) throws RuntimeException

Resets the bit at position i.

Parameters
i:int

int

Exceptions
RuntimeException:
if (i < 0) || (i > (len - 1))
setBitback to summary
public void setBit(int i) throws RuntimeException

Sets the bit at position i.

Parameters
i:int

int

Exceptions
RuntimeException:
if (i < 0) || (i > (len - 1))
shiftBlocksLeftback to summary
pack-priv void shiftBlocksLeft()

Shifts-left this GF2Polynomial's value blockwise 1 block resulting in a shift-left by 32.

See Also
GF2Polynomial#multiply
shiftLeftback to summary
public GF2Polynomial shiftLeft()

Returns this GF2Polynomial shift-left by 1 in a new GF2Polynomial.

Returns:GF2Polynomial

a new GF2Polynomial (this << 1)

shiftLeftback to summary
public GF2Polynomial shiftLeft(int k)

Returns this GF2Polynomial shift-left by k in a new GF2Polynomial.

Parameters
k:int

int

Returns:GF2Polynomial

a new GF2Polynomial (this << k)

shiftLeftAddThisback to summary
public void shiftLeftAddThis(GF2Polynomial b, int k)

Shifts left b and adds the result to Its a fast version of this = add(b.shl(k));

Parameters
b:GF2Polynomial

GF2Polynomial to shift and add to this

k:int

the amount to shift

See Also
GF2nPolynomialElement#invertEEA
shiftLeftThisback to summary
public void shiftLeftThis()

Shifts-left this by one and enlarges the size of value if necesary.

shiftRightback to summary
public GF2Polynomial shiftRight()

Returns this GF2Polynomial shift-right by 1 in a new GF2Polynomial.

Returns:GF2Polynomial

a new GF2Polynomial (this << 1)

shiftRightThisback to summary
public void shiftRightThis()

Shifts-right this GF2Polynomial by 1.

squareThisBitwiseback to summary
public void squareThisBitwise()

Squares this GF2Polynomial and expands it accordingly. This method does not reduce the result in GF(2^N). There exists a faster method for squaring in GF(2^N).

See Also
GF2nPolynomialElement#square
squareThisPreCalcback to summary
public void squareThisPreCalc()

Squares this GF2Polynomial by using precomputed values of squaringTable. This method does not reduce the result in GF(2^N).

subtractback to summary
public GF2Polynomial subtract(GF2Polynomial b)

Subtracts two GF2Polynomials, this and b, and returns the result in a new GF2Polynomial. this and b can be of different size.

Parameters
b:GF2Polynomial

a GF2Polynomial

Returns:GF2Polynomial

a new GF2Polynomial (this - b)

subtractFromThisback to summary
public void subtractFromThis(GF2Polynomial b)

Subtracts b from this GF2Polynomial and assigns the result to this GF2Polynomial. b can be of different size.

Parameters
b:GF2Polynomial

a GF2Polynomial

testBitback to summary
public boolean testBit(int i)

Tests the bit at position i.

Parameters
i:int

the position of the bit to be tested

Returns:boolean

true if the bit at position i is set (a(i) == 1). False if (i < 0) || (i > (len - 1))

toByteArrayback to summary
public byte[] toByteArray()

Converts this polynomial to a byte[] (octet string) according to 1363.

Returns:byte[]

a byte[] representing the value of this polynomial

See Also
P1363 5.5.2 p22f, BS2OSP
toFlexiBigIntback to summary
public BigInteger toFlexiBigInt()

Converts this polynomial to an integer according to 1363.

Returns:BigInteger

a FlexiBigInt representing the value of this polynomial

See Also
P1363 5.5.1 p22, BS2IP
toIntegerArrayback to summary
public int[] toIntegerArray()

Returns the value of this GF2Polynomial in an int[].

Returns:int[]

the value of this GF2Polynomial in a new int[], LSB in int[0]

toStringback to summary
public String toString(int radix)

Returns a string representing this GF2Polynomials value using hexadecimal or binary radix in MSB-first order.

Parameters
radix:int

the radix to use (2 or 16, otherwise 2 is used)

Returns:String

a String representing this GF2Polynomials value.

upperback to summary
private GF2Polynomial upper(int k)

Returns a new GF2Polynomial containing the upper k bytes of this GF2Polynomial.

Returns:GF2Polynomial

a new GF2Polynomial containing the upper k bytes of this GF2Polynomial

See Also
GF2Polynomial#karaMult
vectorMultback to summary
public boolean vectorMult(GF2Polynomial b) throws RuntimeException

Does a vector-multiplication modulo 2 and returns the result as boolean.

Parameters
b:GF2Polynomial

GF2Polynomial

Returns:boolean

this x b as boolean (1->true, 0->false)

xorback to summary
public GF2Polynomial xor(GF2Polynomial b)

Returns the bitwise exclusive-or of this and b in a new GF2Polynomial. this and b can be of different size.

Parameters
b:GF2Polynomial

GF2Polynomial

Returns:GF2Polynomial

a new GF2Polynomial (this ^ b)

xorBitback to summary
public void xorBit(int i) throws RuntimeException

Xors the bit at position i.

Parameters
i:int

int

Exceptions
RuntimeException:
if (i < 0) || (i > (len - 1))
xorThisByback to summary
public void xorThisBy(GF2Polynomial b)

Computes the bitwise exclusive-or of this GF2Polynomial and b and stores the result in this GF2Polynomial. b can be of different size.

Parameters
b:GF2Polynomial

GF2Polynomial

zeroUnusedBitsback to summary
private void zeroUnusedBits()

If len is not a multiple of the block size (32), some extra bits of the last block might have been modified during a blockwise operation. This method compensates for that by restoring these "extra" bits to zero.