// 
// Decompiled by Procyon v0.6.0
// 

package org.bouncycastle.jcajce.provider.asymmetric.slhdsa;

import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import org.bouncycastle.jcajce.util.SpecUtil;
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
import java.security.PrivateKey;
import java.security.PublicKey;
import org.bouncycastle.pqc.crypto.slhdsa.SLHDSAPrivateKeyParameters;
import org.bouncycastle.pqc.crypto.slhdsa.SLHDSAPublicKeyParameters;
import java.security.KeyPair;
import java.security.InvalidAlgorithmParameterException;
import java.security.spec.AlgorithmParameterSpec;
import org.bouncycastle.crypto.KeyGenerationParameters;
import org.bouncycastle.pqc.crypto.slhdsa.SLHDSAParameters;
import org.bouncycastle.util.Strings;
import org.bouncycastle.jcajce.spec.SLHDSAParameterSpec;
import org.bouncycastle.crypto.CryptoServicesRegistrar;
import java.security.SecureRandom;
import org.bouncycastle.pqc.crypto.slhdsa.SLHDSAKeyPairGenerator;
import org.bouncycastle.pqc.crypto.slhdsa.SLHDSAKeyGenerationParameters;
import java.util.Map;
import java.security.KeyPairGenerator;

public class SLHDSAKeyPairGeneratorSpi extends KeyPairGenerator
{
    private static Map parameters;
    SLHDSAKeyGenerationParameters param;
    SLHDSAKeyPairGenerator engine;
    SecureRandom random;
    boolean initialised;
    
    public SLHDSAKeyPairGeneratorSpi(final String algorithm) {
        super(algorithm);
        this.engine = new SLHDSAKeyPairGenerator();
        this.random = CryptoServicesRegistrar.getSecureRandom();
        this.initialised = false;
    }
    
    protected SLHDSAKeyPairGeneratorSpi(final SLHDSAParameterSpec slhdsaParameterSpec) {
        super("SLH-DSA-" + Strings.toUpperCase(slhdsaParameterSpec.getName()));
        this.engine = new SLHDSAKeyPairGenerator();
        this.random = CryptoServicesRegistrar.getSecureRandom();
        this.initialised = false;
        this.param = new SLHDSAKeyGenerationParameters(this.random, SLHDSAKeyPairGeneratorSpi.parameters.get(slhdsaParameterSpec.getName()));
        this.engine.init(this.param);
        this.initialised = true;
    }
    
    @Override
    public void initialize(final int n, final SecureRandom secureRandom) {
        throw new IllegalArgumentException("use AlgorithmParameterSpec");
    }
    
    @Override
    public void initialize(final AlgorithmParameterSpec obj, final SecureRandom secureRandom) throws InvalidAlgorithmParameterException {
        final String nameFromParams = getNameFromParams(obj);
        if (nameFromParams == null) {
            throw new InvalidAlgorithmParameterException("invalid ParameterSpec: " + obj);
        }
        final SLHDSAParameters slhdsaParameters = SLHDSAKeyPairGeneratorSpi.parameters.get(nameFromParams);
        if (slhdsaParameters == null) {
            throw new InvalidAlgorithmParameterException("unknown parameter set name: " + nameFromParams);
        }
        this.param = new SLHDSAKeyGenerationParameters(secureRandom, slhdsaParameters);
        this.engine.init(this.param);
        this.initialised = true;
    }
    
    @Override
    public KeyPair generateKeyPair() {
        if (!this.initialised) {
            if (this.getAlgorithm().startsWith("HASH")) {
                this.param = new SLHDSAKeyGenerationParameters(this.random, SLHDSAParameters.sha2_128f_with_sha256);
            }
            else {
                this.param = new SLHDSAKeyGenerationParameters(this.random, SLHDSAParameters.sha2_128f);
            }
            this.engine.init(this.param);
            this.initialised = true;
        }
        final AsymmetricCipherKeyPair generateKeyPair = this.engine.generateKeyPair();
        return new KeyPair(new BCSLHDSAPublicKey((SLHDSAPublicKeyParameters)generateKeyPair.getPublic()), new BCSLHDSAPrivateKey((SLHDSAPrivateKeyParameters)generateKeyPair.getPrivate()));
    }
    
    private static String getNameFromParams(final AlgorithmParameterSpec algorithmParameterSpec) {
        if (algorithmParameterSpec instanceof SLHDSAParameterSpec) {
            return ((SLHDSAParameterSpec)algorithmParameterSpec).getName();
        }
        return Strings.toUpperCase(SpecUtil.getNameFrom(algorithmParameterSpec));
    }
    
