Ejemplo n.º 1
0
        /*
         *      r = p - q
         */

        private static void Msub(out GroupElementP1P1 r, ref GroupElementP3 p, ref GroupElementPreComp q)
        {
            FieldElement t0;

            /* qhasm: YpX1 = Y1+X1 */
            /* asm 1: Add(>YpX1=fe#1,<Y1=fe#12,<X1=fe#11); */
            /* asm 2: Add(>YpX1=r.X,<Y1=p.Y,<X1=p.X); */
            FieldOperations.Add(out r.X, ref p.Y, ref p.X);

            /* qhasm: YmX1 = Y1-X1 */
            /* asm 1: Subtract(>YmX1=fe#2,<Y1=fe#12,<X1=fe#11); */
            /* asm 2: Subtract(>YmX1=r.Y,<Y1=p.Y,<X1=p.X); */
            FieldOperations.Subtract(out r.Y, ref p.Y, ref p.X);

            /* qhasm: A = YpX1*ymx2 */
            /* asm 1: Multiplication(>A=fe#3,<YpX1=fe#1,<ymx2=fe#16); */
            /* asm 2: Multiplication(>A=r.Z,<YpX1=r.X,<ymx2=q.yminusx); */
            FieldOperations.Multiplication(out r.Z, ref r.X, ref q.yminusx);

            /* qhasm: B = YmX1*ypx2 */
            /* asm 1: Multiplication(>B=fe#2,<YmX1=fe#2,<ypx2=fe#15); */
            /* asm 2: Multiplication(>B=r.Y,<YmX1=r.Y,<ypx2=q.yplusx); */
            FieldOperations.Multiplication(out r.Y, ref r.Y, ref q.yplusx);

            /* qhasm: C = xy2d2*T1 */
            /* asm 1: Multiplication(>C=fe#4,<xy2d2=fe#17,<T1=fe#14); */
            /* asm 2: Multiplication(>C=r.T,<xy2d2=q.xy2d,<T1=p.T); */
            FieldOperations.Multiplication(out r.T, ref q.xy2d, ref p.T);

            /* qhasm: D = 2*Z1 */
            /* asm 1: Add(>D=fe#5,<Z1=fe#13,<Z1=fe#13); */
            /* asm 2: Add(>D=t0,<Z1=p.Z,<Z1=p.Z); */
            FieldOperations.Add(out t0, ref p.Z, ref p.Z);

            /* qhasm: X3 = A-B */
            /* asm 1: Subtract(>X3=fe#1,<A=fe#3,<B=fe#2); */
            /* asm 2: Subtract(>X3=r.X,<A=r.Z,<B=r.Y); */
            FieldOperations.Subtract(out r.X, ref r.Z, ref r.Y);

            /* qhasm: Y3 = A+B */
            /* asm 1: Add(>Y3=fe#2,<A=fe#3,<B=fe#2); */
            /* asm 2: Add(>Y3=r.Y,<A=r.Z,<B=r.Y); */
            FieldOperations.Add(out r.Y, ref r.Z, ref r.Y);

            /* qhasm: Z3 = D-C */
            /* asm 1: Subtract(>Z3=fe#3,<D=fe#5,<C=fe#4); */
            /* asm 2: Subtract(>Z3=r.Z,<D=t0,<C=r.T); */
            FieldOperations.Subtract(out r.Z, ref t0, ref r.T);

            /* qhasm: T3 = D+C */
            /* asm 1: Add(>T3=fe#4,<D=fe#5,<C=fe#4); */
            /* asm 2: Add(>T3=r.T,<D=t0,<C=r.T); */
            FieldOperations.Add(out r.T, ref t0, ref r.T);

            /* qhasm: return */
        }
