what-the-bank/sources/org/bouncycastle/pqc/jcajce/provider/mceliece/McElieceKeysToParams.java

28 lines
1.4 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package org.bouncycastle.pqc.jcajce.provider.mceliece;
import java.security.InvalidKeyException;
import java.security.PrivateKey;
import java.security.PublicKey;
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
import org.bouncycastle.pqc.crypto.mceliece.McEliecePrivateKeyParameters;
/* loaded from: classes6.dex */
public class McElieceKeysToParams {
public static AsymmetricKeyParameter generatePublicKeyParameter(PublicKey publicKey) throws InvalidKeyException {
if (publicKey instanceof BCMcEliecePublicKey) {
return ((BCMcEliecePublicKey) publicKey).getKeyParams();
}
StringBuilder sb = new StringBuilder("can't identify McEliece public key: ");
sb.append(publicKey.getClass().getName());
throw new InvalidKeyException(sb.toString());
}
public static AsymmetricKeyParameter generatePrivateKeyParameter(PrivateKey privateKey) throws InvalidKeyException {
if (!(privateKey instanceof BCMcEliecePrivateKey)) {
throw new InvalidKeyException("can't identify McEliece private key.");
}
BCMcEliecePrivateKey bCMcEliecePrivateKey = (BCMcEliecePrivateKey) privateKey;
return new McEliecePrivateKeyParameters(bCMcEliecePrivateKey.getN(), bCMcEliecePrivateKey.getK(), bCMcEliecePrivateKey.getField(), bCMcEliecePrivateKey.getGoppaPoly(), bCMcEliecePrivateKey.getP1(), bCMcEliecePrivateKey.getP2(), bCMcEliecePrivateKey.getSInv());
}
}