Program: 52494
Project: 52494
Buggy source:
private void populateFromPrivKeyInfo(PrivateKeyInfo info) throws IOException {
  ASN1Primitive p=info.getPrivateKeyAlgorithm().getParameters().toASN1Primitive();
  if (p instanceof ASN1Sequence && (ASN1Sequence.getInstance(p).size() == 2 || ASN1Sequence.getInstance(p).size() == 3)) {
    gostParams=GOST3410PublicKeyAlgParameters.getInstance(info.getPrivateKeyAlgorithm().getParameters());
    ECNamedCurveParameterSpec spec=ECGOST3410NamedCurveTable.getParameterSpec(ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()));
    ECCurve curve=spec.getCurve();
    EllipticCurve ellipticCurve=EC5Util.convertCurve(curve,spec.getSeed());
    ecSpec=new ECNamedCurveSpec(ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()),ellipticCurve,new ECPoint(spec.getG().getAffineXCoord().toBigInteger(),spec.getG().getAffineYCoord().toBigInteger()),spec.getN(),spec.getH());
    ASN1Encodable privKey=info.parsePrivateKey();
    byte[] encVal=ASN1OctetString.getInstance(privKey).getOctets();
    byte[] dVal=new byte[encVal.length];
    for (int i=0; i != encVal.length; i++) {
      dVal[i]=encVal[encVal.length - 1 - i];
    }
    this.d=new BigInteger(1,dVal);
  }
 else {
    X962Parameters params=X962Parameters.getInstance(info.getPrivateKeyAlgorithm().getParameters());
    if (params.isNamedCurve()) {
      ASN1ObjectIdentifier oid=ASN1ObjectIdentifier.getInstance(params.getParameters());
      X9ECParameters ecP=ECUtil.getNamedCurveByOid(oid);
      if (ecP == null) {
        ECDomainParameters gParam=ECGOST3410NamedCurves.getByOID(oid);
        EllipticCurve ellipticCurve=EC5Util.convertCurve(gParam.getCurve(),gParam.getSeed());
        ecSpec=new ECNamedCurveSpec(ECGOST3410NamedCurves.getName(oid),ellipticCurve,new ECPoint(gParam.getG().getAffineXCoord().toBigInteger(),gParam.getG().getAffineYCoord().toBigInteger()),gParam.getN(),gParam.getH());
      }
 else {
        EllipticCurve ellipticCurve=EC5Util.convertCurve(ecP.getCurve(),ecP.getSeed());
        ecSpec=new ECNamedCurveSpec(ECUtil.getCurveName(oid),ellipticCurve,new ECPoint(ecP.getG().getAffineXCoord().toBigInteger(),ecP.getG().getAffineYCoord().toBigInteger()),ecP.getN(),ecP.getH());
      }
    }
 else     if (params.isImplicitlyCA()) {
      ecSpec=null;
    }
 else {
      X9ECParameters ecP=X9ECParameters.getInstance(params.getParameters());
      EllipticCurve ellipticCurve=EC5Util.convertCurve(ecP.getCurve(),ecP.getSeed());
      this.ecSpec=new ECParameterSpec(ellipticCurve,new ECPoint(ecP.getG().getAffineXCoord().toBigInteger(),ecP.getG().getAffineYCoord().toBigInteger()),ecP.getN(),ecP.getH().intValue());
    }
    ASN1Encodable privKey=info.parsePrivateKey();
    if (privKey instanceof ASN1Integer) {
      ASN1Integer derD=ASN1Integer.getInstance(privKey);
      this.d=derD.getValue();
    }
 else {
      org.bouncycastle.asn1.sec.ECPrivateKey ec=org.bouncycastle.asn1.sec.ECPrivateKey.getInstance(privKey);
      this.d=ec.getKey();
      this.publicKey=ec.getPublicKey();
    }
  }
}

