Ejemplo n.º 1
0
    /// <summary>
    /// Ms the game order_ on your turn begin.
    /// когда ход игрока, игрок выбирает клетку для атаки
    /// и x, y отправляется другому игроку
    /// </summary>
    void mGameOrder_OnYourTurnBegin()
    {
        FieldOperations field = mGameOrder.EnemyField.GetComponent <FieldOperations>();

        field.SelectAim((x, y) =>
        {
            bool res = false;
            mGameOrder.AddTask(1.0f, () =>
            {
                res = field.AttackCell(x, y);
                if (GameOptions.Instance.Server)
                {
                    SendAttackCell(x, y);
                }
                else
                {
                    SendAttackCell(x, y);
                }
            });
            mGameOrder.AddTask(1.0f, () =>
            {
                mGameOrder.EndTurn(res);
            });
        });
    }
Ejemplo n.º 2
0
 private static void GetP3(out GroupElementP3 h)
 {
     FieldOperations.FieldOperations_0(out h.X);
     FieldOperations.FieldOperations_1(out h.Y);
     FieldOperations.FieldOperations_1(out h.Z);
     FieldOperations.FieldOperations_0(out h.T);
 }
Ejemplo n.º 3
0
    /// <summary>
    /// Gets the possible poitions.
    /// определение списка возможных позиций для корабля типа type на поле
    /// </summary>
    /// <returns>The possible poitions.</returns>
    /// <param name="type">Type.</param>
    private List <ShipPos> GetPossiblePoitions(int type)
    {
        List <ShipPos>  pos   = new List <ShipPos>();
        FieldOperations field = mGameOrder.EnemyField.GetComponent <FieldOperations>();

        for (int i = 0; i < FieldOperations.FieldsHorCount; ++i)
        {
            for (int j = 0; j < FieldOperations.FieldsVerCount; ++j)
            {
                int len = Ship.GetShipLength((Ship.Type)type);

                for (int k = 0; k < 2; ++k)
                {
                    bool hor = ((k == 0) ? true : false);

                    if (field.isPossibleShipPos(len, hor, i, j))
                    {
                        pos.Add(new ShipPos {
                            X = i, Y = j, Horizontal = hor
                        });
                    }
                }
            }
        }

        return(pos);
    }
Ejemplo n.º 4
0
 internal static void ge_p3_0(out GroupElementP3 h)
 {
     FieldOperations.fe_0(out h.X);
     FieldOperations.fe_1(out h.Y);
     FieldOperations.fe_1(out h.Z);
     FieldOperations.fe_0(out h.T);
 }
Ejemplo n.º 5
0
        /*
         *      r = p
         */

        private static void P3ToCached(out GroupElementCached r, ref GroupElementP3 p)
        {
            FieldOperations.Add(out r.YplusX, ref p.Y, ref p.X);
            FieldOperations.Subtract(out r.YminusX, ref p.Y, ref p.X);
            r.Z = p.Z;
            FieldOperations.Multiplication(out r.T2d, ref p.T, ref LookupTables.D2);
        }
Ejemplo n.º 6
0
        public ActionResult Create([Bind(Include = "FieldOperationsId,TechApproval,PerDiemAdvance,TechApprovalADV,status,CertificatesStatus,RejectionComment,ARejectionComment,TechId,PurchaseOrderId")] FieldOperations fieldOperations, int ContractId)
        {
            if (ModelState.IsValid)
            {
                fieldOperations.status             = "PENDING APPROVAL";
                fieldOperations.CertificatesStatus = "NO SENDING";
                fieldOperations.TechApprovalADV    = "PROCESSING";
                db.FieldOperations.Add(fieldOperations);
                db.SaveChanges();

                var tech = db.Teches.Find(fieldOperations.TechId);
                tech.Status          = "PENDING APPROVAL";
                db.Entry(tech).State = EntityState.Modified;
                db.SaveChanges();


                return(RedirectToAction("Create", "FieldOperations", new { id = fieldOperations.PurchaseOrderId, ContractId = ContractId }));
            }

            ViewBag.ContractId      = ContractId;
            ViewBag.PurchaseOrderId = fieldOperations.PurchaseOrderId;

            ViewBag.TechId = new SelectList(db.Teches.Where(c => c.Status == "BANCH"), "TechId", "FullName");
            return(View(fieldOperations));
        }
