/** * Multiplies this GF2Polynomial with <i>b</i> and returns the result in a * new GF2Polynomial. This method does not reduce the result in GF(2^N). * This method uses Karatzuba multiplication. * * @param b a GF2Polynomial * @return a new GF2Polynomial (<i>this</i> * <i>b</i>) */ public GF2Polynomial multiply(GF2Polynomial b) { int n = Math.max(len, b.len); expandN(n); b.expandN(n); return karaMult(b); }
/** * Multiplies this GF2Polynomial with <i>b</i> and returns the result in a * new GF2Polynomial. This method does not reduce the result in GF(2^N). * This method uses Karatzuba multiplication. * * @param b a GF2Polynomial * @return a new GF2Polynomial (<i>this</i> * <i>b</i>) */ public GF2Polynomial multiply(GF2Polynomial b) { int n = Math.max(len, b.len); expandN(n); b.expandN(n); return karaMult(b); }
/** * Adds <i>b</i> to this GF2Polynomial and assigns the result to this * GF2Polynomial. <i>b</i> can be of different size. * * @param b GF2Polynomial to add to this GF2Polynomial */ public void addToThis(GF2Polynomial b) { expandN(b.len); xorThisBy(b); }
/** * Subtracts <i>b</i> from this GF2Polynomial and assigns the result to * this GF2Polynomial. <i>b</i> can be of different size. * * @param b a GF2Polynomial */ public void subtractFromThis(GF2Polynomial b) { expandN(b.len); xorThisBy(b); }
/** * Assign a random value to this GF2nPolynomialElement using the specified * source of randomness. * * @param rand the source of randomness */ private void randomize(Random rand) { polynomial.expandN(mDegree); polynomial.randomize(rand); }
/** * Subtracts <i>b</i> from this GF2Polynomial and assigns the result to * this GF2Polynomial. <i>b</i> can be of different size. * * @param b a GF2Polynomial */ public void subtractFromThis(GF2Polynomial b) { expandN(b.len); xorThisBy(b); }
/** * Adds <i>b</i> to this GF2Polynomial and assigns the result to this * GF2Polynomial. <i>b</i> can be of different size. * * @param b GF2Polynomial to add to this GF2Polynomial */ public void addToThis(GF2Polynomial b) { expandN(b.len); xorThisBy(b); }
/** * Assign a random value to this GF2nPolynomialElement using the specified * source of randomness. * * @param rand the source of randomness */ private void randomize(Random rand) { polynomial.expandN(mDegree); polynomial.randomize(rand); }
/** * Shifts left b and adds the result to Its a fast version of * <tt>this = add(b.shl(k));</tt> * * @param b GF2Polynomial to shift and add to this * @param k the amount to shift * @see GF2nPolynomialElement#invertEEA */ public void shiftLeftAddThis(GF2Polynomial b, int k) { if (k == 0) { addToThis(b); return; } int i; expandN(b.len + k); int d = k >>> 5; for (i = b.blocks - 1; i >= 0; i--) { if ((i + d + 1 < blocks) && ((k & 0x1f) != 0)) { value[i + d + 1] ^= b.value[i] >>> (32 - (k & 0x1f)); } value[i + d] ^= b.value[i] << (k & 0x1f); } }
/** * Creates a new GF2nPolynomialElement using the given field and Bitstring. * * @param f the GF2nPolynomialField to use * @param bs the desired value as Bitstring */ public GF2nPolynomialElement(GF2nPolynomialField f, GF2Polynomial bs) { mField = f; mDegree = mField.getDegree(); polynomial = new GF2Polynomial(bs); polynomial.expandN(mDegree); }
/** * Creates a new GF2nPolynomialElement using the given field and Bitstring. * * @param f the GF2nPolynomialField to use * @param bs the desired value as Bitstring */ public GF2nPolynomialElement(GF2nPolynomialField f, GF2Polynomial bs) { mField = f; mDegree = mField.getDegree(); polynomial = new GF2Polynomial(bs); polynomial.expandN(mDegree); }
/** * Creates a new GF2nPolynomialElement using the given field <i>f</i> and * int[] <i>is</i> as value. * * @param f the GF2nField to use * @param is the integer string to assign to this GF2nPolynomialElement */ public GF2nPolynomialElement(GF2nPolynomialField f, int[] is) { mField = f; mDegree = mField.getDegree(); polynomial = new GF2Polynomial(mDegree, is); polynomial.expandN(f.mDegree); }
/** * Creates a new GF2nPolynomialElement using the given field <i>f</i> and * byte[] <i>os</i> as value. The conversion is done according to 1363. * * @param f the GF2nField to use * @param os the octet string to assign to this GF2nPolynomialElement * @see "P1363 5.5.5 p23, OS2FEP/OS2BSP" */ public GF2nPolynomialElement(GF2nPolynomialField f, byte[] os) { mField = f; mDegree = mField.getDegree(); polynomial = new GF2Polynomial(mDegree, os); polynomial.expandN(mDegree); }
/** * Creates a new GF2nPolynomialElement using the given field <i>f</i> and * int[] <i>is</i> as value. * * @param f the GF2nField to use * @param is the integer string to assign to this GF2nPolynomialElement */ public GF2nPolynomialElement(GF2nPolynomialField f, int[] is) { mField = f; mDegree = mField.getDegree(); polynomial = new GF2Polynomial(mDegree, is); polynomial.expandN(f.mDegree); }
/** * Creates a new GF2nPolynomialElement using the given field <i>f</i> and * byte[] <i>os</i> as value. The conversion is done according to 1363. * * @param f the GF2nField to use * @param os the octet string to assign to this GF2nPolynomialElement * @see "P1363 5.5.5 p23, OS2FEP/OS2BSP" */ public GF2nPolynomialElement(GF2nPolynomialField f, byte[] os) { mField = f; mDegree = mField.getDegree(); polynomial = new GF2Polynomial(mDegree, os); polynomial.expandN(mDegree); }
/** * Compute the square root of this element. */ public void squareRootThis() { // increase performance polynomial.expandN((mDegree << 1) + 32); polynomial.reduceN(); for (int i = 0; i < mField.getDegree() - 1; i++) { squareThis(); } }
/** * Compute the square root of this element. */ public void squareRootThis() { // increase performance polynomial.expandN((mDegree << 1) + 32); polynomial.reduceN(); for (int i = 0; i < mField.getDegree() - 1; i++) { squareThis(); } }
/** * Reduce this GF2nPolynomialElement using the trinomial x^n + x^tc + 1 as * fieldpolynomial. The coefficients are reduced bit by bit. */ private void reduceTrinomialBitwise(int tc) { int i; int k = mDegree - tc; for (i = polynomial.getLength() - 1; i >= mDegree; i--) { if (polynomial.testBit(i)) { polynomial.xorBit(i); polynomial.xorBit(i - k); polynomial.xorBit(i - mDegree); } } polynomial.reduceN(); polynomial.expandN(mDegree); }
/** * Reduce this GF2nPolynomialElement using the trinomial x^n + x^tc + 1 as * fieldpolynomial. The coefficients are reduced bit by bit. */ private void reduceTrinomialBitwise(int tc) { int i; int k = mDegree - tc; for (i = polynomial.getLength() - 1; i >= mDegree; i--) { if (polynomial.testBit(i)) { polynomial.xorBit(i); polynomial.xorBit(i - k); polynomial.xorBit(i - mDegree); } } polynomial.reduceN(); polynomial.expandN(mDegree); }
/** * Reduce this GF2nPolynomialElement using the pentanomial x^n + x^pc[2] + * x^pc[1] + x^pc[0] + 1 as fieldpolynomial. The coefficients are reduced * bit by bit. */ private void reducePentanomialBitwise(int[] pc) { int i; int k = mDegree - pc[2]; int l = mDegree - pc[1]; int m = mDegree - pc[0]; for (i = polynomial.getLength() - 1; i >= mDegree; i--) { if (polynomial.testBit(i)) { polynomial.xorBit(i); polynomial.xorBit(i - k); polynomial.xorBit(i - l); polynomial.xorBit(i - m); polynomial.xorBit(i - mDegree); } } polynomial.reduceN(); polynomial.expandN(mDegree); }