    static {
        (SLHDSAKeyPairGeneratorSpi.parameters = new HashMap()).put(SLHDSAParameterSpec.slh_dsa_sha2_128f.getName(), SLHDSAParameters.sha2_128f);
        SLHDSAKeyPairGeneratorSpi.parameters.put(SLHDSAParameterSpec.slh_dsa_sha2_128s.getName(), SLHDSAParameters.sha2_128s);
        SLHDSAKeyPairGeneratorSpi.parameters.put(SLHDSAParameterSpec.slh_dsa_sha2_192f.getName(), SLHDSAParameters.sha2_192f);
        SLHDSAKeyPairGeneratorSpi.parameters.put(SLHDSAParameterSpec.slh_dsa_sha2_192s.getName(), SLHDSAParameters.sha2_192s);
        SLHDSAKeyPairGeneratorSpi.parameters.put(SLHDSAParameterSpec.slh_dsa_sha2_256f.getName(), SLHDSAParameters.sha2_256f);
        SLHDSAKeyPairGeneratorSpi.parameters.put(SLHDSAParameterSpec.slh_dsa_sha2_256s.getName(), SLHDSAParameters.sha2_256s);
        SLHDSAKeyPairGeneratorSpi.parameters.put(SLHDSAParameterSpec.slh_dsa_shake_128f.getName(), SLHDSAParameters.shake_128f);
        SLHDSAKeyPairGeneratorSpi.parameters.put(SLHDSAParameterSpec.slh_dsa_shake_128s.getName(), SLHDSAParameters.shake_128s);
        SLHDSAKeyPairGeneratorSpi.parameters.put(SLHDSAParameterSpec.slh_dsa_shake_192f.getName(), SLHDSAParameters.shake_192f);
        SLHDSAKeyPairGeneratorSpi.parameters.put(SLHDSAParameterSpec.slh_dsa_shake_192s.getName(), SLHDSAParameters.shake_192s);
        SLHDSAKeyPairGeneratorSpi.parameters.put(SLHDSAParameterSpec.slh_dsa_shake_256f.getName(), SLHDSAParameters.shake_256f);
        SLHDSAKeyPairGeneratorSpi.parameters.put(SLHDSAParameterSpec.slh_dsa_shake_256s.getName(), SLHDSAParameters.shake_256s);
        SLHDSAKeyPairGeneratorSpi.parameters.put(SLHDSAParameterSpec.slh_dsa_sha2_128f_with_sha256.getName(), SLHDSAParameters.sha2_128f_with_sha256);
        SLHDSAKeyPairGeneratorSpi.parameters.put(SLHDSAParameterSpec.slh_dsa_sha2_128s_with_sha256.getName(), SLHDSAParameters.sha2_128s_with_sha256);
        SLHDSAKeyPairGeneratorSpi.parameters.put(SLHDSAParameterSpec.slh_dsa_sha2_192f_with_sha512.getName(), SLHDSAParameters.sha2_192f_with_sha512);
        SLHDSAKeyPairGeneratorSpi.parameters.put(SLHDSAParameterSpec.slh_dsa_sha2_192s_with_sha512.getName(), SLHDSAParameters.sha2_192s_with_sha512);
        SLHDSAKeyPairGeneratorSpi.parameters.put(SLHDSAParameterSpec.slh_dsa_sha2_256f_with_sha512.getName(), SLHDSAParameters.sha2_256f_with_sha512);
        SLHDSAKeyPairGeneratorSpi.parameters.put(SLHDSAParameterSpec.slh_dsa_sha2_256s_with_sha512.getName(), SLHDSAParameters.sha2_256s_with_sha512);
        SLHDSAKeyPairGeneratorSpi.parameters.put(SLHDSAParameterSpec.slh_dsa_shake_128f_with_shake128.getName(), SLHDSAParameters.shake_128f_with_shake128);
        SLHDSAKeyPairGeneratorSpi.parameters.put(SLHDSAParameterSpec.slh_dsa_shake_128s_with_shake128.getName(), SLHDSAParameters.shake_128s_with_shake128);
        SLHDSAKeyPairGeneratorSpi.parameters.put(SLHDSAParameterSpec.slh_dsa_shake_192f_with_shake256.getName(), SLHDSAParameters.shake_192f_with_shake256);
        SLHDSAKeyPairGeneratorSpi.parameters.put(SLHDSAParameterSpec.slh_dsa_shake_192s_with_shake256.getName(), SLHDSAParameters.shake_192s_with_shake256);
        SLHDSAKeyPairGeneratorSpi.parameters.put(SLHDSAParameterSpec.slh_dsa_shake_256f_with_shake256.getName(), SLHDSAParameters.shake_256f_with_shake256);
        SLHDSAKeyPairGeneratorSpi.parameters.put(SLHDSAParameterSpec.slh_dsa_shake_256s_with_shake256.getName(), SLHDSAParameters.shake_256s_with_shake256);
    }
    
    public static class Hash extends SLHDSAKeyPairGeneratorSpi
    {
        public Hash() throws NoSuchAlgorithmException {
            super("HASH-SLH-DSA");
        }
    }
    
    public static class HashSha2_128f extends SLHDSAKeyPairGeneratorSpi
    {
        public HashSha2_128f() {
            super(SLHDSAParameterSpec.slh_dsa_sha2_128f_with_sha256);
        }
    }
    
    public static class HashSha2_128s extends SLHDSAKeyPairGeneratorSpi
    {
        public HashSha2_128s() {
            super(SLHDSAParameterSpec.slh_dsa_sha2_128s_with_sha256);
        }
    }
    