Ejemplo n.º 7
0
        public static void GetPublicKey(ArraySegment <byte> publicKey, ArraySegment <byte> privateKey)
        {
            if (publicKey.Array == null)
            {
                throw new ArgumentNullException("publicKey.Array");
            }
            if (privateKey.Array == null)
            {
                throw new ArgumentNullException("privateKey.Array");
            }
            if (publicKey.Count != PublicKeySizeInBytes)
            {
                throw new ArgumentException("privateKey.Count must be 32");
            }
            if (privateKey.Count != PrivateKeySizeInBytes)
            {
                throw new ArgumentException("privateKey.Count must be 32");
            }

            // hack: abusing publicKey as temporary storage
            // todo: remove hack
            for (int i = 0; i < 32; i++)
            {
                publicKey.Array[publicKey.Offset + i] = privateKey.Array[privateKey.Offset + i];
            }
            ScalarOperations.sc_clamp(publicKey.Array, publicKey.Offset);

            GroupElementP3 A;

            GroupOperations.ge_scalarmult_base(out A, publicKey.Array, publicKey.Offset);
            FieldElement publicKeyFE;

            EdwardsToMontgomeryX(out publicKeyFE, ref A.Y, ref A.Z);
            FieldOperations.fe_tobytes(publicKey.Array, publicKey.Offset, ref publicKeyFE);
        }
Ejemplo n.º 8
0
        /*
         *      r = p
         */

        private static void P1P1ConvertToP3(out GroupElementP3 r, ref GroupElementP1P1 p)
        {
            FieldOperations.Multiplication(out r.X, ref p.X, ref p.T);
            FieldOperations.Multiplication(out r.Y, ref p.Y, ref p.Z);
            FieldOperations.Multiplication(out r.Z, ref p.Z, ref p.T);
            FieldOperations.Multiplication(out r.T, ref p.X, ref p.Y);
        }
Ejemplo n.º 9
0
 /*
  *      r = p
  */
 internal static void ge_p1p1_to_p3(out GroupElementP3 r, ref GroupElementP1P1 p)
 {
     FieldOperations.fe_mul(out r.X, ref p.X, ref p.T);
     FieldOperations.fe_mul(out r.Y, ref p.Y, ref p.Z);
     FieldOperations.fe_mul(out r.Z, ref p.Z, ref p.T);
     FieldOperations.fe_mul(out r.T, ref p.X, ref p.Y);
 }
Ejemplo n.º 10
0
 /*
  * r = p
  */
 internal static void ge_p3_to_cached(out GroupElementCached r, ref GroupElementP3 p)
 {
     FieldOperations.fe_add(out r.YplusX, ref p.Y, ref p.X);
     FieldOperations.fe_sub(out r.YminusX, ref p.Y, ref p.X);
     r.Z = p.Z;
     FieldOperations.fe_mul(out r.T2d, ref p.T, ref LookupTables.d2);
 }