Ejemplo n.º 2
0
        private static void Select(out GroupElementPreComp t, int pos, sbyte b)
        {
            GroupElementPreComp minust;
            byte bnegative = Negative(b);
            byte babs      = (byte)(b - ((-bnegative & b) << 1));

            ge_precomp_0(out t);
            GroupElementPreComp[] 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;
            FieldOperations.fe_neg(out minust.xy2d, ref t.xy2d);
            Cmov(ref t, ref minust, bnegative);
        }
        private static void Select(out GroupElementPreComp t, int pos, sbyte b)
        {
            GroupElementPreComp minust;
            var bnegative = Negative(b);
            var babs      = (byte)(b - ((-bnegative & b) << 1));

            ge_precomp_0(out t);
            var table = stellar_dotnet_sdk.chaos.nacl.Internal.Ed25519Ref10.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;
            stellar_dotnet_sdk.chaos.nacl.Internal.Ed25519Ref10.FieldOperations.fe_neg(out minust.xy2d, ref t.xy2d);
            Cmov(ref t, ref minust, bnegative);
        }
Ejemplo n.º 4
0
        /*
         * r = p - q
         */
        public static void ge_msub(out GroupElementP1P1 r, ref GroupElementP3 p, ref GroupElementPreComp q)
        {
            /* qhasm: enter ge_msub */

            /* qhasm: fe X1 */

            /* qhasm: fe Y1 */

            /* qhasm: fe Z1 */

            /* qhasm: fe T1 */

            /* qhasm: fe ypx2 */

            /* qhasm: fe ymx2 */

            /* qhasm: fe xy2d2 */

            /* qhasm: fe X3 */

            /* qhasm: fe Y3 */

            /* qhasm: fe Z3 */

            /* qhasm: fe T3 */

            /* qhasm: fe YpX1 */

            /* qhasm: fe YmX1 */

            /* qhasm: fe A */

            /* qhasm: fe B */

            /* qhasm: fe C */

            /* qhasm: fe D */

            /* qhasm: YpX1 = Y1+X1 */
            /* asm 1: fe_add(>YpX1=fe#1,<Y1=fe#12,<X1=fe#11); */
            /* asm 2: fe_add(>YpX1=r.X,<Y1=p.Y,<X1=p.X); */
            FieldOperations.fe_add(out r.X, ref p.Y, ref p.X);

            /* qhasm: YmX1 = Y1-X1 */
            /* asm 1: fe_sub(>YmX1=fe#2,<Y1=fe#12,<X1=fe#11); */
            /* asm 2: fe_sub(>YmX1=r.Y,<Y1=p.Y,<X1=p.X); */
            FieldOperations.fe_sub(out r.Y, ref p.Y, ref p.X);

            /* qhasm: A = YpX1*ymx2 */
            /* asm 1: fe_mul(>A=fe#3,<YpX1=fe#1,<ymx2=fe#16); */
            /* asm 2: fe_mul(>A=r.Z,<YpX1=r.X,<ymx2=q.yminusx); */
            FieldOperations.fe_mul(out r.Z, ref r.X, ref q.yminusx);

            /* qhasm: B = YmX1*ypx2 */
            /* asm 1: fe_mul(>B=fe#2,<YmX1=fe#2,<ypx2=fe#15); */
            /* asm 2: fe_mul(>B=r.Y,<YmX1=r.Y,<ypx2=q.yplusx); */
            FieldOperations.fe_mul(out r.Y, ref r.Y, ref q.yplusx);

            /* qhasm: C = xy2d2*T1 */
            /* asm 1: fe_mul(>C=fe#4,<xy2d2=fe#17,<T1=fe#14); */
            /* asm 2: fe_mul(>C=r.T,<xy2d2=q.xy2d,<T1=p.T); */
            FieldOperations.fe_mul(out r.T, ref q.xy2d, ref p.T);

            /* qhasm: D = 2*Z1 */
            /* asm 1: fe_add(>D=fe#5,<Z1=fe#13,<Z1=fe#13); */
            /* asm 2: fe_add(>D=t0,<Z1=p.Z,<Z1=p.Z); */
            FieldOperations.fe_add(out FieldElement t0, ref p.Z, ref p.Z);

            /* qhasm: X3 = A-B */
            /* asm 1: fe_sub(>X3=fe#1,<A=fe#3,<B=fe#2); */
            /* asm 2: fe_sub(>X3=r.X,<A=r.Z,<B=r.Y); */
            FieldOperations.fe_sub(out r.X, ref r.Z, ref r.Y);

            /* qhasm: Y3 = A+B */
            /* asm 1: fe_add(>Y3=fe#2,<A=fe#3,<B=fe#2); */
            /* asm 2: fe_add(>Y3=r.Y,<A=r.Z,<B=r.Y); */
            FieldOperations.fe_add(out r.Y, ref r.Z, ref r.Y);

            /* qhasm: Z3 = D-C */
            /* asm 1: fe_sub(>Z3=fe#3,<D=fe#5,<C=fe#4); */
            /* asm 2: fe_sub(>Z3=r.Z,<D=t0,<C=r.T); */
            FieldOperations.fe_sub(out r.Z, ref t0, ref r.T);

            /* qhasm: T3 = D+C */
            /* asm 1: fe_add(>T3=fe#4,<D=fe#5,<C=fe#4); */
            /* asm 2: fe_add(>T3=r.T,<D=t0,<C=r.T); */
            FieldOperations.fe_add(out r.T, ref t0, ref r.T);

            /* qhasm: return */
        }
