public ImageFile(Pack pack, FileCommonHeader commonHeader)
     : base(pack, commonHeader)
 {
     var stream = GetSourceStream();
     stream.Position = CommonHeader.EndOfHeader;
     ImageHeader = new ImageHeader(stream);
 }
        private static GenericResponse UpdatePack(PackInformation pkinfo)
        {
            try
            {
                var response = new GenericResponse();
                using (var context = new Entities())
                {
                    var yd = (from yard in context.Yards
                        where yard.Id == pkinfo.YardId
                        select yard.CustomerNumberPrefix).First() ?? string.Empty;
                    pkinfo.NumberPrefix = yd;
                    pkinfo.InternalPackNumber = yd.Trim() + pkinfo.TagNumber;

                    var pack = (from pk in context.Packs
                        where pk.Id == pkinfo.Id
                        select pk).FirstOrDefault();
                    if (pack == null)
                    {
                        var pk = new Pack();
                        Mapper.Map(pkinfo, pk);
                        context.Packs.AddObject(pk);
                    }
                    else Mapper.Map(pkinfo, pack);
                    context.SaveChanges();
                }
                response.Success = true;
                return response;
            }
            catch (Exception ex)
            {
                LoggingMediator.Log("UpdatePack");
                LoggingMediator.Log(ex);
                return new GenericResponse {Success = false, FailureInformation = "Error in PAPService:UpdatePack"};
            }
        }
 public Material(string name = "", Pack pack = null)
 {
     loadedformat = forsavingformat = ElementType.Material;
     if (name != "") this.name = name; else
     name = "New Material " + DateTime.Now.Millisecond.ToString();
     this.pack = pack;
     lodMats = new List<Lod>();
 }
        public Pack GetPack(PackIdentifier id)
        {
            Pack pack;
            if (_Packs.TryGetValue(id, out pack)) return pack;

            pack = new Pack(this, DataDirectory, id);
            _Packs.Add(id, pack);
            return pack;
        }
 public override System.Windows.Forms.DialogResult createpropertieswindow(Pack p, System.Windows.Forms.TreeView outputtreeview)
 {
     FormParticleRenderObjectDescription dd = new FormParticleRenderObjectDescription(this);
     dd.ShowDialog();
     name = dd.textBox1.Text;
     if (!name.EndsWith("\0"))
         name += "\0";
     return System.Windows.Forms.DialogResult.OK;
 }
        public Pack GetPack(string path)
        {
            var id = PackIdentifier.Get(path);
            Pack pack;
            if (_Packs.TryGetValue(id, out pack)) return pack;

            pack = new Pack(this, DataDirectory, id);
            _Packs.Add(id, pack);
            return pack;
        }
        public void CanCreatePack()
        {
            // arrange

            // act
            var pack = new Pack();

            // assert
            Assert.Equal(52, pack.Count());
        }
        public void CanShuffle()
        {
            // arrange
            var pack = new Pack(false /* shuffle */);

            // act
            pack.Shuffle();

            // assert
            Assert.NotEqual(Pack.Etalon, pack);
        }
        public void CanDeal()
        {
            // arrange
            var pack = new Pack();

            // act
            var hand = pack.Deal(5);

            // assert
            Assert.Equal(5, hand.Count());
            Assert.Equal(47, pack.Count());
        }
        public override System.Windows.Forms.DialogResult createpropertieswindow(Pack p, System.Windows.Forms.TreeView outputtreeview)
        {
            /* FormMeshList form = new FormMeshList(this, outputtreeview);

            if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                name = form.TextBoxName.Text + "\0";
                if (TreeNode != null)
                    TreeNode.Text = name;
            }
            return form.DialogResult;*/
            return DialogResult.Cancel;
        }
示例#11
0
    public static void ChangeStatus(Guid ID, Pack.StatusX toStatus, PackTransaction.TypeX transType, string note)
    {
        RedBloodDataContext db = new RedBloodDataContext();

        Pack p = Get(db, ID);

        if (p.Status == toStatus)
        {
            throw new Exception("Can not change statuses which are the same.");
        }

        PackTransactionBLL.Add(ID, p.Status, toStatus, transType, note);

        p.Status = toStatus;
        db.SubmitChanges();
    }
示例#12
0
    public static void Add(string DIN, string productCode, int? volume, bool isOriginal)
    {
        RedBloodDataContext db = new RedBloodDataContext();

        Donation d = null;

        if (isOriginal)
        {
            d = DonationBLL.Get4CreateOriginal(db, DIN);
        }
        else
        {
            d = DonationBLL.Get(DIN);
        }

        Product product = ProductBLL.Get(productCode);

        if (IsExist(DIN, productCode))
            throw new Exception(PackErrEnum.Existed.Message);

        //TODO: Check to see valid product code in collection
        //Code will be here

        //TODO: Check to see if the pack is collector too late
        //Code check will be here.

        Pack pack = new Pack();

        pack.DIN = DIN;
        pack.ProductCode = productCode;
        pack.Status = Pack.StatusX.Product;
        pack.Actor = RedBloodSystem.CurrentActor;
        //pack.Volume = product.OriginalVolume.HasValue ? product.OriginalVolume : defaultVolume;
        pack.Volume = volume;
        pack.ExpirationDate = DateTime.Now.Add(product.Duration.Value - RedBloodSystem.RootTime);

        db.Packs.InsertOnSubmit(pack);
        db.SubmitChanges();

        PackTransactionBLL.Add(pack.ID, Pack.StatusX.Non, Pack.StatusX.Product,
            isOriginal ? PackTransaction.TypeX.In_Collect : PackTransaction.TypeX.In_Product);

        if (isOriginal)
        {
            DonationBLL.SetOriginalPack(DIN, pack.ID);
        }
    }
        public FormObjectPicker(Pack p, int filter, bool multiselect = false, string label = "", string found_regex = "", bool auto = false)
        {
            this.multiselect = multiselect;
            PickedContent = new List<string>();
            InitializeComponent();
            checkedListBox1.Items.AddRange(
                p.Objects.FindAll(o => o.loadedformat == filter || o.forsavingformat == filter).ConvertAll(o => o.name).ToArray()); ;

            if (label != "") { label1.Text = label; label1.Visible = true; }

            if (found_regex != "")
            {
                int i =0;
                foreach (dynamic val in checkedListBox1.Items)
                {

                    try
                    {
                        if (Regex.IsMatch(val, found_regex))
                        {
                            checkedListBox1.SetItemChecked(i, true);
                            if (multiselect)
                            {
                                checkedListBox1.SelectedItems.Add(val);
                            }
                            else
                            {
                                checkedListBox1.SelectedItem = val;
                                button1.Focus();
                                break;
                            }

                        }
                    }
                    catch { }
                    i++;
                }
            }

            if (auto)
            { button1_Click(null, null); }

            checkedListBox2.Items.AddRange(
                Eggs.Buffer.FindAll(o => o.loadedformat == filter || o.forsavingformat == filter).ConvertAll(o => o.name).ToArray()); ;
        }
示例#14
0
        public static File Get(Pack pack, IIndexFile file) {
            var stream = pack.GetDataStream(file.DatFile);
            stream.Position = file.Offset;

            var header = new FileCommonHeader(file, stream);

            switch (header.FileType) {
                case FileType.Empty:
                    return new EmptyFile(pack, header);
                case FileType.Default:
                    return new FileDefault(pack, header);
                case FileType.Image:
                    return new ImageFile(pack, header);
                case FileType.Model:
                    return new ModelFile(pack, header);
                default:
                    throw new NotSupportedException(string.Format("Unknown file type {0:X2}h", (int)header.FileType));
            }
        }
示例#15
0
        public override System.Windows.Forms.DialogResult createpropertieswindow(Pack p, System.Windows.Forms.TreeView outputtreeview)
        {
            if (Enginereadedobject.Count == 0)
            {
                FormMaterial form = new FormMaterial(this);

                if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    //  name = form.TextBoxName.Text + "\0";
                    if (TreeNode != null)
                        TreeNode.Text = name;
                }
                return form.DialogResult;
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("object are loaded to scene. cannot to edit");
                return System.Windows.Forms.DialogResult.Cancel;
            }
        }
        public override System.Windows.Forms.DialogResult createpropertieswindow(Pack p, System.Windows.Forms.TreeView outputtreeview)
        {
            FormTextureList form = new FormTextureList(this,outputtreeview);

            if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {

                name = form.TextBoxName.Text + "\0";
                if (TreeNode != null)
                    TreeNode.Text = name;
                if (form.generatedimages != null)
                {
                    for (int i = 0; i < form.generatedimages.Length; i++)
                    {
                        Pack.Attach(form.generatedimages[i]);
                    }
                    FormMainPackExplorer.Instance.UpdateData();
                }
            }
            return  form.DialogResult;
        }