Ejemplo n.º 11
0
        /*
         *      r = p - q
         */

        private static void Subtract(out GroupElementP1P1 r, ref GroupElementP3 p, ref GroupElementCached q)
        {
            /* 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 = T2d2*T1 */
            /* asm 1: Multiplication(>C=fe#4,<T2d2=fe#18,<T1=fe#14); */
            /* asm 2: Multiplication(>C=r.T,<T2d2=q.T2d,<T1=p.T); */
            FieldOperations.Multiplication(out r.T, ref q.T2d, ref p.T);

            /* qhasm: ZZ = Z1*Z2 */
            /* asm 1: Multiplication(>ZZ=fe#1,<Z1=fe#13,<Z2=fe#17); */
            /* asm 2: Multiplication(>ZZ=r.X,<Z1=p.Z,<Z2=q.Z); */
            FieldOperations.Multiplication(out r.X, ref p.Z, ref q.Z);

            /* qhasm: D = 2*ZZ */
            /* asm 1: Add(>D=fe#5,<ZZ=fe#1,<ZZ=fe#1); */
            /* asm 2: Add(>D=t0,<ZZ=r.X,<ZZ=r.X); */
            FieldOperations.Add(out var t0, ref r.X, ref r.X);

            /* 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.º 12
0
 public static void GeToBytes(byte[] s, int offset, ref GroupElementP2 h)
 {
     FieldOperations.fe_invert(out FieldElement recip, ref h.Z);
     FieldOperations.fe_mul(out FieldElement x, ref h.X, ref recip);
     FieldOperations.fe_mul(out FieldElement y, ref h.Y, ref recip);
     FieldOperations.fe_tobytes(s, offset, ref y);
     s[offset + 31] ^= (byte)(FieldOperations.fe_isnegative(ref x) << 7);
 }
Ejemplo n.º 13
0
 public static void ToBytes(byte[] s, int offset, ref GroupElementP2 h)
 {
     FieldOperations.Invert(out var recip, ref h.Z);
     FieldOperations.Multiplication(out var x, ref h.X, ref recip);
     FieldOperations.Multiplication(out var y, ref h.Y, ref recip);
     FieldOperations.ToBytes(s, offset, ref y);
     s[offset + 31] ^= (byte)(FieldOperations.IsNegative(ref x) << 7);
 }
Ejemplo n.º 14
0
    public void ReceivedAttackCell(int x, int y)
    {
        FieldOperations field = mGameOrder.PlayerField.GetComponent <FieldOperations>();
        bool            res   = false;

        res = field.AttackCell(x, y);
        mGameOrder.EndTurn(res);
    }
Ejemplo n.º 15
0
 internal static void EdwardsToMontgomeryX(out FieldElement montgomeryX, ref FieldElement edwardsY, ref FieldElement edwardsZ)
 {
     FieldElement tempX, tempZ;
     FieldOperations.fe_add(out tempX, ref edwardsZ, ref edwardsY);
     FieldOperations.fe_sub(out tempZ, ref edwardsZ, ref edwardsY);
     FieldOperations.fe_invert(out tempZ, ref tempZ);
     FieldOperations.fe_mul(out montgomeryX, ref tempX, ref tempZ);
 }
Ejemplo n.º 16
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.º 17
0
        internal static void MontgomeryXToEdwards(out FieldElement edwardsY, ref FieldElement montgomeryX, ref FieldElement montgomeryZ)
        {
            // edwardsY = (montgomeryX - montgomeryZ) / (montgomeryX + montgomeryZ)
            FieldElement tempY, tempZ;

            FieldOperations.fe_sub(out tempY, ref montgomeryX, ref montgomeryZ);
            FieldOperations.fe_add(out tempZ, ref montgomeryX, ref montgomeryZ);
            FieldOperations.fe_invert(out tempZ, ref tempZ);
            FieldOperations.fe_mul(out edwardsY, ref tempY, ref tempZ);
        }
Ejemplo n.º 18
0
        public static void EdwardsToMontgomery(ArraySegment <byte> montgomery, ArraySegment <byte> edwards)
        {
            FieldElement edwardsY, edwardsZ, montgomeryX;

            FieldOperations.fe_frombytes(out edwardsY, edwards.Array, edwards.Offset);
            FieldOperations.fe_1(out edwardsZ);
            EdwardsToMontgomeryX(out montgomeryX, ref edwardsY, ref edwardsZ);
            FieldOperations.fe_tobytes(montgomery.Array, montgomery.Offset, ref montgomeryX);
            montgomery.Array[montgomery.Offset + 31] |= (byte)(edwards.Array[edwards.Offset + 31] & 0x80);// copy sign
        }
Ejemplo n.º 19
0
        public static void MontgomeryToEdwards(ArraySegment <byte> edwards, ArraySegment <byte> montgomery)
        {
            FieldElement montgomeryX, montgomeryZ, edwardsY;

            FieldOperations.fe_frombytes(out montgomeryX, montgomery.Array, montgomery.Offset);
            FieldOperations.fe_1(out montgomeryZ);
            MontgomeryXToEdwards(out edwardsY, ref montgomeryX, ref montgomeryZ);
            FieldOperations.fe_tobytes(edwards.Array, edwards.Offset, ref edwardsY);
            edwards.Array[edwards.Offset + 31] |= (byte)(montgomery.Array[montgomery.Offset + 31] & 0x80);// copy sign
        }
Ejemplo n.º 20
0
        public static void ScalarMult(
            byte[] q, int qoffset,
            byte[] n, int noffset,
            byte[] p, int poffset)
        {
            FieldElement p0, q0;

            FieldOperations.FromBytes2(out p0, p, poffset);
            ScalarMult(out q0, n, noffset, ref p0);
            FieldOperations.ToBytes(q, qoffset, ref q0);
        }
Ejemplo n.º 21
0
    /// <summary>
    /// Attacks the random side.
    /// атака случайно вверх, вниз, влево, вправо
    /// от клетки i, j
    /// </summary>
    /// <returns><c>true</c>, if random side was attacked, <c>false</c> otherwise.</returns>
    /// <param name="i">The index.</param>
    /// <param name="j">J.</param>
    /// <param name="x">The x coordinate.</param>
    /// <param name="y">The y coordinate.</param>
    private bool AttackRandomSide(int i, int j, out int x, out int y)
    {
        FieldOperations field = mGameOrder.PlayerField.GetComponent <FieldOperations>();

        // просчет возможных вариантов для атаки
        bool possible_left   = (i > 0) && !field.isCellAttacked(i - 1, j);
        bool possible_top    = (j > 0) && !field.isCellAttacked(i, j - 1);
        bool possible_right  = (i < FieldOperations.FieldsHorCount - 1) && !field.isCellAttacked(i + 1, j);
        bool possible_bottom = (j < FieldOperations.FieldsVerCount - 1) && !field.isCellAttacked(i, j + 1);

        List <AimPos> aims = new List <AimPos>();

        if (possible_left)
        {
            aims.Add(new AimPos {
                X = i - 1, Y = j
            });
        }

        if (possible_top)
        {
            aims.Add(new AimPos {
                X = i, Y = j - 1
            });
        }

        if (possible_right)
        {
            aims.Add(new AimPos {
                X = i + 1, Y = j
            });
        }

        if (possible_bottom)
        {
            aims.Add(new AimPos {
                X = i, Y = j + 1
            });
        }

        if (aims.Count == 0)
        {
            x = 0;
            y = 0;
            return(false);
        }

        // из возможных целей, выбирается одна случайно
        int num = Random.Range(0, aims.Count);

        x = aims[num].X;
        y = aims[num].Y;
        return(true);
    }
Ejemplo n.º 22
0
        internal static void ge_p3_tobytes(byte[] s, int offset, ref GroupElementP3 h)
        {
            FieldElement recip;
            FieldElement x;
            FieldElement y;

            FieldOperations.fe_invert(out recip, ref h.Z);
            FieldOperations.fe_mul(out x, ref h.X, ref recip);
            FieldOperations.fe_mul(out y, ref h.Y, ref recip);
            FieldOperations.fe_tobytes(s, offset, ref y);
            s[offset + 31] ^= (byte)(FieldOperations.fe_isnegative(ref x) << 7);
        }
Ejemplo n.º 23
0
        public static void scalarmult(
            byte[] q, int qoffset,
            byte[] n, int noffset,
            byte[] p, int poffset)
        {
            FieldElement p0;
            FieldElement q0;

            FieldOperations.fe_frombytes2(out p0, p, poffset);
            scalarmult(out q0, n, noffset, ref p0);
            FieldOperations.fe_tobytes(q, qoffset, ref q0);
        }
Ejemplo n.º 24
0
        /*
         *      r = 2 * p
         */

        private static void GetP2Dbl(out GroupElementP1P1 r, ref GroupElementP2 p)
        {
            FieldElement t0;

            /* qhasm: XX=X1^2 */
            /* asm 1: Square(>XX=fe#1,<X1=fe#11); */
            /* asm 2: Square(>XX=r.X,<X1=p.X); */
            FieldOperations.Square(out r.X, ref p.X);

            /* qhasm: YY=Y1^2 */
            /* asm 1: Square(>YY=fe#3,<Y1=fe#12); */
            /* asm 2: Square(>YY=r.Z,<Y1=p.Y); */
            FieldOperations.Square(out r.Z, ref p.Y);

            /* qhasm: B=2*Z1^2 */
            /* asm 1: Square2(>B=fe#4,<Z1=fe#13); */
            /* asm 2: Square2(>B=r.T,<Z1=p.Z); */
            FieldOperations.Square2(out r.T, ref p.Z);

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

            /* qhasm: AA=A^2 */
            /* asm 1: Square(>AA=fe#5,<A=fe#2); */
            /* asm 2: Square(>AA=t0,<A=r.Y); */
            FieldOperations.Square(out t0, ref r.Y);

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

            /* qhasm: Z3=YY-XX */
            /* asm 1: Subtract(>Z3=fe#3,<YY=fe#3,<XX=fe#1); */
            /* asm 2: Subtract(>Z3=r.Z,<YY=r.Z,<XX=r.X); */
            FieldOperations.Subtract(out r.Z, ref r.Z, ref r.X);

            /* qhasm: X3=AA-Y3 */
            /* asm 1: Subtract(>X3=fe#1,<AA=fe#5,<Y3=fe#2); */
            /* asm 2: Subtract(>X3=r.X,<AA=t0,<Y3=r.Y); */
            FieldOperations.Subtract(out r.X, ref t0, ref r.Y);

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

            /* qhasm: return */
        }
Ejemplo n.º 25
0
        /*
         * r = 2 * p
         */

        public static void ge_p2_dbl(out GroupElementP1P1 r, ref GroupElementP2 p)
        {
            FieldElement t0;

            /* qhasm: XX=X1^2 */
            /* asm 1: fe_sq(>XX=fe#1,<X1=fe#11); */
            /* asm 2: fe_sq(>XX=r.X,<X1=p.X); */
            FieldOperations.fe_sq(out r.X, ref p.X);

            /* qhasm: YY=Y1^2 */
            /* asm 1: fe_sq(>YY=fe#3,<Y1=fe#12); */
            /* asm 2: fe_sq(>YY=r.Z,<Y1=p.Y); */
            FieldOperations.fe_sq(out r.Z, ref p.Y);

            /* qhasm: B=2*Z1^2 */
            /* asm 1: fe_sq2(>B=fe#4,<Z1=fe#13); */
            /* asm 2: fe_sq2(>B=r.T,<Z1=p.Z); */
            FieldOperations.fe_sq2(out r.T, ref p.Z);

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

            /* qhasm: AA=A^2 */
            /* asm 1: fe_sq(>AA=fe#5,<A=fe#2); */
            /* asm 2: fe_sq(>AA=t0,<A=r.Y); */
            FieldOperations.fe_sq(out t0, ref r.Y);

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

            /* qhasm: Z3=YY-XX */
            /* asm 1: fe_sub(>Z3=fe#3,<YY=fe#3,<XX=fe#1); */
            /* asm 2: fe_sub(>Z3=r.Z,<YY=r.Z,<XX=r.X); */
            FieldOperations.fe_sub(out r.Z, ref r.Z, ref r.X);

            /* qhasm: X3=AA-Y3 */
            /* asm 1: fe_sub(>X3=fe#1,<AA=fe#5,<Y3=fe#2); */
            /* asm 2: fe_sub(>X3=r.X,<AA=t0,<Y3=r.Y); */
            FieldOperations.fe_sub(out r.X, ref t0, ref r.Y);

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

            /* qhasm: return */
        }
Ejemplo n.º 26
0
        public static void KeyExchange(ArraySegment <byte> sharedKey, ArraySegment <byte> publicKey, ArraySegment <byte> privateKey, bool naclCompat = false)
        {
            if (sharedKey.Array == null)
            {
                throw new ArgumentNullException("sharedKey.Array");
            }
            if (publicKey.Array == null)
            {
                throw new ArgumentNullException("publicKey.Array");
            }
            if (privateKey.Array == null)
            {
                throw new ArgumentNullException("privateKey");
            }
            if (sharedKey.Count != SharedKeySizeInBytes)
            {
                throw new ArgumentException("sharedKey.Count != 32");
            }
            if (publicKey.Count != PublicKeySizeInBytes)
            {
                throw new ArgumentException("publicKey.Count != 32");
            }
            if (privateKey.Count != ExpandedPrivateKeySizeInBytes)
            {
                throw new ArgumentException("privateKey.Count != 64");
            }

            FieldElement montgomeryX, edwardsY, edwardsZ, sharedMontgomeryX;

            FieldOperations.fe_frombytes(out edwardsY, publicKey.Array, publicKey.Offset);
            FieldOperations.fe_1(out edwardsZ);
            Curve25519.EdwardsToMontgomeryX(out montgomeryX, ref edwardsY, ref edwardsZ);

            IHash hasher = AuthenticatorFactory.CreateHashPrimitive(HashFunction.Sha512);

            hasher.BlockUpdate(privateKey.Array, privateKey.Offset, 32);
            byte[] h = new byte[64];
            hasher.DoFinal(h, 0);
            ScalarOperations.sc_clamp(h, 0);
            MontgomeryOperations.scalarmult(out sharedMontgomeryX, h, 0, ref montgomeryX);
            h.SecureWipe();
            FieldOperations.fe_tobytes(sharedKey.Array, sharedKey.Offset, ref sharedMontgomeryX);

            if (naclCompat)
            {
                Curve25519.KeyExchangeOutputHashNaCl(sharedKey.Array, sharedKey.Offset);
            }
        }
Ejemplo n.º 27
0
        // GET: FieldOperations/Details/5
        public ActionResult Details(int?id, int ContractId, int PurchaseOrderId)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            FieldOperations fieldOperations = db.FieldOperations.Find(id);

            if (fieldOperations == null || fieldOperations.status != "ASSIGNED")
            {
                return(HttpNotFound());
            }
            ViewBag.ContractId      = ContractId;
            ViewBag.PurchaseOrderId = PurchaseOrderId;
            return(View(fieldOperations));
        }
