what-the-bank/sources/org/bouncycastle/pqc/crypto/mceliece/McElieceCCA2KeyPairGenerato...

54 lines
2.9 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
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;
/* loaded from: classes6.dex */
public class McElieceCCA2KeyPairGenerator implements AsymmetricCipherKeyPairGenerator {
public static final String OID = "1.3.6.1.4.1.8301.3.1.3.4.2";
private int fieldPoly;
private boolean initialized = false;
private int m;
private McElieceCCA2KeyGenerationParameters mcElieceCCA2Params;
private int n;
private SecureRandom random;
private int t;
@Override // org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator
public void init(KeyGenerationParameters keyGenerationParameters) {
this.mcElieceCCA2Params = (McElieceCCA2KeyGenerationParameters) keyGenerationParameters;
this.random = new SecureRandom();
this.m = this.mcElieceCCA2Params.getParameters().getM();
this.n = this.mcElieceCCA2Params.getParameters().getN();
this.t = this.mcElieceCCA2Params.getParameters().getT();
this.fieldPoly = this.mcElieceCCA2Params.getParameters().getFieldPoly();
this.initialized = true;
}
@Override // org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator
public AsymmetricCipherKeyPair generateKeyPair() {
if (!this.initialized) {
initializeDefault();
}
GF2mField gF2mField = new GF2mField(this.m, this.fieldPoly);
PolynomialGF2mSmallM polynomialGF2mSmallM = new PolynomialGF2mSmallM(gF2mField, this.t, 'I', this.random);
GoppaCode.MaMaPe computeSystematicForm = GoppaCode.computeSystematicForm(GoppaCode.createCanonicalCheckMatrix(gF2mField, polynomialGF2mSmallM), this.random);
GF2Matrix secondMatrix = computeSystematicForm.getSecondMatrix();
Permutation permutation = computeSystematicForm.getPermutation();
GF2Matrix gF2Matrix = (GF2Matrix) secondMatrix.computeTranspose();
return new AsymmetricCipherKeyPair((AsymmetricKeyParameter) new McElieceCCA2PublicKeyParameters(this.n, this.t, gF2Matrix, this.mcElieceCCA2Params.getParameters().getDigest()), (AsymmetricKeyParameter) new McElieceCCA2PrivateKeyParameters(this.n, gF2Matrix.getNumRows(), gF2mField, polynomialGF2mSmallM, permutation, this.mcElieceCCA2Params.getParameters().getDigest()));
}
private void initializeDefault() {
init(new McElieceCCA2KeyGenerationParameters(new SecureRandom(), new McElieceCCA2Parameters()));
}
}