示例#17
0
    public static PackTransaction Add(Guid packID, Pack.StatusX fromStatus, Pack.StatusX toStatus, PackTransaction.TypeX type, string note)
    {
        //Always run SOD before new transaction
        RedBloodSystemBLL.SOD();

        RedBloodDataContext db = new RedBloodDataContext();

        if (fromStatus == toStatus)
            throw new Exception("Can not add pack transaction if not change pack status.");

        PackTransaction e = new PackTransaction();
        e.FromStatus = fromStatus;
        e.ToStatus = toStatus;
        e.PackID = packID;
        e.Type = type;
        e.Actor = RedBloodSystem.CurrentActor;
        e.Note = note.Trim();

        db.PackTransactions.InsertOnSubmit(e);

        db.SubmitChanges();

        return e;
    }
        private void MeshImportList_Shown(object sender, EventArgs e)
        {
            p = new Pack();

            p.Init(s, null);

            TreeNode root = new TreeNode(s);
            root.Text = s;
            treeView1.Nodes.Add(root);
            for (int o = 0; o < p.Objects.Count; o++)
            {
                TreeNode tn = new TreeNode(p.Objects[o].name);
                tn.Text = p.Objects[o].name;
                root.Nodes.Add(tn);
            }

            TreeNodeCollection c = treeView1.Nodes[0].Nodes;
            TreeNode[] nodes = new TreeNode[c.Count];

               c.CopyTo(nodes,0);
            treeView1.Nodes.Clear();
            treeView1.Nodes.AddRange(nodes);
            toolStripProgressBar1.Value = toolStripProgressBar2.Value = 100;
        }
示例#19
0
        static OstHelper()
        {
            packs = new Pack[] {
                new Pack
                {
                    PackID         = "OstVol1",
                    PackName       = "Original Soundtrack Vol. 1",
                    SongDictionary = new Dictionary <string, string>
                    {
                        { "BeatSaber", "Beat Saber" },
                        { "Escape", "Escape" },
                        { "LvlInsane", "Lvl Insane" },
                        { "100Bills", "$100 Bills" },
                        { "CountryRounds", "Country Rounds" },
                        { "Breezer", "Breezer" },
                        { "TurnMeOn", "Turn Me On" },
                        { "BalearicPumping", "Balaeric Pumping" },
                        { "Legend", "Legend" },
                        { "CommercialPumping", "Commercial Pumping" }
                    }
                },
                new Pack
                {
                    PackID         = "OstVol2",
                    PackName       = "Original Soundtrack Vol. 2",
                    SongDictionary = new Dictionary <string, string>
                    {
                        { "BeThereForYou", "Be There For You" },
                        { "Elixia", "Elixia" },
                        { "INeedYou", "I Need You" },
                        { "RumNBass", "Rum n' Bass" },
                        { "UnlimitedPower", "Unlimited Power" }
                    }
                },
                new Pack
                {
                    PackID         = "OstVol3",
                    PackName       = "Original Soundtrack Vol. 3",
                    SongDictionary = new Dictionary <string, string>
                    {
                        { "Origins", "Origins" },
                        { "ReasonForLiving", "Reason For Living" },
                        { "GiveALittleLove", "Give a Little Love" },
                        { "FullCharge", "Full Charge" },
                        { "Immortal", "Immortal" },
                        { "BurningSands", "Burning Sands" }
                    }
                },
                new Pack
                {
                    PackID         = "Extras",
                    PackName       = "Extras",
                    SongDictionary = new Dictionary <string, string>
                    {
                        { "Crystallized", "Crystallized" },
                        { "CycleHit", "Cycle Hit" },
                        { "WhatTheCat", "WHAT THE CAT!?" },
                        { "CrabRave", "Crab Rave" },
                        { "AngelVoices", "Angel Voices" },
                        { "OneHope", "One Hope" },
                        { "PopStars", "POP/STARS - K/DA" }
                    }
                },
                new Pack
                {
                    PackID         = "Monstercat",
                    PackName       = "Monstercat Music Pack Vol. 1",
                    SongDictionary = new Dictionary <string, string>
                    {
                        { "Boundless", "Boundless" },
                        { "EmojiVIP", "Emoji VIP" },
                        { "Epic", "EPIC" },
                        { "FeelingStronger", "Feeling Stronger" },
                        { "Overkill", "Overkill" },
                        { "Rattlesnake", "Rattlesnake" },
                        { "Stronger", "Stronger" },
                        { "ThisTime", "This Time" },
                        { "TillItsOver", "Till It's Over" },
                        { "WeWontBeAlone", "We Won't Be Alone" },
                    }
                },
                new Pack
                {
                    PackID         = "ImagineDragons",
                    PackName       = "Imagine Dragons Music Pack",
                    SongDictionary = new Dictionary <string, string>
                    {
                        { "BadLiar", "Bad Liar" },
                        { "Believer", "Believer" },
                        { "Digital", "Digital" },
                        { "ItsTime", "It's Time" },
                        { "Machine", "Machine" },
                        { "Natural", "Natural" },
                        { "Radioactive", "Radioactive" },
                        { "Thunder", "Thunder" },
                        { "Warriors", "Warriors" },
                        { "WhateverItTakes", "Whatever It Takes" }
                    }
                }
            };

            foreach (Pack pack in packs)
            {
                allLevels = allLevels.Concat(pack.SongDictionary).ToDictionary(s => s.Key, s => s.Value);
            }
        }
示例#20
0
        //==================================
        // Private Implementation
        //==================================

        /*
         * Creates the subkeys using the same nomenclature
         * as described in RFC2612.
         *
         * See section 2.4
         */
        internal override void SetKey(
            byte[] key)
        {
            uint Cm = 0x5a827999;
            uint Mm = 0x6ed9eba1;
            int  Cr = 19;
            int  Mr = 17;

            /*
             * Determine the key size here, if required
             *
             * if keysize < 256 bytes, pad with 0
             *
             * Typical key sizes => 128, 160, 192, 224, 256
             */
            for (int i = 0; i < 24; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    _Tm[i * 8 + j] = Cm;
                    Cm            += Mm;               //mod 2^32;
                    _Tr[i * 8 + j] = Cr;
                    Cr             = (Cr + Mr) & 0x1f; // mod 32
                }
            }

            byte[] tmpKey = new byte[64];
            key.CopyTo(tmpKey, 0);

            // now create ABCDEFGH
            for (int i = 0; i < 8; i++)
            {
                _workingKey[i] = Pack.BE_To_UInt32(tmpKey, i * 4);
            }

            // Generate the key schedule
            for (int i = 0; i < 12; i++)
            {
                // KAPPA <- W2i(KAPPA)
                int i2 = i * 2 * 8;
                _workingKey[6] ^= F1(_workingKey[7], _Tm[i2], _Tr[i2]);
                _workingKey[5] ^= F2(_workingKey[6], _Tm[i2 + 1], _Tr[i2 + 1]);
                _workingKey[4] ^= F3(_workingKey[5], _Tm[i2 + 2], _Tr[i2 + 2]);
                _workingKey[3] ^= F1(_workingKey[4], _Tm[i2 + 3], _Tr[i2 + 3]);
                _workingKey[2] ^= F2(_workingKey[3], _Tm[i2 + 4], _Tr[i2 + 4]);
                _workingKey[1] ^= F3(_workingKey[2], _Tm[i2 + 5], _Tr[i2 + 5]);
                _workingKey[0] ^= F1(_workingKey[1], _Tm[i2 + 6], _Tr[i2 + 6]);
                _workingKey[7] ^= F2(_workingKey[0], _Tm[i2 + 7], _Tr[i2 + 7]);
                // KAPPA <- W2i+1(KAPPA)
                i2              = (i * 2 + 1) * 8;
                _workingKey[6] ^= F1(_workingKey[7], _Tm[i2], _Tr[i2]);
                _workingKey[5] ^= F2(_workingKey[6], _Tm[i2 + 1], _Tr[i2 + 1]);
                _workingKey[4] ^= F3(_workingKey[5], _Tm[i2 + 2], _Tr[i2 + 2]);
                _workingKey[3] ^= F1(_workingKey[4], _Tm[i2 + 3], _Tr[i2 + 3]);
                _workingKey[2] ^= F2(_workingKey[3], _Tm[i2 + 4], _Tr[i2 + 4]);
                _workingKey[1] ^= F3(_workingKey[2], _Tm[i2 + 5], _Tr[i2 + 5]);
                _workingKey[0] ^= F1(_workingKey[1], _Tm[i2 + 6], _Tr[i2 + 6]);
                _workingKey[7] ^= F2(_workingKey[0], _Tm[i2 + 7], _Tr[i2 + 7]);
                // Kr_(i) <- KAPPA
                _Kr[i * 4]     = (int)(_workingKey[0] & 0x1f);
                _Kr[i * 4 + 1] = (int)(_workingKey[2] & 0x1f);
                _Kr[i * 4 + 2] = (int)(_workingKey[4] & 0x1f);
                _Kr[i * 4 + 3] = (int)(_workingKey[6] & 0x1f);
                // Km_(i) <- KAPPA
                _Km[i * 4]     = _workingKey[7];
                _Km[i * 4 + 1] = _workingKey[5];
                _Km[i * 4 + 2] = _workingKey[3];
                _Km[i * 4 + 3] = _workingKey[1];
            }
        }