Ejemplo n.º 5
0
 public static void ge_precomp_0(out GroupElementPreComp h)
 {
     FieldOperations.fe_1(out h.yplusx);
     FieldOperations.fe_1(out h.yminusx);
     FieldOperations.fe_0(out h.xy2d);
 }
Ejemplo n.º 6
0
 private static void Cmov(ref GroupElementPreComp t, ref GroupElementPreComp u, byte b)
 {
     FieldOperations.ConditionalMove(ref t.yplusx, ref u.yplusx, b);
     FieldOperations.ConditionalMove(ref t.yminusx, ref u.yminusx, b);
     FieldOperations.ConditionalMove(ref t.xy2d, ref u.xy2d, b);
 }
Ejemplo n.º 7
0
 private static void cmov(ref GroupElementPreComp t, ref GroupElementPreComp u, byte b)
 {
     FieldOperations.fe_cmov(ref t.yplusx, ref u.yplusx, b);
     FieldOperations.fe_cmov(ref t.yminusx, ref u.yminusx, b);
     FieldOperations.fe_cmov(ref t.xy2d, ref u.xy2d, b);
 }
Ejemplo n.º 8
0
 public static void ge_precomp_0(out GroupElementPreComp h)
 {
     stellar_dotnet_sdk.chaos.nacl.Internal.Ed25519Ref10.FieldOperations.fe_1(out h.yplusx);
     stellar_dotnet_sdk.chaos.nacl.Internal.Ed25519Ref10.FieldOperations.fe_1(out h.yminusx);
     stellar_dotnet_sdk.chaos.nacl.Internal.Ed25519Ref10.FieldOperations.fe_0(out h.xy2d);
 }
Ejemplo n.º 9
0
 private static void GetPreComp(out GroupElementPreComp h)
 {
     FieldOperations.FieldOperations_1(out h.yplusx);
     FieldOperations.FieldOperations_1(out h.yminusx);
     FieldOperations.FieldOperations_0(out h.xy2d);
 }
 private static void Cmov(ref GroupElementPreComp t, ref GroupElementPreComp u, byte b)
 {
     stellar_dotnet_sdk.chaos.nacl.Internal.Ed25519Ref10.FieldOperations.fe_cmov(ref t.yplusx, ref u.yplusx, b);
     stellar_dotnet_sdk.chaos.nacl.Internal.Ed25519Ref10.FieldOperations.fe_cmov(ref t.yminusx, ref u.yminusx, b);
     stellar_dotnet_sdk.chaos.nacl.Internal.Ed25519Ref10.FieldOperations.fe_cmov(ref t.xy2d, ref u.xy2d, b);
 }