Exemplo n.º 1
0
        /**
         * Decompresses a compressed point P = (xp, yp) (X9.62 s 4.2.2).
         *
         * @param yTilde
         *            ~yp, an indication bit for the decompression of yp.
         * @param X1
         *            The field element xp.
         * @return the decompressed point.
         */
        protected override ECPoint DecompressPoint(int yTilde, BigInteger X1)
        {
            ECFieldElement x = FromBigInteger(X1), y = null;

            if (x.IsZero)
            {
                y = B.Sqrt();
            }
            else
            {
                ECFieldElement beta = x.Square().Invert().Multiply(B).Add(A).Add(x);
                ECFieldElement z    = SolveQuadraticEquation(beta);
                if (z != null)
                {
                    if (z.TestBitZero() != (yTilde == 1))
                    {
                        z = z.AddOne();
                    }

                    switch (this.CoordinateSystem)
                    {
                    case COORD_LAMBDA_AFFINE:
                    case COORD_LAMBDA_PROJECTIVE:
                    {
                        y = z.Add(x);
                        break;
                    }

                    default:
                    {
                        y = z.Multiply(x);
                        break;
                    }
                    }
                }
            }

            if (y == null)
            {
                throw new ArgumentException("Invalid point compression");
            }

            return(this.CreateRawPoint(x, y, true));
        }
Exemplo n.º 2
0
    protected override ECPoint DecompressPoint(int yTilde, BigInteger X1)
    {
        ECFieldElement eCFieldElement  = FromBigInteger(X1);
        ECFieldElement eCFieldElement2 = null;

        if (eCFieldElement.IsZero)
        {
            eCFieldElement2 = B.Sqrt();
        }
        else
        {
            ECFieldElement beta = eCFieldElement.Square().Invert().Multiply(B)
                                  .Add(A)
                                  .Add(eCFieldElement);
            ECFieldElement eCFieldElement3 = SolveQuadradicEquation(beta);
            if (eCFieldElement3 != null)
            {
                if (eCFieldElement3.TestBitZero() != (yTilde == 1))
                {
                    eCFieldElement3 = eCFieldElement3.AddOne();
                }
                switch (CoordinateSystem)
                {
                case 5:
                case 6:
                    eCFieldElement2 = eCFieldElement3.Add(eCFieldElement);
                    break;

                default:
                    eCFieldElement2 = eCFieldElement3.Multiply(eCFieldElement);
                    break;
                }
            }
        }
        if (eCFieldElement2 == null)
        {
            throw new ArgumentException("Invalid point compression");
        }
        return(CreateRawPoint(eCFieldElement, eCFieldElement2, withCompression: true));
    }
Exemplo n.º 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));
        }
Exemplo n.º 4
0
        protected override ECPoint DecompressPoint(int yTilde, BigInteger X1)
        {
            ECFieldElement b = this.FromBigInteger(X1);
            ECFieldElement y = null;

            if (b.IsZero)
            {
                y = this.B.Sqrt();
            }
            else
            {
                ECFieldElement beta     = b.Square().Invert().Multiply(this.B).Add(this.A).Add(b);
                ECFieldElement element4 = this.SolveQuadraticEquation(beta);
                if (element4 != null)
                {
                    if (element4.TestBitZero() != (yTilde == 1))
                    {
                        element4 = element4.AddOne();
                    }
                    switch (this.CoordinateSystem)
                    {
                    case 5:
                    case 6:
                        y = element4.Add(b);
                        goto Label_00A9;
                    }
                    y = element4.Multiply(b);
                }
            }
Label_00A9:
            if (y == null)
            {
                throw new ArgumentException("Invalid point compression");
            }
            return(this.CreateRawPoint(b, y, true));
        }