示例#21
0
        static void Main(string[] args)
        {
            SQLQueue  = new MySqlConnection[10];
            RandomSQL = new Random(new Guid().GetHashCode());

            string connectionString = "server=localhost;uid=auxilium;pwd=123456;database=auxilium";

            for (int i = 0; i < SQLQueue.Length; i++)
            {
                MySqlConnection msc = new MySqlConnection();
                SQLQueue[i] = msc;
                try
                {
                    msc.ConnectionString = connectionString;
                    msc.Open();
                }
                catch (Exception)
                {
                    Console.Write("An error occured connecting to the database.\nPlease enter your credentials.\n\nUsername: "******"Password: "******"server=localhost;uid={0};pwd={1};database=auxilium", username, password));
                    msc.Open();
                }
            }

            EmailClient = new SmtpClient
            {
                Host                  = "smtp.gmail.com",
                Port                  = 587,
                EnableSsl             = true,
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false
            };

            LetsDoThis();

            Channels = new string[] { "Lounge" };

            MOTD = GetMOTD();

            Packer   = new Pack();
            Listener = new Server {
                BufferSize = 2048, MaxConnections = 1000
            };

            Listener.ClientRead  += ClientRead;
            Listener.ClientState += ClientState;
            Listener.ServerState += ServerState;
            Listener.Listen(Port);

            //Create the chat monitor timer.
            ChatMonitor = new Timer(Monitor, null, 1000, 240000); //240,000 = 4 Minutes
            LastBackup  = DateTime.Now;

            string console = string.Empty;

            while (true)
            {
                char c = Console.ReadKey().KeyChar;
                if (c == Convert.ToChar(ConsoleKey.Escape))
                {
                    break;
                }
                if (c == Convert.ToChar(ConsoleKey.Enter))
                {
                    CheckCommand(null, console);
                    console = string.Empty;
                }
                else
                {
                    console += c;
                }
            }
        }
示例#22
0
        private static void FindVdsDisk(string serverName, Func <Disk, bool> compareFunc, out AdvancedDisk advancedDisk, out Pack diskPack)
        {
            advancedDisk = null;
            diskPack     = null;

            ServiceLoader serviceLoader = new ServiceLoader();
            Service       vds           = serviceLoader.LoadService(serverName);

            vds.WaitForServiceReady();

            foreach (Disk disk in vds.UnallocatedDisks)
            {
                if (compareFunc(disk))
                {
                    advancedDisk = (AdvancedDisk)disk;
                    break;
                }
            }

            if (advancedDisk == null)
            {
                vds.HardwareProvider = false;
                vds.SoftwareProvider = true;

                foreach (SoftwareProvider provider in vds.Providers)
                {
                    foreach (Pack pack in provider.Packs)
                    {
                        foreach (Disk disk in pack.Disks)
                        {
                            if (compareFunc(disk))
                            {
                                diskPack     = pack;
                                advancedDisk = (AdvancedDisk)disk;
                                break;
                            }
                        }
                    }
                }
            }
        }
示例#23
0
 public static void AsUlongs(byte[] x, ulong[] z)
 {
     Pack.BE_To_UInt64(x, 0, z);
 }
示例#24
0
        public static void FindVdsDisk(string serverName, string diskAddress, out AdvancedDisk advancedDisk, out Pack diskPack)
        {
            Func <Disk, bool> compareFunc = disk => disk.DiskAddress == diskAddress;

            FindVdsDisk(serverName, compareFunc, out advancedDisk, out diskPack);
        }
 void Calc4Component(List<int> camIDL, int componentID, Pack.StatusX status, Label lblNonTR, Label lblPos, Label lblNeg, Label lblDeliver, Label lblExpire, Label lblDelete)
 {
 }
示例#26
0
 private void log(Pack pack)
 {
     log(createItem(pack.text, pack.message, pack.color));
 }
示例#27
0
        /**
         * the DES engine.
         */
        internal static void DesFunc(
            int[]       wKey,
            byte[]      input,
            int inOff,
            byte[]      outBytes,
            int outOff)
        {
            uint left  = Pack.BE_To_UInt32(input, inOff);
            uint right = Pack.BE_To_UInt32(input, inOff + 4);
            uint work;

            work   = ((left >> 4) ^ right) & 0x0f0f0f0f;
            right ^= work;
            left  ^= (work << 4);
            work   = ((left >> 16) ^ right) & 0x0000ffff;
            right ^= work;
            left  ^= (work << 16);
            work   = ((right >> 2) ^ left) & 0x33333333;
            left  ^= work;
            right ^= (work << 2);
            work   = ((right >> 8) ^ left) & 0x00ff00ff;
            left  ^= work;
            right ^= (work << 8);
            right  = (right << 1) | (right >> 31);
            work   = (left ^ right) & 0xaaaaaaaa;
            left  ^= work;
            right ^= work;
            left   = (left << 1) | (left >> 31);

            for (int round = 0; round < 8; round++)
            {
                uint fval;

                work   = (right << 28) | (right >> 4);
                work  ^= (uint)wKey[round * 4 + 0];
                fval   = SP7[work & 0x3f];
                fval  |= SP5[(work >> 8) & 0x3f];
                fval  |= SP3[(work >> 16) & 0x3f];
                fval  |= SP1[(work >> 24) & 0x3f];
                work   = right ^ (uint)wKey[round * 4 + 1];
                fval  |= SP8[work & 0x3f];
                fval  |= SP6[(work >> 8) & 0x3f];
                fval  |= SP4[(work >> 16) & 0x3f];
                fval  |= SP2[(work >> 24) & 0x3f];
                left  ^= fval;
                work   = (left << 28) | (left >> 4);
                work  ^= (uint)wKey[round * 4 + 2];
                fval   = SP7[work & 0x3f];
                fval  |= SP5[(work >> 8) & 0x3f];
                fval  |= SP3[(work >> 16) & 0x3f];
                fval  |= SP1[(work >> 24) & 0x3f];
                work   = left ^ (uint)wKey[round * 4 + 3];
                fval  |= SP8[work & 0x3f];
                fval  |= SP6[(work >> 8) & 0x3f];
                fval  |= SP4[(work >> 16) & 0x3f];
                fval  |= SP2[(work >> 24) & 0x3f];
                right ^= fval;
            }

            right  = (right << 31) | (right >> 1);
            work   = (left ^ right) & 0xaaaaaaaa;
            left  ^= work;
            right ^= work;
            left   = (left << 31) | (left >> 1);
            work   = ((left >> 8) ^ right) & 0x00ff00ff;
            right ^= work;
            left  ^= (work << 8);
            work   = ((left >> 2) ^ right) & 0x33333333;
            right ^= work;
            left  ^= (work << 2);
            work   = ((right >> 16) ^ left) & 0x0000ffff;
            left  ^= work;
            right ^= (work << 16);
            work   = ((right >> 4) ^ left) & 0x0f0f0f0f;
            left  ^= work;
            right ^= (work << 4);

            Pack.UInt32_To_BE(right, outBytes, outOff);
            Pack.UInt32_To_BE(left, outBytes, outOff + 4);
        }
示例#28
0
        public virtual int GenerateBytes(byte[] outBytes, int outOff, int len)
        {
            if ((outBytes.Length - len) < outOff)
            {
                throw new DataLengthException("output buffer too small");
            }

            long oBytes = len;
            int  outLen = digest.GetDigestSize();

            //
            // this is at odds with the standard implementation, the
            // maximum value should be hBits * (2^32 - 1) where hBits
            // is the digest output size in bits. We can't have an
            // array with a long index at the moment...
            //
            if (oBytes > ((2L << 32) - 1))
            {
                throw new ArgumentException("Output length too large");
            }

            int cThreshold = (int)((oBytes + outLen - 1) / outLen);

            byte[] dig = new byte[digest.GetDigestSize()];

            uint counter = 1;

            for (int i = 0; i < cThreshold; i++)
            {
                digest.BlockUpdate(z, 0, z.Length);

                // KeySpecificInfo
                DerSequence keyInfo = new DerSequence(
                    algorithm,
                    new DerOctetString(Pack.UInt32_To_BE(counter)));

                // OtherInfo
                Asn1EncodableVector v1 = new Asn1EncodableVector(keyInfo);

                if (partyAInfo != null)
                {
                    v1.Add(new DerTaggedObject(true, 0, new DerOctetString(partyAInfo)));
                }

                v1.Add(new DerTaggedObject(true, 2, new DerOctetString(Pack.UInt32_To_BE((uint)keySize))));

                byte[] other = new DerSequence(v1).GetDerEncoded();

                digest.BlockUpdate(other, 0, other.Length);

                digest.DoFinal(dig, 0);

                if (len > outLen)
                {
                    Array.Copy(dig, 0, outBytes, outOff, outLen);
                    outOff += outLen;
                    len    -= outLen;
                }
                else
                {
                    Array.Copy(dig, 0, outBytes, outOff, len);
                }

                counter++;
            }

            digest.Reset();

            return((int)oBytes);
        }
