package org.bouncycastle.pqc.crypto.mceliece; import java.security.SecureRandom; import org.bouncycastle.crypto.AsymmetricCipherKeyPair; import org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator; import org.bouncycastle.crypto.KeyGenerationParameters; import org.bouncycastle.crypto.params.AsymmetricKeyParameter; import org.bouncycastle.pqc.math.linearalgebra.GF2Matrix; import org.bouncycastle.pqc.math.linearalgebra.GF2mField; import org.bouncycastle.pqc.math.linearalgebra.GoppaCode; import org.bouncycastle.pqc.math.linearalgebra.Permutation; import org.bouncycastle.pqc.math.linearalgebra.PolynomialGF2mSmallM; import org.bouncycastle.pqc.math.linearalgebra.PolynomialRingGF2m; /* loaded from: classes6.dex */ public class McElieceKeyPairGenerator implements AsymmetricCipherKeyPairGenerator { private static final String OID = "1.3.6.1.4.1.8301.3.1.3.4.1"; private int fieldPoly; private boolean initialized = false; private int m; private McElieceKeyGenerationParameters mcElieceParams; private int n; private SecureRandom random; private int t; @Override // org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator public void init(KeyGenerationParameters keyGenerationParameters) { initialize(keyGenerationParameters); } @Override // org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator public AsymmetricCipherKeyPair generateKeyPair() { return genKeyPair(); } private void initializeDefault() { initialize(new McElieceKeyGenerationParameters(new SecureRandom(), new McElieceParameters())); } private void initialize(KeyGenerationParameters keyGenerationParameters) { this.mcElieceParams = (McElieceKeyGenerationParameters) keyGenerationParameters; this.random = new SecureRandom(); this.m = this.mcElieceParams.getParameters().getM(); this.n = this.mcElieceParams.getParameters().getN(); this.t = this.mcElieceParams.getParameters().getT(); this.fieldPoly = this.mcElieceParams.getParameters().getFieldPoly(); this.initialized = true; } private AsymmetricCipherKeyPair genKeyPair() { if (!this.initialized) { initializeDefault(); } GF2mField gF2mField = new GF2mField(this.m, this.fieldPoly); PolynomialGF2mSmallM polynomialGF2mSmallM = new PolynomialGF2mSmallM(gF2mField, this.t, 'I', this.random); new PolynomialRingGF2m(gF2mField, polynomialGF2mSmallM).getSquareRootMatrix(); GoppaCode.MaMaPe computeSystematicForm = GoppaCode.computeSystematicForm(GoppaCode.createCanonicalCheckMatrix(gF2mField, polynomialGF2mSmallM), this.random); GF2Matrix secondMatrix = computeSystematicForm.getSecondMatrix(); Permutation permutation = computeSystematicForm.getPermutation(); GF2Matrix gF2Matrix = (GF2Matrix) secondMatrix.computeTranspose(); GF2Matrix extendLeftCompactForm = gF2Matrix.extendLeftCompactForm(); int numRows = gF2Matrix.getNumRows(); GF2Matrix[] createRandomRegularMatrixAndItsInverse = GF2Matrix.createRandomRegularMatrixAndItsInverse(numRows, this.random); Permutation permutation2 = new Permutation(this.n, this.random); return new AsymmetricCipherKeyPair((AsymmetricKeyParameter) new McEliecePublicKeyParameters(this.n, this.t, (GF2Matrix) ((GF2Matrix) createRandomRegularMatrixAndItsInverse[0].rightMultiply(extendLeftCompactForm)).rightMultiply(permutation2)), (AsymmetricKeyParameter) new McEliecePrivateKeyParameters(this.n, numRows, gF2mField, polynomialGF2mSmallM, permutation, permutation2, createRandomRegularMatrixAndItsInverse[1])); } }