org.bouncycastle.pqc.math.ntru.polynomial.ModularResultant Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcprov-jdk15to18 Show documentation
Show all versions of bcprov-jdk15to18 Show documentation
The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5 to JDK 1.8.
package org.bouncycastle.pqc.math.ntru.polynomial; import java.math.BigInteger; import org.bouncycastle.pqc.math.ntru.euclid.BigIntEuclidean; /** * A resultant modulo a
res is set toBigInteger
*/ public class ModularResultant extends Resultant { BigInteger modulus; ModularResultant(BigIntPolynomial rho, BigInteger res, BigInteger modulus) { super(rho, res); this.modulus = modulus; } /** * Calculates arho
modulom1*m2
from * two resultants whoserho
s are modulom1
andm2
.
*null
. * * @param modRes1 * @param modRes2 * @returnrho
modulomodRes1.modulus * modRes2.modulus
, andnull
for res. */ static ModularResultant combineRho(ModularResultant modRes1, ModularResultant modRes2) { BigInteger mod1 = modRes1.modulus; BigInteger mod2 = modRes2.modulus; BigInteger prod = mod1.multiply(mod2); BigIntEuclidean er = BigIntEuclidean.calculate(mod2, mod1); BigIntPolynomial rho1 = (BigIntPolynomial)modRes1.rho.clone(); rho1.mult(er.x.multiply(mod2)); BigIntPolynomial rho2 = (BigIntPolynomial)modRes2.rho.clone(); rho2.mult(er.y.multiply(mod1)); rho1.add(rho2); rho1.mod(prod); return new ModularResultant(rho1, null, prod); } }