示例#29
0
        /**
         * Calculate the necessary round keys
         * The number of calculations depends on key size and block size
         * AES specified a fixed block size of 128 bits and key sizes 128/192/256 bits
         * This code is written assuming those are the only possible values
         */
        private uint[][] GenerateWorkingKey(byte[] key, bool forEncryption)
        {
            int keyLen = key.Length;

            if (keyLen < 16 || keyLen > 32 || (keyLen & 7) != 0)
            {
                throw new ArgumentException("Key length not 128/192/256 bits.");
            }

            int KC = keyLen >> 2;

            this.ROUNDS = KC + 6;                // This is not always true for the generalized Rijndael that allows larger block sizes

            uint[][] W = new uint[ROUNDS + 1][]; // 4 words in a block
            for (int i = 0; i <= ROUNDS; ++i)
            {
                W[i] = new uint[4];
            }

            switch (KC)
            {
            case 4:
            {
                uint t0 = Pack.LE_To_UInt32(key, 0); W[0][0] = t0;
                uint t1 = Pack.LE_To_UInt32(key, 4); W[0][1] = t1;
                uint t2 = Pack.LE_To_UInt32(key, 8); W[0][2] = t2;
                uint t3 = Pack.LE_To_UInt32(key, 12); W[0][3] = t3;

                for (int i = 1; i <= 10; ++i)
                {
                    uint u = SubWord(Shift(t3, 8)) ^ rcon[i - 1];
                    t0 ^= u;  W[i][0] = t0;
                    t1 ^= t0; W[i][1] = t1;
                    t2 ^= t1; W[i][2] = t2;
                    t3 ^= t2; W[i][3] = t3;
                }

                break;
            }

            case 6:
            {
                uint t0 = Pack.LE_To_UInt32(key, 0); W[0][0] = t0;
                uint t1 = Pack.LE_To_UInt32(key, 4); W[0][1] = t1;
                uint t2 = Pack.LE_To_UInt32(key, 8); W[0][2] = t2;
                uint t3 = Pack.LE_To_UInt32(key, 12); W[0][3] = t3;
                uint t4 = Pack.LE_To_UInt32(key, 16); W[1][0] = t4;
                uint t5 = Pack.LE_To_UInt32(key, 20); W[1][1] = t5;

                uint rcon = 1;
                uint u    = SubWord(Shift(t5, 8)) ^ rcon; rcon <<= 1;
                t0 ^= u;  W[1][2] = t0;
                t1 ^= t0; W[1][3] = t1;
                t2 ^= t1; W[2][0] = t2;
                t3 ^= t2; W[2][1] = t3;
                t4 ^= t3; W[2][2] = t4;
                t5 ^= t4; W[2][3] = t5;

                for (int i = 3; i < 12; i += 3)
                {
                    u   = SubWord(Shift(t5, 8)) ^ rcon; rcon <<= 1;
                    t0 ^= u;  W[i][0] = t0;
                    t1 ^= t0; W[i][1] = t1;
                    t2 ^= t1; W[i][2] = t2;
                    t3 ^= t2; W[i][3] = t3;
                    t4 ^= t3; W[i + 1][0] = t4;
                    t5 ^= t4; W[i + 1][1] = t5;
                    u   = SubWord(Shift(t5, 8)) ^ rcon; rcon <<= 1;
                    t0 ^= u;  W[i + 1][2] = t0;
                    t1 ^= t0; W[i + 1][3] = t1;
                    t2 ^= t1; W[i + 2][0] = t2;
                    t3 ^= t2; W[i + 2][1] = t3;
                    t4 ^= t3; W[i + 2][2] = t4;
                    t5 ^= t4; W[i + 2][3] = t5;
                }

                u   = SubWord(Shift(t5, 8)) ^ rcon;
                t0 ^= u;  W[12][0] = t0;
                t1 ^= t0; W[12][1] = t1;
                t2 ^= t1; W[12][2] = t2;
                t3 ^= t2; W[12][3] = t3;

                break;
            }

            case 8:
            {
                uint t0 = Pack.LE_To_UInt32(key, 0); W[0][0] = t0;
                uint t1 = Pack.LE_To_UInt32(key, 4); W[0][1] = t1;
                uint t2 = Pack.LE_To_UInt32(key, 8); W[0][2] = t2;
                uint t3 = Pack.LE_To_UInt32(key, 12); W[0][3] = t3;
                uint t4 = Pack.LE_To_UInt32(key, 16); W[1][0] = t4;
                uint t5 = Pack.LE_To_UInt32(key, 20); W[1][1] = t5;
                uint t6 = Pack.LE_To_UInt32(key, 24); W[1][2] = t6;
                uint t7 = Pack.LE_To_UInt32(key, 28); W[1][3] = t7;

                uint u, rcon = 1;

                for (int i = 2; i < 14; i += 2)
                {
                    u   = SubWord(Shift(t7, 8)) ^ rcon; rcon <<= 1;
                    t0 ^= u;  W[i][0] = t0;
                    t1 ^= t0; W[i][1] = t1;
                    t2 ^= t1; W[i][2] = t2;
                    t3 ^= t2; W[i][3] = t3;
                    u   = SubWord(t3);
                    t4 ^= u;  W[i + 1][0] = t4;
                    t5 ^= t4; W[i + 1][1] = t5;
                    t6 ^= t5; W[i + 1][2] = t6;
                    t7 ^= t6; W[i + 1][3] = t7;
                }

                u   = SubWord(Shift(t7, 8)) ^ rcon;
                t0 ^= u;  W[14][0] = t0;
                t1 ^= t0; W[14][1] = t1;
                t2 ^= t1; W[14][2] = t2;
                t3 ^= t2; W[14][3] = t3;

                break;
            }

            default:
            {
                throw new InvalidOperationException("Should never get here");
            }
            }

            if (!forEncryption)
            {
                for (int j = 1; j < ROUNDS; j++)
                {
                    uint[] w = W[j];
                    for (int i = 0; i < 4; i++)
                    {
                        w[i] = Inv_Mcol(w[i]);
                    }
                }
            }

            return(W);
        }
示例#30
0
 public virtual void AddSeedMaterial(long seed)
 {
     AddSeedMaterial(Pack.UInt64_To_BE((ulong)seed));
 }
示例#31
0
	private void detach_Packs(Pack entity)
	{
		this.SendPropertyChanging();
		entity.Donation = null;
	}
示例#32
0
        public int DoFinal(byte[] output, int outOff)
        {
            if (totalLength == 0)
            {
                InitCipher();
            }

            int extra = bufOff;

            if (forEncryption)
            {
                Check.OutputLength(output, outOff, extra + macSize, "Output buffer too short");
            }
            else
            {
                if (extra < macSize)
                {
                    throw new InvalidCipherTextException("data too short");
                }

                extra -= macSize;

                Check.OutputLength(output, outOff, extra, "Output buffer too short");
            }

            if (extra > 0)
            {
                gCTRPartial(bufBlock, 0, extra, output, outOff);
            }

            atLength += (uint)atBlockPos;

            if (atLength > atLengthPre)
            {
                /*
                 *  Some AAD was sent after the cipher started. We determine the difference b/w the hash value
                 *  we actually used when the cipher started (S_atPre) and the final hash value calculated (S_at).
                 *  Then we carry this difference forward by multiplying by H^c, where c is the number of (full or
                 *  partial) cipher-text blocks produced, and adjust the current hash.
                 */

                // Finish hash for partial AAD block
                if (atBlockPos > 0)
                {
                    gHASHPartial(S_at, atBlock, 0, atBlockPos);
                }

                // Find the difference between the AAD hashes
                if (atLengthPre > 0)
                {
                    GcmUtilities.Xor(S_at, S_atPre);
                }

                // Number of cipher-text blocks produced
                long c = (long)(((totalLength * 8) + 127) >> 7);

                // Calculate the adjustment factor
                byte[] H_c = new byte[16];
                if (exp == null)
                {
                    exp = new Tables1kGcmExponentiator();
                    exp.Init(H);
                }
                exp.ExponentiateX(c, H_c);

                // Carry the difference forward
                GcmUtilities.Multiply(S_at, H_c);

                // Adjust the current hash
                GcmUtilities.Xor(S, S_at);
            }

            // Final gHASH
            byte[] X = new byte[BlockSize];
            Pack.UInt64_To_BE(atLength * 8UL, X, 0);
            Pack.UInt64_To_BE(totalLength * 8UL, X, 8);

            gHASHBlock(S, X);

            // T = MSBt(GCTRk(J0,S))
            byte[] tag = new byte[BlockSize];
            cipher.ProcessBlock(J0, 0, tag, 0);
            GcmUtilities.Xor(tag, S);

            int resultLen = extra;

            // We place into macBlock our calculated value for T
            this.macBlock = new byte[macSize];
            Array.Copy(tag, 0, macBlock, 0, macSize);

            if (forEncryption)
            {
                // Append T to the message
                Array.Copy(macBlock, 0, output, outOff + bufOff, macSize);
                resultLen += macSize;
            }
            else
            {
                // Retrieve the T value from the message and compare to calculated one
                byte[] msgMac = new byte[macSize];
                Array.Copy(bufBlock, extra, msgMac, 0, macSize);
                if (!Arrays.ConstantTimeAreEqual(this.macBlock, msgMac))
                {
                    throw new InvalidCipherTextException("mac check in GCM failed");
                }
            }

            Reset(false);

            return(resultLen);
        }
