Esempio n. 1
0
        private static GroupElementP4 Select(int pos, sbyte b)
        {
            GroupElementP4 t;

            GroupElementP4 minust;
            var            bnegative = Negative(b);
            var            babs      = (byte)(b - ((-bnegative & b) << 1));

            t = new GroupElementP4
            {
                YplusX  = FieldElementOperations.Set1(),
                YminusX = FieldElementOperations.Set1(),
                XY2D    = FieldElementOperations.Set0()
            };

            var table = LookupTables.Base[pos];

            Cmov(ref t, ref table[0], Equal(babs, 1));
            Cmov(ref t, ref table[1], Equal(babs, 2));
            Cmov(ref t, ref table[2], Equal(babs, 3));
            Cmov(ref t, ref table[3], Equal(babs, 4));
            Cmov(ref t, ref table[4], Equal(babs, 5));
            Cmov(ref t, ref table[5], Equal(babs, 6));
            Cmov(ref t, ref table[6], Equal(babs, 7));
            Cmov(ref t, ref table[7], Equal(babs, 8));
            minust.YplusX  = t.YminusX;
            minust.YminusX = t.YplusX;
            minust.XY2D    = FieldElementOperations.Negate(ref t.XY2D);
            Cmov(ref t, ref minust, bnegative);

            return(t);
        }
Esempio n. 2
0
        private static GroupElementP1 Madd(ref GroupElementP3 p, ref GroupElementP4 q)
        {
            var t0 = FieldElementOperations.Add(ref p.Z, ref p.Z);             /* D = 2*Z1 */
            var r  = new GroupElementP1();

            /* YpX1 = Y1+X1 */
            r.X = FieldElementOperations.Add(ref p.Y, ref p.X);

            /* YmX1 = Y1-X1 */
            r.Y = FieldElementOperations.Sub(ref p.Y, ref p.X);

            /* A = YpX1*ypx2 */
            r.Z = FieldElementOperations.Multiplication(ref r.X, ref q.YplusX);

            /* B = YmX1*ymx2 */
            r.Y = FieldElementOperations.Multiplication(ref r.Y, ref q.YminusX);

            /* C = xy2d2*T1 */
            r.T = FieldElementOperations.Multiplication(ref q.XY2D, ref p.T);

            /* X3 = A-B */
            r.X = FieldElementOperations.Sub(ref r.Z, ref r.Y);

            /* Y3 = A+B */
            r.Y = FieldElementOperations.Add(ref r.Z, ref r.Y);

            /* Z3 = D+C */
            r.Z = FieldElementOperations.Add(ref t0, ref r.T);

            /* T3 = D-C */
            r.T = FieldElementOperations.Sub(ref t0, ref r.T);

            return(r);
        }
Esempio n. 3
0
 private static void Cmov(ref GroupElementP4 t, ref GroupElementP4 u, byte b)
 {
     FieldElementOperations.Mov(ref t.YplusX, ref u.YplusX, b);
     FieldElementOperations.Mov(ref t.YminusX, ref u.YminusX, b);
     FieldElementOperations.Mov(ref t.XY2D, ref u.XY2D, b);
 }