Beispiel #1
0
        public static FpPoint GetRandomPoint(string input, FpCurve curve, int index, Formatter formater, out int finalCounter)
        {
            int            counter = 0;
            ECFieldElement x = null, y = null, z = null;

            while (y == null)
            {
                x = GetX(input, curve, index, counter);
                z = x.Multiply(x.Square().Add(curve.A)).Add(curve.B);
                if (z.ToBigInteger() == BigInteger.Zero)
                {
                    y = z;
                }
                else
                {
                    y = z.Sqrt(); // returns null if sqrt does not exist
                }
                counter++;
            }
            finalCounter = counter - 1;
            if (formater != null)
            {
                formater.PrintBigInteger("vr_z", "UCAHR", null, z.ToBigInteger());
            }
            ECFieldElement yPrime = y.Negate();

            return(new FpPoint(curve, x, y.ToBigInteger().CompareTo(yPrime.ToBigInteger()) < 0 ? y : yPrime));
        }
Beispiel #2
0
    protected override ECPoint DecompressPoint(int yTilde, BigInteger X1)
    {
        ECFieldElement eCFieldElement  = FromBigInteger(X1);
        ECFieldElement eCFieldElement2 = eCFieldElement.Square().Add(A).Multiply(eCFieldElement)
                                         .Add(B);
        ECFieldElement eCFieldElement3 = eCFieldElement2.Sqrt();

        if (eCFieldElement3 == null)
        {
            throw new ArgumentException("Invalid point compression");
        }
        if (eCFieldElement3.TestBitZero() != (yTilde == 1))
        {
            eCFieldElement3 = eCFieldElement3.Negate();
        }
        return(CreateRawPoint(eCFieldElement, eCFieldElement3, withCompression: true));
    }
Beispiel #3
0
        protected override ECPoint DecompressPoint(int yTilde, BigInteger X1)
        {
            ECFieldElement x     = FromBigInteger(X1);
            ECFieldElement alpha = x.Square().Add(A).Multiply(x).Add(B);
            ECFieldElement beta  = alpha.Sqrt();

            //
            // if we can't find a sqrt we haven't got a point on the
            // curve - run!
            //
            if (beta == null)
            {
                throw new ArithmeticException("Invalid point compression");
            }

            if (beta.TestBitZero() != (yTilde == 1))
            {
                // Use the other root
                beta = beta.Negate();
            }

            return(new SecP521R1Point(this, x, beta, true));
        }