示例#33
0
	private void attach_Packs(Pack entity)
	{
		this.SendPropertyChanging();
		entity.Product = this;
	}
示例#34
0
        /// <remarks>
        /// MAC sizes from 32 bits to 128 bits (must be a multiple of 8) are supported. The default is 128 bits.
        /// Sizes less than 96 are not recommended, but are supported for specialized applications.
        /// </remarks>
        public virtual void Init(
            bool forEncryption,
            ICipherParameters parameters)
        {
            this.forEncryption = forEncryption;
            this.macBlock      = null;

            KeyParameter keyParam;

            if (parameters is AeadParameters)
            {
                AeadParameters param = (AeadParameters)parameters;

                nonce = param.GetNonce();
                initialAssociatedText = param.GetAssociatedText();

                int macSizeBits = param.MacSize;
                if (macSizeBits < 32 || macSizeBits > 128 || macSizeBits % 8 != 0)
                {
                    throw new ArgumentException("Invalid value for MAC size: " + macSizeBits);
                }

                macSize  = macSizeBits / 8;
                keyParam = param.Key;
            }
            else if (parameters is ParametersWithIV)
            {
                ParametersWithIV param = (ParametersWithIV)parameters;

                nonce = param.GetIV();
                initialAssociatedText = null;
                macSize  = 16;
                keyParam = (KeyParameter)param.Parameters;
            }
            else
            {
                throw new ArgumentException("invalid parameters passed to GCM");
            }

            int bufLength = forEncryption ? BlockSize : (BlockSize + macSize);

            this.bufBlock = new byte[bufLength];

            if (nonce == null || nonce.Length < 1)
            {
                throw new ArgumentException("IV must be at least 1 byte");
            }

            // TODO Restrict macSize to 16 if nonce length not 12?

            // Cipher always used in forward mode
            // if keyParam is null we're reusing the last key.
            if (keyParam != null)
            {
                cipher.Init(true, keyParam);

                this.H = new byte[BlockSize];
                cipher.ProcessBlock(H, 0, H, 0);

                // if keyParam is null we're reusing the last key and the multiplier doesn't need re-init
                multiplier.Init(H);
                exp = null;
            }
            else if (this.H == null)
            {
                throw new ArgumentException("Key must be specified in initial init");
            }

            this.J0 = new byte[BlockSize];

            if (nonce.Length == 12)
            {
                Array.Copy(nonce, 0, J0, 0, nonce.Length);
                this.J0[BlockSize - 1] = 0x01;
            }
            else
            {
                gHASH(J0, nonce, nonce.Length);
                byte[] X = new byte[BlockSize];
                Pack.UInt64_To_BE((ulong)nonce.Length * 8UL, X, 8);
                gHASHBlock(J0, X);
            }

            this.S           = new byte[BlockSize];
            this.S_at        = new byte[BlockSize];
            this.S_atPre     = new byte[BlockSize];
            this.atBlock     = new byte[BlockSize];
            this.atBlockPos  = 0;
            this.atLength    = 0;
            this.atLengthPre = 0;
            this.counter     = Arrays.Clone(J0);
            this.bufOff      = 0;
            this.totalLength = 0;

            if (initialAssociatedText != null)
            {
                ProcessAadBytes(initialAssociatedText, 0, initialAssociatedText.Length);
            }
        }
示例#35
0
        public PackForm(string levelTemplatePath, string packPath = null)
        {
            InitializeComponent();

            cmLinePanel.MenuItems.Add(new MenuItem("Add", cmLinePanel_ClickAdd));
            cmLinePanel.MenuItems.Add(new MenuItem("Add wizard...", cmLinePanel_ClickAddWizard));
            cmLinePanel.MenuItems.Add(new MenuItem("Delete all", cmLinePanel_ClickDeleteAll));

            cmButton.MenuItems.Add(new MenuItem("Insert", cmButton_ClickInsert));
            cmButton.MenuItems.Add(new MenuItem("Insert wizard...", cmButton_ClickInsertWizard));
            cmButton.MenuItems.Add(new MenuItem("Delete", cmButton_ClickDelete));
            cmButton.MenuItems.Add(new MenuItem("Delete all", cmButton_ClickDeleteAll));


            decimal zoomOut = (decimal)23 / Math.Max(ilSpawnItemTypesLarge.ImageSize.Width, ilSpawnItemTypesLarge.ImageSize.Height);

            ilSpawnItemTypesSmall.ImageSize = new Size((int)(ilSpawnItemTypesLarge.ImageSize.Width * zoomOut), (int)(ilSpawnItemTypesLarge.ImageSize.Height * zoomOut));
            ilSpawnItemTypesSmall.Images.Clear();
            foreach (string key in ilSpawnItemTypesLarge.Images.Keys)
            {
                ilSpawnItemTypesSmall.Images.Add(key, ilSpawnItemTypesLarge.Images[key]);
            }

            BeginBinding();
            try
            {
                for (int i = 0; i < MaxAttachmentsForType; i++)
                {
                    var gc = gvAttachmentTypes.Columns.Add();

                    gc.Name        = AttachmentColNamePrefix + i.ToString();
                    gc.FieldName   = gc.Name;
                    gc.UnboundType = UnboundColumnType.String;
                    gc.Visible     = true;
                    gc.Width       = 30;
                }

                txtTime.Properties.Increment           = (decimal)SpawnLine.DefaultDelay;
                txtSpawnItemDelay.Properties.Increment = (decimal)SpawnLine.DefaultDelay;

                for (int i = 0; ; i++)
                {
                    string panelName = String.Format("pnlLine{0}", i + 1);
                    if (!pnlLines.Controls.ContainsKey(panelName))
                    {
                        break;
                    }

                    var pnlLine = (Panel)pnlLines.Controls[panelName];
                    _linePanels.Add(pnlLine);

                    pnlLine.AllowDrop = true;

                    pnlLine.ContextMenu = cmLinePanel;
                    pnlLine.MouseDown  += pnlLine_MouseDown;
                    pnlLine.Paint      += pnlLine_Paint;
                    pnlLine.DragEnter  += pnlLine_DragEnter;
                    pnlLine.DragDrop   += pnlLine_DragDrop;
                }

                InitTaskParamMap();

                BindSpawnItem(null);
                Text = packPath;

                string packXml = packPath.IsNullOrWhiteSpace() ? null : File.ReadAllText(packPath);
                _pack = new Pack(File.ReadAllText(levelTemplatePath), packXml, this);

                LookupUtility.Configure(repCmbTaskCategory, Pack.TaskConfig.Categories);
                LookupUtility.Configure(repCmbTaskType, Pack.TaskConfig.Types);

                GridUtility.ConfigureInstantCommit(gvTasks, repCmbTaskCategory);
                GridUtility.ConfigureInstantCommit(gvTasks, repCmbTaskType);

                ConfigureSpawnItems();

                gvAttachmentTypes.CellValueChanged += view_CellValueChanged;
                gvTasks.CellValueChanged           += view_CellValueChanged;
                gvLevelItems.CellValueChanged      += view_CellValueChanged;

                LoadLevel(true);

                // сбрасываем флаги в последнюю очередь, т.к. биндинг может привести к изменению значений
                bool isNew = packPath == null;

                IsNeedSave = isNew;
                IsNew      = isNew;
            }
            finally
            {
                EndBinding();
            }
        }
示例#36
0
    public void SetCardViewButton(Pack pack)
    {
        this.wordPack = pack;

        SetView();
    }
示例#37
0
 internal static ulong[] AsUlongs(byte[] x)
 {
     ulong[] z = new ulong[2];
     Pack.BE_To_UInt64(x, 0, z);
     return(z);
 }
