Program: 8446
Project: 8446
Buggy source:
public static PGPSecretKey createKey(int algorithmChoice,int keySize,String passPhrase) throws NoSuchAlgorithmException, PGPException, NoSuchProviderException, GeneralException, InvalidAlgorithmParameterException {
  if (keySize < 512) {
    throw new GeneralException("String_Node_Str");
  }
  Security.addProvider(new BouncyCastleProvider());
  if (passPhrase == null) {
    passPhrase="String_Node_Str";
  }
  int algorithm=0;
  KeyPairGenerator keyGen=null;
switch (algorithmChoice) {
case Id.choice.algorithm.dsa:
{
      keyGen=KeyPairGenerator.getInstance("String_Node_Str",new BouncyCastleProvider());
      keyGen.initialize(keySize,new SecureRandom());
      algorithm=PGPPublicKey.DSA;
      break;
    }
case Id.choice.algorithm.elgamal:
{
    if (keySize != 2048) {
      throw new GeneralException("String_Node_Str");
    }
    keyGen=KeyPairGenerator.getInstance("String_Node_Str",new BouncyCastleProvider());
    BigInteger p=new BigInteger("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str",16);
    ElGamalParameterSpec elParams=new ElGamalParameterSpec(p,new BigInteger("String_Node_Str"));
    keyGen.initialize(elParams);
    algorithm=PGPPublicKey.ELGAMAL_GENERAL;
    break;
  }
case Id.choice.algorithm.rsa:
{
  keyGen=KeyPairGenerator.getInstance("String_Node_Str",new BouncyCastleProvider());
  keyGen.initialize(keySize,new SecureRandom());
  algorithm=PGPPublicKey.RSA_GENERAL;
  break;
}
default :
{
throw new GeneralException("String_Node_Str");
}
}
PGPKeyPair keyPair=new PGPKeyPair(algorithm,keyGen.generateKeyPair(),new Date());
PGPSecretKey secretKey=new PGPSecretKey(PGPSignature.DEFAULT_CERTIFICATION,keyPair,"String_Node_Str",PGPEncryptedData.CAST5,passPhrase.toCharArray(),null,null,new SecureRandom(),new BouncyCastleProvider().getName());
return secretKey;
}

Fixed version (ground truth):
public static PGPSecretKey createKey(int algorithmChoice,int keySize,String passPhrase,PGPSecretKey masterKey) throws NoSuchAlgorithmException, PGPException, NoSuchProviderException, GeneralException, InvalidAlgorithmParameterException {
  if (keySize < 512) {
    throw new GeneralException("String_Node_Str");
  }
  Security.addProvider(new BouncyCastleProvider());
  if (passPhrase == null) {
    passPhrase="String_Node_Str";
  }
  int algorithm=0;
  KeyPairGenerator keyGen=null;
switch (algorithmChoice) {
case Id.choice.algorithm.dsa:
{
      keyGen=KeyPairGenerator.getInstance("String_Node_Str",new BouncyCastleProvider());
      keyGen.initialize(keySize,new SecureRandom());
      algorithm=PGPPublicKey.DSA;
      break;
    }
case Id.choice.algorithm.elgamal:
{
    if (masterKey == null) {
      throw new GeneralException("String_Node_Str");
    }
    keyGen=KeyPairGenerator.getInstance("String_Node_Str",new BouncyCastleProvider());
    BigInteger p=Primes.getBestPrime(keySize);
    BigInteger g=new BigInteger("String_Node_Str");
    ElGamalParameterSpec elParams=new ElGamalParameterSpec(p,g);
    keyGen.initialize(elParams);
    algorithm=PGPPublicKey.ELGAMAL_ENCRYPT;
    break;
  }
case Id.choice.algorithm.rsa:
{
  keyGen=KeyPairGenerator.getInstance("String_Node_Str",new BouncyCastleProvider());
  keyGen.initialize(keySize,new SecureRandom());
  algorithm=PGPPublicKey.RSA_GENERAL;
  break;
}
default :
{
throw new GeneralException("String_Node_Str");
}
}
PGPKeyPair keyPair=new PGPKeyPair(algorithm,keyGen.generateKeyPair(),new Date());
PGPSecretKey secretKey=null;
if (masterKey == null) {
secretKey=new PGPSecretKey(PGPSignature.DEFAULT_CERTIFICATION,keyPair,"String_Node_Str",PGPEncryptedData.CAST5,passPhrase.toCharArray(),null,null,new SecureRandom(),new BouncyCastleProvider().getName());
}
 else {
PGPPublicKey tmpKey=masterKey.getPublicKey();
PGPPublicKey masterPublicKey=new PGPPublicKey(tmpKey.getAlgorithm(),tmpKey.getKey(new BouncyCastleProvider()),tmpKey.getCreationTime());
PGPPrivateKey masterPrivateKey=masterKey.extractPrivateKey(passPhrase.toCharArray(),new BouncyCastleProvider());
PGPKeyPair masterKeyPair=new PGPKeyPair(masterPublicKey,masterPrivateKey);
PGPKeyRingGenerator ringGen=new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION,masterKeyPair,"String_Node_Str",PGPEncryptedData.CAST5,passPhrase.toCharArray(),null,null,new SecureRandom(),new BouncyCastleProvider().getName());
ringGen.addSubKey(keyPair);
PGPSecretKeyRing secKeyRing=ringGen.generateSecretKeyRing();
Iterator it=secKeyRing.getSecretKeys();
it.next();
secretKey=(PGPSecretKey)it.next();
}
return secretKey;
}