76 lines
3.4 KiB
Java
76 lines
3.4 KiB
Java
package org.bouncycastle.pqc.jcajce.provider.mceliece;
|
|
|
|
import java.security.InvalidAlgorithmParameterException;
|
|
import java.security.InvalidKeyException;
|
|
import java.security.Key;
|
|
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.params.ParametersWithRandom;
|
|
import org.bouncycastle.pqc.crypto.mceliece.McElieceCipher;
|
|
import org.bouncycastle.pqc.crypto.mceliece.McElieceKeyParameters;
|
|
import org.bouncycastle.pqc.jcajce.provider.util.AsymmetricBlockCipher;
|
|
|
|
/* loaded from: classes6.dex */
|
|
public class McEliecePKCSCipherSpi extends AsymmetricBlockCipher implements PKCSObjectIdentifiers, X509ObjectIdentifiers {
|
|
private McElieceCipher cipher;
|
|
|
|
@Override // org.bouncycastle.pqc.jcajce.provider.util.AsymmetricBlockCipher
|
|
public byte[] messageEncrypt(byte[] bArr) throws IllegalBlockSizeException, BadPaddingException {
|
|
try {
|
|
return this.cipher.messageEncrypt(bArr);
|
|
} catch (Exception unused) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
@Override // org.bouncycastle.pqc.jcajce.provider.util.AsymmetricBlockCipher
|
|
public byte[] messageDecrypt(byte[] bArr) throws IllegalBlockSizeException, BadPaddingException {
|
|
try {
|
|
return this.cipher.messageDecrypt(bArr);
|
|
} catch (Exception unused) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
@Override // org.bouncycastle.pqc.jcajce.provider.util.AsymmetricBlockCipher
|
|
public void initCipherEncrypt(Key key, AlgorithmParameterSpec algorithmParameterSpec, SecureRandom secureRandom) throws InvalidKeyException, InvalidAlgorithmParameterException {
|
|
this.cipher.init(true, new ParametersWithRandom(McElieceKeysToParams.generatePublicKeyParameter((PublicKey) key), secureRandom));
|
|
this.maxPlainTextSize = this.cipher.maxPlainTextSize;
|
|
this.cipherTextSize = this.cipher.cipherTextSize;
|
|
}
|
|
|
|
@Override // org.bouncycastle.pqc.jcajce.provider.util.AsymmetricBlockCipher
|
|
public void initCipherDecrypt(Key key, AlgorithmParameterSpec algorithmParameterSpec) throws InvalidKeyException, InvalidAlgorithmParameterException {
|
|
this.cipher.init(false, McElieceKeysToParams.generatePrivateKeyParameter((PrivateKey) key));
|
|
this.maxPlainTextSize = this.cipher.maxPlainTextSize;
|
|
this.cipherTextSize = this.cipher.cipherTextSize;
|
|
}
|
|
|
|
@Override // org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt
|
|
public String getName() {
|
|
return "McEliecePKCS";
|
|
}
|
|
|
|
/* loaded from: classes6.dex */
|
|
public static class McEliecePKCS extends McEliecePKCSCipherSpi {
|
|
public McEliecePKCS() {
|
|
super(new McElieceCipher());
|
|
}
|
|
}
|
|
|
|
@Override // org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt
|
|
public int getKeySize(Key key) throws InvalidKeyException {
|
|
return this.cipher.getKeySize((McElieceKeyParameters) (key instanceof PublicKey ? McElieceKeysToParams.generatePublicKeyParameter((PublicKey) key) : McElieceKeysToParams.generatePrivateKeyParameter((PrivateKey) key)));
|
|
}
|
|
|
|
public McEliecePKCSCipherSpi(McElieceCipher mcElieceCipher) {
|
|
this.cipher = mcElieceCipher;
|
|
}
|
|
}
|