示例#1
0
        private static void EncodePoint(PointExt p, byte[] r, int rOff)
        {
            uint[] x = X448Field.Create();
            uint[] y = X448Field.Create();

            X448Field.Inv(p.z, y);
            X448Field.Mul(p.x, y, x);
            X448Field.Mul(p.y, y, y);
            X448Field.Normalize(x);
            X448Field.Normalize(y);

            X448Field.Encode(y, r, rOff);
            r[rOff + PointBytes - 1] = (byte)((x[0] & 1) << 7);
        }
示例#2
0
        private static int CheckPoint(uint[] x, uint[] y)
        {
            uint[] t = X448Field.Create();
            uint[] u = X448Field.Create();
            uint[] v = X448Field.Create();

            X448Field.Sqr(x, u);
            X448Field.Sqr(y, v);
            X448Field.Mul(u, v, t);
            X448Field.Add(u, v, u);
            X448Field.Mul(t, -C_d, t);
            X448Field.SubOne(t);
            X448Field.Add(t, u, t);
            X448Field.Normalize(t);

            return(X448Field.IsZero(t));
        }
示例#3
0
        private static bool DecodePointVar(byte[] p, int pOff, bool negate, PointExt r)
        {
            byte[] py = Arrays.CopyOfRange(p, pOff, pOff + PointBytes);
            if (!CheckPointVar(py))
            {
                return(false);
            }

            int x_0 = (py[PointBytes - 1] & 0x80) >> 7;

            py[PointBytes - 1] &= 0x7F;

            X448Field.Decode(py, 0, r.y);

            uint[] u = X448Field.Create();
            uint[] v = X448Field.Create();

            X448Field.Sqr(r.y, u);
            X448Field.Mul(u, (uint)-C_d, v);
            X448Field.Negate(u, u);
            X448Field.AddOne(u);
            X448Field.AddOne(v);

            if (!X448Field.SqrtRatioVar(u, v, r.x))
            {
                return(false);
            }

            X448Field.Normalize(r.x);
            if (x_0 == 1 && X448Field.IsZeroVar(r.x))
            {
                return(false);
            }

            if (negate ^ (x_0 != (r.x[0] & 1)))
            {
                X448Field.Negate(r.x, r.x);
            }

            PointExtendXY(r);
            return(true);
        }