private BouncyCastle.FpFieldElement GetX(
            byte[] input,
            BouncyCastle.FpCurve curve,
            int index,
            int counter)
        {
            int numIterations = (int)System.Math.Ceiling(
                (double)(curve.Q.BitLength / 8) / (double)hashByteSize);

            byte[] digest = new byte[numIterations * hashByteSize];

            for (int iteration = 0; iteration < numIterations; iteration++)
            {
                byte[] hashInput = ProtocolHelper.Concatenate(
                    input,
                    encoding.GetBytes(
                        index.ToString() + counter.ToString() + iteration.ToString()));
                hash.HashWithoutFormatting(hashInput);
                Array.Copy(hash.Digest, 0, digest, hashByteSize * iteration, hashByteSize);
            }

            BCBigInt x = new BCBigInt(1, digest).Mod(curve.Q);

            return(curve.FromBigInteger(x) as BouncyCastle.FpFieldElement);
        }