what-the-bank/sources/org/bouncycastle/pqc/jcajce/provider/rainbow/RainbowKeysToParams.java

30 lines
1.7 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package org.bouncycastle.pqc.jcajce.provider.rainbow;
import java.security.InvalidKeyException;
import java.security.PrivateKey;
import java.security.PublicKey;
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
import org.bouncycastle.pqc.crypto.rainbow.RainbowPrivateKeyParameters;
import org.bouncycastle.pqc.crypto.rainbow.RainbowPublicKeyParameters;
/* loaded from: classes6.dex */
public class RainbowKeysToParams {
public static AsymmetricKeyParameter generatePublicKeyParameter(PublicKey publicKey) throws InvalidKeyException {
if (publicKey instanceof BCRainbowPublicKey) {
BCRainbowPublicKey bCRainbowPublicKey = (BCRainbowPublicKey) publicKey;
return new RainbowPublicKeyParameters(bCRainbowPublicKey.getDocLength(), bCRainbowPublicKey.getCoeffQuadratic(), bCRainbowPublicKey.getCoeffSingular(), bCRainbowPublicKey.getCoeffScalar());
}
StringBuilder sb = new StringBuilder("can't identify Rainbow public key: ");
sb.append(publicKey.getClass().getName());
throw new InvalidKeyException(sb.toString());
}
public static AsymmetricKeyParameter generatePrivateKeyParameter(PrivateKey privateKey) throws InvalidKeyException {
if (!(privateKey instanceof BCRainbowPrivateKey)) {
throw new InvalidKeyException("can't identify Rainbow private key.");
}
BCRainbowPrivateKey bCRainbowPrivateKey = (BCRainbowPrivateKey) privateKey;
return new RainbowPrivateKeyParameters(bCRainbowPrivateKey.getInvA1(), bCRainbowPrivateKey.getB1(), bCRainbowPrivateKey.getInvA2(), bCRainbowPrivateKey.getB2(), bCRainbowPrivateKey.getVi(), bCRainbowPrivateKey.getLayers());
}
}