package org.bouncycastle.pqc.jcajce.provider.mceliece; import java.io.ByteArrayOutputStream; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.Key; import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; import java.security.PublicKey; import java.security.SecureRandom; import java.security.spec.AlgorithmParameterSpec; import javax.crypto.BadPaddingException; import javax.crypto.IllegalBlockSizeException; import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; import org.bouncycastle.asn1.x509.X509ObjectIdentifiers; import org.bouncycastle.crypto.Digest; import org.bouncycastle.crypto.digests.SHA1Digest; import org.bouncycastle.crypto.digests.SHA224Digest; import org.bouncycastle.crypto.digests.SHA256Digest; import org.bouncycastle.crypto.digests.SHA384Digest; import org.bouncycastle.crypto.digests.SHA512Digest; import org.bouncycastle.crypto.params.AsymmetricKeyParameter; import org.bouncycastle.crypto.params.ParametersWithRandom; import org.bouncycastle.pqc.crypto.mceliece.McElieceCCA2KeyParameters; import org.bouncycastle.pqc.crypto.mceliece.McEliecePointchevalCipher; import org.bouncycastle.pqc.jcajce.provider.util.AsymmetricHybridCipher; /* loaded from: classes6.dex */ public class McEliecePointchevalCipherSpi extends AsymmetricHybridCipher implements PKCSObjectIdentifiers, X509ObjectIdentifiers { private ByteArrayOutputStream buf; private McEliecePointchevalCipher cipher; private Digest digest; @Override // org.bouncycastle.pqc.jcajce.provider.util.AsymmetricHybridCipher public int decryptOutputSize(int i) { return 0; } @Override // org.bouncycastle.pqc.jcajce.provider.util.AsymmetricHybridCipher public int encryptOutputSize(int i) { return 0; } @Override // org.bouncycastle.pqc.jcajce.provider.util.AsymmetricHybridCipher, org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt public byte[] update(byte[] bArr, int i, int i2) { this.buf.write(bArr, i, i2); return new byte[0]; } public byte[] messageEncrypt(byte[] bArr) throws IllegalBlockSizeException, BadPaddingException, NoSuchAlgorithmException { try { return this.cipher.messageEncrypt(bArr); } catch (Exception unused) { return null; } } public byte[] messageDecrypt(byte[] bArr) throws IllegalBlockSizeException, BadPaddingException, NoSuchAlgorithmException { try { return this.cipher.messageDecrypt(bArr); } catch (Exception unused) { return null; } } @Override // org.bouncycastle.pqc.jcajce.provider.util.AsymmetricHybridCipher public void initCipherEncrypt(Key key, AlgorithmParameterSpec algorithmParameterSpec, SecureRandom secureRandom) throws InvalidKeyException, InvalidAlgorithmParameterException { ParametersWithRandom parametersWithRandom = new ParametersWithRandom(McElieceCCA2KeysToParams.generatePublicKeyParameter((PublicKey) key), secureRandom); this.digest.reset(); this.cipher.init(true, parametersWithRandom); } @Override // org.bouncycastle.pqc.jcajce.provider.util.AsymmetricHybridCipher public void initCipherDecrypt(Key key, AlgorithmParameterSpec algorithmParameterSpec) throws InvalidKeyException, InvalidAlgorithmParameterException { AsymmetricKeyParameter generatePrivateKeyParameter = McElieceCCA2KeysToParams.generatePrivateKeyParameter((PrivateKey) key); this.digest.reset(); this.cipher.init(false, generatePrivateKeyParameter); } @Override // org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt public String getName() { return "McEliecePointchevalCipher"; } @Override // org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt public int getKeySize(Key key) throws InvalidKeyException { return this.cipher.getKeySize((McElieceCCA2KeyParameters) (key instanceof PublicKey ? McElieceCCA2KeysToParams.generatePublicKeyParameter((PublicKey) key) : McElieceCCA2KeysToParams.generatePrivateKeyParameter((PrivateKey) key))); } @Override // org.bouncycastle.pqc.jcajce.provider.util.AsymmetricHybridCipher, org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt public byte[] doFinal(byte[] bArr, int i, int i2) throws BadPaddingException { update(bArr, i, i2); byte[] byteArray = this.buf.toByteArray(); this.buf.reset(); try { if (this.opMode == 1) { return this.cipher.messageEncrypt(byteArray); } if (this.opMode == 2) { return this.cipher.messageDecrypt(byteArray); } return null; } catch (Exception unused) { return null; } } /* loaded from: classes6.dex */ public static class McEliecePointcheval extends McEliecePointchevalCipherSpi { public McEliecePointcheval() { super(new SHA1Digest(), new McEliecePointchevalCipher()); } } /* loaded from: classes6.dex */ public static class McEliecePointcheval224 extends McEliecePointchevalCipherSpi { public McEliecePointcheval224() { super(new SHA224Digest(), new McEliecePointchevalCipher()); } } /* loaded from: classes6.dex */ public static class McEliecePointcheval256 extends McEliecePointchevalCipherSpi { public McEliecePointcheval256() { super(new SHA256Digest(), new McEliecePointchevalCipher()); } } /* loaded from: classes6.dex */ public static class McEliecePointcheval384 extends McEliecePointchevalCipherSpi { public McEliecePointcheval384() { super(new SHA384Digest(), new McEliecePointchevalCipher()); } } /* loaded from: classes6.dex */ public static class McEliecePointcheval512 extends McEliecePointchevalCipherSpi { public McEliecePointcheval512() { super(new SHA512Digest(), new McEliecePointchevalCipher()); } } protected McEliecePointchevalCipherSpi(Digest digest, McEliecePointchevalCipher mcEliecePointchevalCipher) { this.buf = new ByteArrayOutputStream(); this.digest = digest; this.cipher = mcEliecePointchevalCipher; this.buf = new ByteArrayOutputStream(); } }