Fixed version (ground truth):
private void populateFromPrivKeyInfo(PrivateKeyInfo info) throws IOException {
  ASN1Primitive p=info.getPrivateKeyAlgorithm().getParameters().toASN1Primitive();
  if (p instanceof ASN1Sequence && (ASN1Sequence.getInstance(p).size() == 2 || ASN1Sequence.getInstance(p).size() == 3)) {
    gostParams=GOST3410PublicKeyAlgParameters.getInstance(info.getPrivateKeyAlgorithm().getParameters());
    ECNamedCurveParameterSpec spec=ECGOST3410NamedCurveTable.getParameterSpec(ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()));
    ECCurve curve=spec.getCurve();
    EllipticCurve ellipticCurve=EC5Util.convertCurve(curve,spec.getSeed());
    ecSpec=new ECNamedCurveSpec(ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()),ellipticCurve,new ECPoint(spec.getG().getAffineXCoord().toBigInteger(),spec.getG().getAffineYCoord().toBigInteger()),spec.getN(),spec.getH());
    ASN1Encodable privKey=info.parsePrivateKey();
    if (privKey instanceof ASN1Integer) {
      this.d=ASN1Integer.getInstance(privKey).getPositiveValue();
    }
 else {
      byte[] encVal=ASN1OctetString.getInstance(privKey).getOctets();
      byte[] dVal=new byte[encVal.length];
      for (int i=0; i != encVal.length; i++) {
        dVal[i]=encVal[encVal.length - 1 - i];
      }
      this.d=new BigInteger(1,dVal);
    }
  }
 else {
    X962Parameters params=X962Parameters.getInstance(info.getPrivateKeyAlgorithm().getParameters());
    if (params.isNamedCurve()) {
      ASN1ObjectIdentifier oid=ASN1ObjectIdentifier.getInstance(params.getParameters());
      X9ECParameters ecP=ECUtil.getNamedCurveByOid(oid);
      if (ecP == null) {
        ECDomainParameters gParam=ECGOST3410NamedCurves.getByOID(oid);
        EllipticCurve ellipticCurve=EC5Util.convertCurve(gParam.getCurve(),gParam.getSeed());
        ecSpec=new ECNamedCurveSpec(ECGOST3410NamedCurves.getName(oid),ellipticCurve,new ECPoint(gParam.getG().getAffineXCoord().toBigInteger(),gParam.getG().getAffineYCoord().toBigInteger()),gParam.getN(),gParam.getH());
      }
 else {
        EllipticCurve ellipticCurve=EC5Util.convertCurve(ecP.getCurve(),ecP.getSeed());
        ecSpec=new ECNamedCurveSpec(ECUtil.getCurveName(oid),ellipticCurve,new ECPoint(ecP.getG().getAffineXCoord().toBigInteger(),ecP.getG().getAffineYCoord().toBigInteger()),ecP.getN(),ecP.getH());
      }
    }
 else     if (params.isImplicitlyCA()) {
      ecSpec=null;
    }
 else {
      X9ECParameters ecP=X9ECParameters.getInstance(params.getParameters());
      EllipticCurve ellipticCurve=EC5Util.convertCurve(ecP.getCurve(),ecP.getSeed());
      this.ecSpec=new ECParameterSpec(ellipticCurve,new ECPoint(ecP.getG().getAffineXCoord().toBigInteger(),ecP.getG().getAffineYCoord().toBigInteger()),ecP.getN(),ecP.getH().intValue());
    }
    ASN1Encodable privKey=info.parsePrivateKey();
    if (privKey instanceof ASN1Integer) {
      ASN1Integer derD=ASN1Integer.getInstance(privKey);
      this.d=derD.getValue();
    }
 else {
      org.bouncycastle.asn1.sec.ECPrivateKey ec=org.bouncycastle.asn1.sec.ECPrivateKey.getInstance(privKey);
      this.d=ec.getKey();
      this.publicKey=ec.getPublicKey();
    }
  }
}