示例#38
0
        /**
         * Decrypt one block of ciphertext.
         *
         * @param input the array containing the input data.
         * @param inOff offset into the in array the data starts at.
         * @param output the array the output data will be copied into.
         * @param outOff the offset into the out array the output will start at.
         */
        protected override void DecryptBlock(byte[] input, int inOff, byte[] output, int outOff)
        {
            X0 = wKey[128] ^ (int)Pack.LE_To_UInt32(input, inOff);
            X1 = wKey[129] ^ (int)Pack.LE_To_UInt32(input, inOff + 4);
            X2 = wKey[130] ^ (int)Pack.LE_To_UInt32(input, inOff + 8);
            X3 = wKey[131] ^ (int)Pack.LE_To_UInt32(input, inOff + 12);

            Ib7(X0, X1, X2, X3);
            X0 ^= wKey[124]; X1 ^= wKey[125]; X2 ^= wKey[126]; X3 ^= wKey[127];
            InverseLT(); Ib6(X0, X1, X2, X3);
            X0 ^= wKey[120]; X1 ^= wKey[121]; X2 ^= wKey[122]; X3 ^= wKey[123];
            InverseLT(); Ib5(X0, X1, X2, X3);
            X0 ^= wKey[116]; X1 ^= wKey[117]; X2 ^= wKey[118]; X3 ^= wKey[119];
            InverseLT(); Ib4(X0, X1, X2, X3);
            X0 ^= wKey[112]; X1 ^= wKey[113]; X2 ^= wKey[114]; X3 ^= wKey[115];
            InverseLT(); Ib3(X0, X1, X2, X3);
            X0 ^= wKey[108]; X1 ^= wKey[109]; X2 ^= wKey[110]; X3 ^= wKey[111];
            InverseLT(); Ib2(X0, X1, X2, X3);
            X0 ^= wKey[104]; X1 ^= wKey[105]; X2 ^= wKey[106]; X3 ^= wKey[107];
            InverseLT(); Ib1(X0, X1, X2, X3);
            X0 ^= wKey[100]; X1 ^= wKey[101]; X2 ^= wKey[102]; X3 ^= wKey[103];
            InverseLT(); Ib0(X0, X1, X2, X3);
            X0 ^= wKey[96]; X1 ^= wKey[97]; X2 ^= wKey[98]; X3 ^= wKey[99];
            InverseLT(); Ib7(X0, X1, X2, X3);
            X0 ^= wKey[92]; X1 ^= wKey[93]; X2 ^= wKey[94]; X3 ^= wKey[95];
            InverseLT(); Ib6(X0, X1, X2, X3);
            X0 ^= wKey[88]; X1 ^= wKey[89]; X2 ^= wKey[90]; X3 ^= wKey[91];
            InverseLT(); Ib5(X0, X1, X2, X3);
            X0 ^= wKey[84]; X1 ^= wKey[85]; X2 ^= wKey[86]; X3 ^= wKey[87];
            InverseLT(); Ib4(X0, X1, X2, X3);
            X0 ^= wKey[80]; X1 ^= wKey[81]; X2 ^= wKey[82]; X3 ^= wKey[83];
            InverseLT(); Ib3(X0, X1, X2, X3);
            X0 ^= wKey[76]; X1 ^= wKey[77]; X2 ^= wKey[78]; X3 ^= wKey[79];
            InverseLT(); Ib2(X0, X1, X2, X3);
            X0 ^= wKey[72]; X1 ^= wKey[73]; X2 ^= wKey[74]; X3 ^= wKey[75];
            InverseLT(); Ib1(X0, X1, X2, X3);
            X0 ^= wKey[68]; X1 ^= wKey[69]; X2 ^= wKey[70]; X3 ^= wKey[71];
            InverseLT(); Ib0(X0, X1, X2, X3);
            X0 ^= wKey[64]; X1 ^= wKey[65]; X2 ^= wKey[66]; X3 ^= wKey[67];
            InverseLT(); Ib7(X0, X1, X2, X3);
            X0 ^= wKey[60]; X1 ^= wKey[61]; X2 ^= wKey[62]; X3 ^= wKey[63];
            InverseLT(); Ib6(X0, X1, X2, X3);
            X0 ^= wKey[56]; X1 ^= wKey[57]; X2 ^= wKey[58]; X3 ^= wKey[59];
            InverseLT(); Ib5(X0, X1, X2, X3);
            X0 ^= wKey[52]; X1 ^= wKey[53]; X2 ^= wKey[54]; X3 ^= wKey[55];
            InverseLT(); Ib4(X0, X1, X2, X3);
            X0 ^= wKey[48]; X1 ^= wKey[49]; X2 ^= wKey[50]; X3 ^= wKey[51];
            InverseLT(); Ib3(X0, X1, X2, X3);
            X0 ^= wKey[44]; X1 ^= wKey[45]; X2 ^= wKey[46]; X3 ^= wKey[47];
            InverseLT(); Ib2(X0, X1, X2, X3);
            X0 ^= wKey[40]; X1 ^= wKey[41]; X2 ^= wKey[42]; X3 ^= wKey[43];
            InverseLT(); Ib1(X0, X1, X2, X3);
            X0 ^= wKey[36]; X1 ^= wKey[37]; X2 ^= wKey[38]; X3 ^= wKey[39];
            InverseLT(); Ib0(X0, X1, X2, X3);
            X0 ^= wKey[32]; X1 ^= wKey[33]; X2 ^= wKey[34]; X3 ^= wKey[35];
            InverseLT(); Ib7(X0, X1, X2, X3);
            X0 ^= wKey[28]; X1 ^= wKey[29]; X2 ^= wKey[30]; X3 ^= wKey[31];
            InverseLT(); Ib6(X0, X1, X2, X3);
            X0 ^= wKey[24]; X1 ^= wKey[25]; X2 ^= wKey[26]; X3 ^= wKey[27];
            InverseLT(); Ib5(X0, X1, X2, X3);
            X0 ^= wKey[20]; X1 ^= wKey[21]; X2 ^= wKey[22]; X3 ^= wKey[23];
            InverseLT(); Ib4(X0, X1, X2, X3);
            X0 ^= wKey[16]; X1 ^= wKey[17]; X2 ^= wKey[18]; X3 ^= wKey[19];
            InverseLT(); Ib3(X0, X1, X2, X3);
            X0 ^= wKey[12]; X1 ^= wKey[13]; X2 ^= wKey[14]; X3 ^= wKey[15];
            InverseLT(); Ib2(X0, X1, X2, X3);
            X0 ^= wKey[8]; X1 ^= wKey[9]; X2 ^= wKey[10]; X3 ^= wKey[11];
            InverseLT(); Ib1(X0, X1, X2, X3);
            X0 ^= wKey[4]; X1 ^= wKey[5]; X2 ^= wKey[6]; X3 ^= wKey[7];
            InverseLT(); Ib0(X0, X1, X2, X3);

            Pack.UInt32_To_LE((uint)(X0 ^ wKey[0]), output, outOff);
            Pack.UInt32_To_LE((uint)(X1 ^ wKey[1]), output, outOff + 4);
            Pack.UInt32_To_LE((uint)(X2 ^ wKey[2]), output, outOff + 8);
            Pack.UInt32_To_LE((uint)(X3 ^ wKey[3]), output, outOff + 12);
        }
示例#39
0
 protected virtual void GenerateKeyStream(byte[] output)
 {
     SalsaCore(rounds, engineState, x);
     Pack.UInt32_To_LE(x, output, 0);
 }
示例#40
0
 public bool Handshake()
 {
     return(Handshake(Pack.Hex(Hash), Encoding.ASCII.GetBytes(LocalPeerID)));
 }