Ejemplo n.º 28
0
        public static void KeyExchange(ArraySegment <byte> sharedKey, ArraySegment <byte> publicKey, ArraySegment <byte> privateKey)
        {
            if (sharedKey.Array == null)
            {
                throw new ArgumentNullException("sharedKey.Array");
            }
            if (publicKey.Array == null)
            {
                throw new ArgumentNullException("publicKey.Array");
            }
            if (privateKey.Array == null)
            {
                throw new ArgumentNullException("privateKey");
            }
            if (sharedKey.Count != 32)
            {
                throw new ArgumentException("sharedKey.Count != 32");
            }
            if (publicKey.Count != 32)
            {
                throw new ArgumentException("publicKey.Count != 32");
            }
            if (privateKey.Count != 64)
            {
                throw new ArgumentException("privateKey.Count != 64");
            }

            FieldElement montgomeryX, edwardsY, edwardsZ, sharedMontgomeryX;

            FieldOperations.fe_frombytes(out edwardsY, publicKey.Array, publicKey.Offset);
            FieldOperations.fe_1(out edwardsZ);
            MontgomeryCurve25519.EdwardsToMontgomeryX(out montgomeryX, ref edwardsY, ref edwardsZ);
            var blake2bConfig = new Blake2BConfig
            {
                OutputSizeInBytes = 64
            };
            var hasher = Blake2B.Create(blake2bConfig);

            hasher.Update(privateKey.Array, privateKey.Offset, 32);
            byte[] h = hasher.Finish();
            //byte[] h = Sha512.Hash(privateKey.Array, privateKey.Offset, 32);//ToDo: Remove alloc
            ScalarOperations.sc_clamp(h, 0);
            MontgomeryOperations.scalarmult(out sharedMontgomeryX, h, 0, ref montgomeryX);
            CryptoBytes.Wipe(h);
            FieldOperations.fe_tobytes(sharedKey.Array, sharedKey.Offset, ref sharedMontgomeryX);
            MontgomeryCurve25519.KeyExchangeOutputHashNaCl(sharedKey.Array, sharedKey.Offset);
        }