    public static class HashSha2_192f extends SLHDSAKeyPairGeneratorSpi
    {
        public HashSha2_192f() {
            super(SLHDSAParameterSpec.slh_dsa_sha2_192f_with_sha512);
        }
    }
    
    public static class HashSha2_192s extends SLHDSAKeyPairGeneratorSpi
    {
        public HashSha2_192s() {
            super(SLHDSAParameterSpec.slh_dsa_sha2_192s_with_sha512);
        }
    }
    
    public static class HashSha2_256f extends SLHDSAKeyPairGeneratorSpi
    {
        public HashSha2_256f() {
            super(SLHDSAParameterSpec.slh_dsa_sha2_256f_with_sha512);
        }
    }
    
    public static class HashSha2_256s extends SLHDSAKeyPairGeneratorSpi
    {
        public HashSha2_256s() {
            super(SLHDSAParameterSpec.slh_dsa_sha2_256s_with_sha512);
        }
    }
    
    public static class HashShake_128f extends SLHDSAKeyPairGeneratorSpi
    {
        public HashShake_128f() {
            super(SLHDSAParameterSpec.slh_dsa_shake_128f_with_shake128);
        }
    }
    
    public static class HashShake_128s extends SLHDSAKeyPairGeneratorSpi
    {
        public HashShake_128s() {
            super(SLHDSAParameterSpec.slh_dsa_shake_128s_with_shake128);
        }
    }
    
    public static class HashShake_192f extends SLHDSAKeyPairGeneratorSpi
    {
        public HashShake_192f() {
            super(SLHDSAParameterSpec.slh_dsa_shake_192f_with_shake256);
        }
    }
    
    public static class HashShake_192s extends SLHDSAKeyPairGeneratorSpi
    {
        public HashShake_192s() {
            super(SLHDSAParameterSpec.slh_dsa_shake_192s_with_shake256);
        }
    }
    
    public static class HashShake_256f extends SLHDSAKeyPairGeneratorSpi
    {
        public HashShake_256f() {
            super(SLHDSAParameterSpec.slh_dsa_shake_256f_with_shake256);
        }
    }
    
    public static class HashShake_256s extends SLHDSAKeyPairGeneratorSpi
    {
        public HashShake_256s() {
            super(SLHDSAParameterSpec.slh_dsa_shake_256s_with_shake256);
        }
    }
    
    public static class Pure extends SLHDSAKeyPairGeneratorSpi
    {
        public Pure() throws NoSuchAlgorithmException {
            super("SLH-DSA");
        }
    }
    
    public static class Sha2_128f extends SLHDSAKeyPairGeneratorSpi
    {
        public Sha2_128f() {
            super(SLHDSAParameterSpec.slh_dsa_sha2_128f);
        }
    }
    
    public static class Sha2_128s extends SLHDSAKeyPairGeneratorSpi
    {
        public Sha2_128s() {
            super(SLHDSAParameterSpec.slh_dsa_sha2_128s);
        }
    }
    
    public static class Sha2_192f extends SLHDSAKeyPairGeneratorSpi
    {
        public Sha2_192f() {
            super(SLHDSAParameterSpec.slh_dsa_sha2_192f);
        }
    }
    
    public static class Sha2_192s extends SLHDSAKeyPairGeneratorSpi
    {
        public Sha2_192s() {
            super(SLHDSAParameterSpec.slh_dsa_sha2_192s);
        }
    }
    
    public static class Sha2_256f extends SLHDSAKeyPairGeneratorSpi
    {
        public Sha2_256f() {
            super(SLHDSAParameterSpec.slh_dsa_sha2_256f);
        }
    }
    
    public static class Sha2_256s extends SLHDSAKeyPairGeneratorSpi
    {
        public Sha2_256s() {
            super(SLHDSAParameterSpec.slh_dsa_sha2_256s);
        }
    }
    
    public static class Shake_128f extends SLHDSAKeyPairGeneratorSpi
    {
        public Shake_128f() {
            super(SLHDSAParameterSpec.slh_dsa_shake_128f);
        }
    }
    
    public static class Shake_128s extends SLHDSAKeyPairGeneratorSpi
    {
        public Shake_128s() {
            super(SLHDSAParameterSpec.slh_dsa_shake_128s);
        }
    }
    
    public static class Shake_192f extends SLHDSAKeyPairGeneratorSpi
    {
        public Shake_192f() {
            super(SLHDSAParameterSpec.slh_dsa_shake_192f);
        }
    }
    
    public static class Shake_192s extends SLHDSAKeyPairGeneratorSpi
    {
        public Shake_192s() {
            super(SLHDSAParameterSpec.slh_dsa_shake_192s);
        }
    }
    
    public static class Shake_256f extends SLHDSAKeyPairGeneratorSpi
    {
        public Shake_256f() {
            super(SLHDSAParameterSpec.slh_dsa_shake_256f);
        }
    }
    
    public static class Shake_256s extends SLHDSAKeyPairGeneratorSpi
    {
        public Shake_256s() {
            super(SLHDSAParameterSpec.slh_dsa_shake_256s);
        }
    }
}