示例#41
0
        // Token: 0x06000124 RID: 292 RVA: 0x000093FC File Offset: 0x000075FC
        private uint[][] GenerateWorkingKey(byte[] key, bool forEncryption)
        {
            int num = key.Length;

            if (num < 16 || num > 32 || (num & 7) != 0)
            {
                throw new ArgumentException("Key length not 128/192/256 bits.");
            }
            int num2 = num >> 2;

            this.ROUNDS = num2 + 6;
            uint[][] array = new uint[this.ROUNDS + 1][];
            for (int i = 0; i <= this.ROUNDS; i++)
            {
                array[i] = new uint[4];
            }
            switch (num2)
            {
            case 4:
            {
                uint num3 = Pack.LE_To_UInt32(key, 0);
                array[0][0] = num3;
                uint num4 = Pack.LE_To_UInt32(key, 4);
                array[0][1] = num4;
                uint num5 = Pack.LE_To_UInt32(key, 8);
                array[0][2] = num5;
                uint num6 = Pack.LE_To_UInt32(key, 12);
                array[0][3] = num6;
                for (int j = 1; j <= 10; j++)
                {
                    uint num7 = AesEngine.SubWord(AesEngine.Shift(num6, 8)) ^ (uint)AesEngine.rcon[j - 1];
                    num3       ^= num7;
                    array[j][0] = num3;
                    num4       ^= num3;
                    array[j][1] = num4;
                    num5       ^= num4;
                    array[j][2] = num5;
                    num6       ^= num5;
                    array[j][3] = num6;
                }
                goto IL_4EC;
            }

            case 6:
            {
                uint num8 = Pack.LE_To_UInt32(key, 0);
                array[0][0] = num8;
                uint num9 = Pack.LE_To_UInt32(key, 4);
                array[0][1] = num9;
                uint num10 = Pack.LE_To_UInt32(key, 8);
                array[0][2] = num10;
                uint num11 = Pack.LE_To_UInt32(key, 12);
                array[0][3] = num11;
                uint num12 = Pack.LE_To_UInt32(key, 16);
                array[1][0] = num12;
                uint num13 = Pack.LE_To_UInt32(key, 20);
                array[1][1] = num13;
                uint num14 = 1U;
                uint num15 = AesEngine.SubWord(AesEngine.Shift(num13, 8)) ^ num14;
                num14     <<= 1;
                num8       ^= num15;
                array[1][2] = num8;
                num9       ^= num8;
                array[1][3] = num9;
                num10      ^= num9;
                array[2][0] = num10;
                num11      ^= num10;
                array[2][1] = num11;
                num12      ^= num11;
                array[2][2] = num12;
                num13      ^= num12;
                array[2][3] = num13;
                for (int k = 3; k < 12; k += 3)
                {
                    num15           = (AesEngine.SubWord(AesEngine.Shift(num13, 8)) ^ num14);
                    num14         <<= 1;
                    num8           ^= num15;
                    array[k][0]     = num8;
                    num9           ^= num8;
                    array[k][1]     = num9;
                    num10          ^= num9;
                    array[k][2]     = num10;
                    num11          ^= num10;
                    array[k][3]     = num11;
                    num12          ^= num11;
                    array[k + 1][0] = num12;
                    num13          ^= num12;
                    array[k + 1][1] = num13;
                    num15           = (AesEngine.SubWord(AesEngine.Shift(num13, 8)) ^ num14);
                    num14         <<= 1;
                    num8           ^= num15;
                    array[k + 1][2] = num8;
                    num9           ^= num8;
                    array[k + 1][3] = num9;
                    num10          ^= num9;
                    array[k + 2][0] = num10;
                    num11          ^= num10;
                    array[k + 2][1] = num11;
                    num12          ^= num11;
                    array[k + 2][2] = num12;
                    num13          ^= num12;
                    array[k + 2][3] = num13;
                }
                num15        = (AesEngine.SubWord(AesEngine.Shift(num13, 8)) ^ num14);
                num8        ^= num15;
                array[12][0] = num8;
                num9        ^= num8;
                array[12][1] = num9;
                num10       ^= num9;
                array[12][2] = num10;
                num11       ^= num10;
                array[12][3] = num11;
                goto IL_4EC;
            }

            case 8:
            {
                uint num16 = Pack.LE_To_UInt32(key, 0);
                array[0][0] = num16;
                uint num17 = Pack.LE_To_UInt32(key, 4);
                array[0][1] = num17;
                uint num18 = Pack.LE_To_UInt32(key, 8);
                array[0][2] = num18;
                uint num19 = Pack.LE_To_UInt32(key, 12);
                array[0][3] = num19;
                uint num20 = Pack.LE_To_UInt32(key, 16);
                array[1][0] = num20;
                uint num21 = Pack.LE_To_UInt32(key, 20);
                array[1][1] = num21;
                uint num22 = Pack.LE_To_UInt32(key, 24);
                array[1][2] = num22;
                uint num23 = Pack.LE_To_UInt32(key, 28);
                array[1][3] = num23;
                uint num24 = 1U;
                uint num25;
                for (int l = 2; l < 14; l += 2)
                {
                    num25           = (AesEngine.SubWord(AesEngine.Shift(num23, 8)) ^ num24);
                    num24         <<= 1;
                    num16          ^= num25;
                    array[l][0]     = num16;
                    num17          ^= num16;
                    array[l][1]     = num17;
                    num18          ^= num17;
                    array[l][2]     = num18;
                    num19          ^= num18;
                    array[l][3]     = num19;
                    num25           = AesEngine.SubWord(num19);
                    num20          ^= num25;
                    array[l + 1][0] = num20;
                    num21          ^= num20;
                    array[l + 1][1] = num21;
                    num22          ^= num21;
                    array[l + 1][2] = num22;
                    num23          ^= num22;
                    array[l + 1][3] = num23;
                }
                num25        = (AesEngine.SubWord(AesEngine.Shift(num23, 8)) ^ num24);
                num16       ^= num25;
                array[14][0] = num16;
                num17       ^= num16;
                array[14][1] = num17;
                num18       ^= num17;
                array[14][2] = num18;
                num19       ^= num18;
                array[14][3] = num19;
                goto IL_4EC;
            }
            }
            throw new InvalidOperationException("Should never get here");
IL_4EC:
            if (!forEncryption)
            {
                for (int m = 1; m < this.ROUNDS; m++)
                {
                    uint[] array2 = array[m];
                    for (int n = 0; n < 4; n++)
                    {
                        array2[n] = AesEngine.Inv_Mcol(array2[n]);
                    }
                }
            }
            return(array);
        }
示例#42
0
 partial void InsertPack(Pack instance);
示例#43
0
 private void InsertPack(Pack pack, string xml, Guid setId)
 {
     packTable.Insert();
     packTable.PutGuid("id", pack.Id);
     packTable.PutString("name", pack.Name);
     packTable.PutGuid("setId", setId);
     packTable.PutString("xml", xml);
     packTable.Post();
 }
示例#44
0
 partial void DeletePack(Pack instance);
示例#45
0
        /**
         * Expand a user-supplied key material into a session key.
         *
         * @param key  The user-key bytes (multiples of 4) to use.
         * @exception ArgumentException
         */
        protected override int[] MakeWorkingKey(byte[] key)
        {
            //
            // pad key to 256 bits
            //
            int[] kPad   = new int[16];
            int   off    = 0;
            int   length = 0;

            for (off = 0; (off + 4) < key.Length; off += 4)
            {
                kPad[length++] = (int)Pack.LE_To_UInt32(key, off);
            }

            if (off % 4 == 0)
            {
                kPad[length++] = (int)Pack.LE_To_UInt32(key, off);
                if (length < 8)
                {
                    kPad[length] = 1;
                }
            }
            else
            {
                throw new ArgumentException("key must be a multiple of 4 bytes");
            }

            //
            // expand the padded key up to 33 x 128 bits of key material
            //
            int amount = (ROUNDS + 1) * 4;

            int[] w = new int[amount];

            //
            // compute w0 to w7 from w-8 to w-1
            //
            for (int i = 8; i < 16; i++)
            {
                kPad[i] = RotateLeft(kPad[i - 8] ^ kPad[i - 5] ^ kPad[i - 3] ^ kPad[i - 1] ^ PHI ^ (i - 8), 11);
            }

            Array.Copy(kPad, 8, w, 0, 8);

            //
            // compute w8 to w136
            //
            for (int i = 8; i < amount; i++)
            {
                w[i] = RotateLeft(w[i - 8] ^ w[i - 5] ^ w[i - 3] ^ w[i - 1] ^ PHI ^ i, 11);
            }

            //
            // create the working keys by processing w with the Sbox and IP
            //
            Sb3(w[0], w[1], w[2], w[3]);
            w[0] = X0; w[1] = X1; w[2] = X2; w[3] = X3;
            Sb2(w[4], w[5], w[6], w[7]);
            w[4] = X0; w[5] = X1; w[6] = X2; w[7] = X3;
            Sb1(w[8], w[9], w[10], w[11]);
            w[8] = X0; w[9] = X1; w[10] = X2; w[11] = X3;
            Sb0(w[12], w[13], w[14], w[15]);
            w[12] = X0; w[13] = X1; w[14] = X2; w[15] = X3;
            Sb7(w[16], w[17], w[18], w[19]);
            w[16] = X0; w[17] = X1; w[18] = X2; w[19] = X3;
            Sb6(w[20], w[21], w[22], w[23]);
            w[20] = X0; w[21] = X1; w[22] = X2; w[23] = X3;
            Sb5(w[24], w[25], w[26], w[27]);
            w[24] = X0; w[25] = X1; w[26] = X2; w[27] = X3;
            Sb4(w[28], w[29], w[30], w[31]);
            w[28] = X0; w[29] = X1; w[30] = X2; w[31] = X3;
            Sb3(w[32], w[33], w[34], w[35]);
            w[32] = X0; w[33] = X1; w[34] = X2; w[35] = X3;
            Sb2(w[36], w[37], w[38], w[39]);
            w[36] = X0; w[37] = X1; w[38] = X2; w[39] = X3;
            Sb1(w[40], w[41], w[42], w[43]);
            w[40] = X0; w[41] = X1; w[42] = X2; w[43] = X3;
            Sb0(w[44], w[45], w[46], w[47]);
            w[44] = X0; w[45] = X1; w[46] = X2; w[47] = X3;
            Sb7(w[48], w[49], w[50], w[51]);
            w[48] = X0; w[49] = X1; w[50] = X2; w[51] = X3;
            Sb6(w[52], w[53], w[54], w[55]);
            w[52] = X0; w[53] = X1; w[54] = X2; w[55] = X3;
            Sb5(w[56], w[57], w[58], w[59]);
            w[56] = X0; w[57] = X1; w[58] = X2; w[59] = X3;
            Sb4(w[60], w[61], w[62], w[63]);
            w[60] = X0; w[61] = X1; w[62] = X2; w[63] = X3;
            Sb3(w[64], w[65], w[66], w[67]);
            w[64] = X0; w[65] = X1; w[66] = X2; w[67] = X3;
            Sb2(w[68], w[69], w[70], w[71]);
            w[68] = X0; w[69] = X1; w[70] = X2; w[71] = X3;
            Sb1(w[72], w[73], w[74], w[75]);
            w[72] = X0; w[73] = X1; w[74] = X2; w[75] = X3;
            Sb0(w[76], w[77], w[78], w[79]);
            w[76] = X0; w[77] = X1; w[78] = X2; w[79] = X3;
            Sb7(w[80], w[81], w[82], w[83]);
            w[80] = X0; w[81] = X1; w[82] = X2; w[83] = X3;
            Sb6(w[84], w[85], w[86], w[87]);
            w[84] = X0; w[85] = X1; w[86] = X2; w[87] = X3;
            Sb5(w[88], w[89], w[90], w[91]);
            w[88] = X0; w[89] = X1; w[90] = X2; w[91] = X3;
            Sb4(w[92], w[93], w[94], w[95]);
            w[92] = X0; w[93] = X1; w[94] = X2; w[95] = X3;
            Sb3(w[96], w[97], w[98], w[99]);
            w[96] = X0; w[97] = X1; w[98] = X2; w[99] = X3;
            Sb2(w[100], w[101], w[102], w[103]);
            w[100] = X0; w[101] = X1; w[102] = X2; w[103] = X3;
            Sb1(w[104], w[105], w[106], w[107]);
            w[104] = X0; w[105] = X1; w[106] = X2; w[107] = X3;
            Sb0(w[108], w[109], w[110], w[111]);
            w[108] = X0; w[109] = X1; w[110] = X2; w[111] = X3;
            Sb7(w[112], w[113], w[114], w[115]);
            w[112] = X0; w[113] = X1; w[114] = X2; w[115] = X3;
            Sb6(w[116], w[117], w[118], w[119]);
            w[116] = X0; w[117] = X1; w[118] = X2; w[119] = X3;
            Sb5(w[120], w[121], w[122], w[123]);
            w[120] = X0; w[121] = X1; w[122] = X2; w[123] = X3;
            Sb4(w[124], w[125], w[126], w[127]);
            w[124] = X0; w[125] = X1; w[126] = X2; w[127] = X3;
            Sb3(w[128], w[129], w[130], w[131]);
            w[128] = X0; w[129] = X1; w[130] = X2; w[131] = X3;

            return(w);
        }