Ejemplo n.º 29
0
        public static int ge_frombytes_negate_vartime(out GroupElementP3 h, byte[] data, int offset)
        {
            FieldElement u;
            FieldElement v;
            FieldElement v3;
            FieldElement vxx;
            FieldElement check;

            FieldOperations.fe_frombytes(out h.Y, data, offset);
            FieldOperations.fe_1(out h.Z);
            FieldOperations.fe_sq(out u, ref h.Y);
            FieldOperations.fe_mul(out v, ref u, ref LookupTables.d);
            FieldOperations.fe_sub(out u, ref u, ref h.Z);                     /* u = y^2-1 */
            FieldOperations.fe_add(out v, ref v, ref h.Z);                     /* v = dy^2+1 */

            FieldOperations.fe_sq(out v3, ref v);
            FieldOperations.fe_mul(out v3, ref v3, ref v);                      /* v3 = v^3 */
            FieldOperations.fe_sq(out h.X, ref v3);
            FieldOperations.fe_mul(out h.X, ref h.X, ref v);
            FieldOperations.fe_mul(out h.X, ref h.X, ref u);            /* x = uv^7 */

            FieldOperations.fe_pow22523(out h.X, ref h.X);              /* x = (uv^7)^((q-5)/8) */
            FieldOperations.fe_mul(out h.X, ref h.X, ref v3);
            FieldOperations.fe_mul(out h.X, ref h.X, ref u);            /* x = uv^3(uv^7)^((q-5)/8) */

            FieldOperations.fe_sq(out vxx, ref h.X);
            FieldOperations.fe_mul(out vxx, ref vxx, ref v);
            FieldOperations.fe_sub(out check, ref vxx, ref u);                  /* vx^2-u */
            if (FieldOperations.fe_isnonzero(ref check) != 0)
            {
                FieldOperations.fe_add(out check, ref vxx, ref u);                    /* vx^2+u */
                if (FieldOperations.fe_isnonzero(ref check) != 0)
                {
                    h = default(GroupElementP3);
                    return(-1);
                }
                FieldOperations.fe_mul(out h.X, ref h.X, ref LookupTables.sqrtm1);
            }

            if (FieldOperations.fe_isnegative(ref h.X) == (data[offset + 31] >> 7))
            {
                FieldOperations.fe_neg(out h.X, ref h.X);
            }

            FieldOperations.fe_mul(out h.T, ref h.X, ref h.Y);
            return(0);
        }
Ejemplo n.º 30
0
    /// <summary>
    /// Ms the game order_ on enemy turn begin.
    /// если ход компьютера, просчет клетки компьютером для удара
    /// </summary>
    void mGameOrder_OnEnemyTurnBegin()
    {
        FieldOperations field = mGameOrder.PlayerField.GetComponent <FieldOperations>();
        bool            res = false;
        int             x, y;

        EvaluateEnemyAim(out x, out y);

        mGameOrder.AddTask(0.5f, () =>
        {
            res = field.AttackCell(x, y);
        });
        mGameOrder.AddTask(res ? 1.5f : 0.5f, () =>
        {
            mGameOrder.EndTurn(res);
        });
    }