예제 #1
0
    private static void ge_p3_to_cached(ref ge_cached r, ge_p3 p)
    {
        ReadOnlySpan <int> d2 = stackalloc int[] { -21827239, -5839606, -30745221, 13898782, 229458, 15978800, -12551817, -6495438, 29715968, 9444199 };

        ge_cached result = new()
        {
            YminusX = stackalloc int[10],
            YplusX  = stackalloc int[10],
            T2d     = stackalloc int[10],
            Z       = stackalloc int[10],
        };

        r.YminusX.CopyTo(result.YminusX);
        r.YplusX.CopyTo(result.YplusX);
        r.T2d.CopyTo(result.T2d);
        r.Z.CopyTo(result.Z);

        fe_add(ref result.YplusX, p.Y, p.X);
        fe_sub(ref result.YminusX, p.Y, p.X);
        fe_copy(ref result.Z, p.Z);
        fe_mul(ref result.T2d, p.T, d2);

        result.YminusX.CopyTo(r.YminusX);
        result.YplusX.CopyTo(r.YplusX);
        result.T2d.CopyTo(r.T2d);
        result.Z.CopyTo(r.Z);
    }
예제 #2
0
    private static void ge_sub(ref ge_p1p1 r, ge_p3 p, ge_cached q)
    {
        Span <int> t0 = stackalloc int[10];

        ge_p1p1 result = new()
        {
            X = stackalloc int[10],
            Y = stackalloc int[10],
            Z = stackalloc int[10],
            T = stackalloc int[10],
        };

        r.X.CopyTo(result.X);
        r.Y.CopyTo(result.Y);
        r.Z.CopyTo(result.Z);
        r.T.CopyTo(result.T);

        fe_add(ref result.X, p.Y, p.X);
        fe_sub(ref result.Y, p.Y, p.X);
        fe_mul(ref result.Z, result.X, q.YminusX);
        fe_mul(ref result.Y, result.Y, q.YplusX);
        fe_mul(ref result.T, q.T2d, p.T);
        fe_mul(ref result.X, p.Z, q.Z);
        fe_add(ref t0, result.X, result.X);
        fe_sub(ref result.X, result.Z, result.Y);
        fe_add(ref result.Y, result.Z, result.Y);
        fe_sub(ref result.Z, t0, result.T);
        fe_add(ref result.T, t0, result.T);

        result.X.CopyTo(r.X);
        result.Y.CopyTo(r.Y);
        result.Z.CopyTo(r.Z);
        result.T.CopyTo(r.T);
    }