示例#46
0
        public bool SendKeepAlive()
        {
            var sent = Socket.Send(Pack.Int32(0));

            return(sent == 4);
        }
 public FileDefault(Pack pack, FileCommonHeader header)
     : base(pack, header)
 {
 }
示例#48
0
        public static void FindVdsDisk(string serverName, int driveNumber, out AdvancedDisk advancedDisk, out Pack diskPack)
        {
            Func <Disk, bool> compareFunc = disk => disk.Name.EndsWith("PhysicalDrive" + driveNumber);

            FindVdsDisk(serverName, compareFunc, out advancedDisk, out diskPack);
        }
示例#49
0
 partial void UpdatePack(Pack instance);
示例#50
0
 internal static byte[] AsBytes(uint[] x)
 {
     return(Pack.UInt32_To_BE(x));
 }
示例#51
0
	private void attach_Packs(Pack entity)
	{
		this.SendPropertyChanging();
		entity.Donation = this;
	}
示例#52
0
 internal static byte[] AsBytes(ulong[] x)
 {
     byte[] z = new byte[16];
     Pack.UInt64_To_BE(x, z, 0);
     return(z);
 }
示例#53
0
 partial void OnStatusChanging(Pack.StatusX value);
示例#54
0
 internal static void AsBytes(ulong[] x, byte[] z)
 {
     Pack.UInt64_To_BE(x, z, 0);
 }
示例#55
0
	private void detach_Packs(Pack entity)
	{
		this.SendPropertyChanging();
		entity.Product = null;
	}
示例#56
0
 internal static uint[] AsUints(byte[] bs)
 {
     uint[] output = new uint[4];
     Pack.BE_To_UInt32(bs, 0, output);
     return(output);
 }
示例#57
0
        //Only pack has status 0 can be remove, to re-assign to another people.
        public static Pack RemovePeople(int autonum)
        {
            if (autonum == 0) return null;

            RedBloodDataContext db = new RedBloodDataContext();

            //Pack p = Get(db, autonum, Pack.StatusX.Collected);
            Pack p = new Pack();

            //if (p == null && p.PeopleID != null) return p;
            //if (p.TestResultStatus != Pack.TestResultStatusX.Non) return p;

            ////remove people
            //p.PeopleID = null;
            //p.CollectedDate = null;
            //p.CampaignID = null;

            //PackStatusHistory h = ChangeStatus(db, p, Pack.StatusX.Init, "Remove peopleID=" + p.PeopleID.ToString() + "&CampaignID=" + p.CampaignID.ToString());
            //db.PackStatusHistories.InsertOnSubmit(h);

            db.SubmitChanges();

            return p;
        }
示例#58
0
 internal static void AsUints(byte[] bs, uint[] output)
 {
     Pack.BE_To_UInt32(bs, 0, output);
 }
示例#59
0
 internal static void AsBytes(uint[] x, byte[] z)
 {
     Pack.UInt32_To_BE(x, z, 0);
 }
示例#60
0
        public static MountedDiskInfo GetMountedDiskInfo(string serverName, int driveNumber)
        {
            MountedDiskInfo diskInfo = new MountedDiskInfo {
                DiskNumber = driveNumber
            };

            // find mounted disk using VDS
            AdvancedDisk advancedDisk = null;
            Pack         diskPack     = null;

            // first attempt
            Thread.Sleep(3000);
            HostedSolutionLog.LogInfo("Trying to find mounted disk - first attempt");
            FindVdsDisk(serverName, diskInfo.DiskNumber, out advancedDisk, out diskPack);

            // second attempt
            if (advancedDisk == null)
            {
                Thread.Sleep(20000);
                HostedSolutionLog.LogInfo("Trying to find mounted disk - second attempt");
                FindVdsDisk(serverName, diskInfo.DiskNumber, out advancedDisk, out diskPack);
            }

            if (advancedDisk == null)
            {
                throw new Exception("Could not find mounted disk");
            }

            // Set disk address
            diskInfo.DiskAddress = advancedDisk.DiskAddress;
            var addressParts = diskInfo.DiskAddress.ParseExact("Port{0}Path{1}Target{2}Lun{3}");
            var portNumber   = addressParts[0];
            var targetId     = addressParts[2];
            var lun          = addressParts[3];

            // check if DiskPart must be used to bring disk online and clear read-only flag
            bool useDiskPartToClearReadOnly = false;

            if (ConfigurationManager.AppSettings[Constants.CONFIG_USE_DISKPART_TO_CLEAR_READONLY_FLAG] != null)
            {
                useDiskPartToClearReadOnly = Boolean.Parse(ConfigurationManager.AppSettings[Constants.CONFIG_USE_DISKPART_TO_CLEAR_READONLY_FLAG]);
            }

            // determine disk index for DiskPart
            Wmi cimv2 = new Wmi(serverName, Constants.WMI_CIMV2_NAMESPACE);
            ManagementObject objDisk = cimv2.GetWmiObject("win32_diskdrive",
                                                          "Model='Msft Virtual Disk SCSI Disk Device' and ScsiTargetID={0} and ScsiLogicalUnit={1} and scsiPort={2}",
                                                          targetId, lun, portNumber);

            if (useDiskPartToClearReadOnly)
            {
                // *** Clear Read-Only and bring disk online with DiskPart ***
                HostedSolutionLog.LogInfo("Clearing disk Read-only flag and bringing disk online");

                if (objDisk != null)
                {
                    // disk found
                    // run DiskPart
                    string diskPartResult = RunDiskPart(serverName, String.Format(@"select disk {0}
attributes disk clear readonly
online disk
exit", Convert.ToInt32(objDisk["Index"])));

                    HostedSolutionLog.LogInfo("DiskPart Result: " + diskPartResult);
                }
            }
            else
            {
                // *** Clear Read-Only and bring disk online with VDS ***
                // clear Read-Only
                if ((advancedDisk.Flags & DiskFlags.ReadOnly) == DiskFlags.ReadOnly)
                {
                    HostedSolutionLog.LogInfo("Clearing disk Read-only flag");
                    advancedDisk.ClearFlags(DiskFlags.ReadOnly);
                    while ((advancedDisk.Flags & DiskFlags.ReadOnly) == DiskFlags.ReadOnly)
                    {
                        Thread.Sleep(100);
                        advancedDisk.Refresh();
                    }
                }

                // bring disk ONLINE
                if (advancedDisk.Status == DiskStatus.Offline)
                {
                    HostedSolutionLog.LogInfo("Bringing disk online");
                    advancedDisk.Online();
                    while (advancedDisk.Status == DiskStatus.Offline)
                    {
                        Thread.Sleep(100);
                        advancedDisk.Refresh();
                    }
                }
            }

            // small pause after getting disk online
            Thread.Sleep(3000);

            // get disk again
            FindVdsDisk(serverName, diskInfo.DiskNumber, out advancedDisk, out diskPack);

            // find volumes using VDS
            List <string> volumes = new List <string>();

            HostedSolutionLog.LogInfo("Querying disk volumes with VDS");
            foreach (Volume volume in diskPack.Volumes)
            {
                string letter = volume.DriveLetter.ToString();
                if (letter != "")
                {
                    volumes.Add(letter);
                }
            }

            // find volumes using WMI
            if (volumes.Count == 0 && objDisk != null)
            {
                HostedSolutionLog.LogInfo("Querying disk volumes with WMI");
                foreach (ManagementObject objPartition in objDisk.GetRelated("Win32_DiskPartition"))
                {
                    foreach (ManagementObject objVolume in objPartition.GetRelated("Win32_LogicalDisk"))
                    {
                        volumes.Add(objVolume["Name"].ToString().TrimEnd(':'));
                    }
                }
            }

            HostedSolutionLog.LogInfo("Volumes found: " + volumes.Count);

            // Set volumes
            diskInfo.DiskVolumes = volumes.ToArray();

            return(diskInfo);
        }