Пример #1
0
 protected ContentHasherTests()
 {
     _hashInfo = GetBuiltInHashInfo(typeof(T));
 }
Пример #2
0
        /// <summary>
        /// Starts key exchange algorithm
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="message">Key exchange init message.</param>
        public virtual void Start(Session session, KeyExchangeInitMessage message)
        {
            this.Session = session;

            this.SendMessage(session.ClientInitMessage);

            //  Determine encryption algorithm
            var clientEncryptionAlgorithmName = (from b in session.ConnectionInfo.Encryptions.Keys
                                                 from a in message.EncryptionAlgorithmsClientToServer
                                                 where a == b
                                                 select a).FirstOrDefault();

            if (string.IsNullOrEmpty(clientEncryptionAlgorithmName))
            {
                throw new SshConnectionException("Client encryption algorithm not found", DisconnectReason.KeyExchangeFailed);
            }

            session.ConnectionInfo.CurrentClientEncryption = clientEncryptionAlgorithmName;

            //  Determine encryption algorithm
            var serverDecryptionAlgorithmName = (from b in session.ConnectionInfo.Encryptions.Keys
                                                 from a in message.EncryptionAlgorithmsServerToClient
                                                 where a == b
                                                 select a).FirstOrDefault();
            if (string.IsNullOrEmpty(serverDecryptionAlgorithmName))
            {
                throw new SshConnectionException("Server decryption algorithm not found", DisconnectReason.KeyExchangeFailed);
            }

            session.ConnectionInfo.CurrentServerEncryption = serverDecryptionAlgorithmName;

            //  Determine client hmac algorithm
            var clientHmacAlgorithmName = (from b in session.ConnectionInfo.HmacAlgorithms.Keys
                                           from a in message.MacAlgorithmsClientToServer
                                           where a == b
                                           select a).FirstOrDefault();
            if (string.IsNullOrEmpty(clientHmacAlgorithmName))
            {
                throw new SshConnectionException("Server HMAC algorithm not found", DisconnectReason.KeyExchangeFailed);
            }

            session.ConnectionInfo.CurrentClientHmacAlgorithm = clientHmacAlgorithmName;

            //  Determine server hmac algorithm
            var serverHmacAlgorithmName = (from b in session.ConnectionInfo.HmacAlgorithms.Keys
                                           from a in message.MacAlgorithmsServerToClient
                                           where a == b
                                           select a).FirstOrDefault();
            if (string.IsNullOrEmpty(serverHmacAlgorithmName))
            {
                throw new SshConnectionException("Server HMAC algorithm not found", DisconnectReason.KeyExchangeFailed);
            }

            session.ConnectionInfo.CurrentServerHmacAlgorithm = serverHmacAlgorithmName;

            //  Determine compression algorithm
            var compressionAlgorithmName = (from b in session.ConnectionInfo.CompressionAlgorithms.Keys
                                            from a in message.CompressionAlgorithmsClientToServer
                                            where a == b
                                            select a).LastOrDefault();
            if (string.IsNullOrEmpty(compressionAlgorithmName))
            {
                throw new SshConnectionException("Compression algorithm not found", DisconnectReason.KeyExchangeFailed);
            }

            session.ConnectionInfo.CurrentClientCompressionAlgorithm = compressionAlgorithmName;

            //  Determine decompression algorithm
            var decompressionAlgorithmName = (from b in session.ConnectionInfo.CompressionAlgorithms.Keys
                                              from a in message.CompressionAlgorithmsServerToClient
                                              where a == b
                                              select a).LastOrDefault();
            if (string.IsNullOrEmpty(decompressionAlgorithmName))
            {
                throw new SshConnectionException("Decompression algorithm not found", DisconnectReason.KeyExchangeFailed);
            }

            session.ConnectionInfo.CurrentServerCompressionAlgorithm = decompressionAlgorithmName;

            this._clientCipherInfo = session.ConnectionInfo.Encryptions[clientEncryptionAlgorithmName];
            this._serverCipherInfo = session.ConnectionInfo.Encryptions[serverDecryptionAlgorithmName];
            this._clientHashInfo = session.ConnectionInfo.HmacAlgorithms[clientHmacAlgorithmName];
            this._serverHashInfo = session.ConnectionInfo.HmacAlgorithms[serverHmacAlgorithmName];
            this._compressionType = session.ConnectionInfo.CompressionAlgorithms[compressionAlgorithmName];
            this._decompressionType = session.ConnectionInfo.CompressionAlgorithms[decompressionAlgorithmName];
        }
Пример #3
0
 public void HashStatusUpdate(HashInfo info)
 {
     Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] (HASH SERVER)  [{info.MaskedAPIKey}] in last 1 minute  {info.Last60MinAPICalles} request/min , AVG: {info.Last60MinAPIAvgTime:0.00} ms/request , Fastest : {info.Fastest}, Slowest: {info.Slowest}");
 }
Пример #4
0
 /// <summary>
 /// Disposes the hasher to save on memory when the server mode process runs
 /// </summary>
 public static void DisposeAndResetHasher()
 {
     s_hasher?.Dispose();
     s_hasher = HashInfo.CreateContentHasher();
 }
Пример #5
0
  /// <summary>
  /// System, welche die FehlerMapErstellen erstellt
  /// </summary>
  /// <param name="würfel">Anzahl der zu testenden Würfel (muss immer weniger sein als die Ziel-Anzahl)</param>
  void FehlerMapErstellen(int würfel)
  {
   int[] kannFelder = Enumerable.Range(0, feldAnzahl).Where(pos => erlaubteBoxFelder[pos]).ToArray();
   var ofss = new[] { -1, +1, -feldBreite, +feldBreite };

   switch (würfel)
   {
    #region # case 1: // --- einzelne unerlaubte Boxen ermitteln ---
    case 1:
    {
     Dictionary<int, bool> spielerFertig = kannFelder.ToDictionary(p => p, p => false);

     foreach (int boxPos in kannFelder)
     {
      List<int> spielerGut = new List<int>();
      List<int> spielerSchlecht = new List<int>();

      foreach (int p in kannFelder) spielerFertig[p] = false;

      MapReset(true);
      feldData[boxPos] ^= 2;
      spielerFertig[boxPos] = true;

      foreach (int spielerPos in kannFelder.Where(pos => !spielerFertig[pos]))
      {
       #region # // --- Spieler setzen und Hash resetten ---
       feldData[spielerPos] ^= 8;
       HashFeld hashFeld = new HashFeld(0, feldData, true);
       hashIndex.Clear();
       hashGro = hashSatzGro;
       feldData[spielerPos] ^= 8;
       #endregion

       #region # // --- prüfen, ob Stellung gelöst werden kann ---
       bool find = false;

       for (int hashPos = 0; hashPos < hashGro; hashPos += hashSatzGro)
       {
        hashFeld = new HashFeld(hashPos);

        if (hashFeld.RestWürfel == 0) // machbare Lösung gefunden?
        {
         find = true;
         break;
        }

        if (hashGro > hashInfoMax * hashSatzGro)
        {
         hashInfoMax *= 2;
         Array.Resize(ref hashInfo, hashInfoMax + 65536);
        }

        if (hashFeld.KannLinks)
        {
         HashFeld neuHash = new HashFeld(hashGro);
         hashInfo[hashGro / hashSatzGro] = new HashInfo(hashPos, hashFeld.BewegeLinks(neuHash));
         if (!HashBekannt(neuHash)) hashGro += hashSatzGro;
        }

        if (hashFeld.KannRechts)
        {
         HashFeld neuHash = new HashFeld(hashGro);
         hashInfo[hashGro / hashSatzGro] = new HashInfo(hashPos, hashFeld.BewegeRechts(neuHash));
         if (!HashBekannt(neuHash)) hashGro += hashSatzGro;
        }

        if (hashFeld.KannOben)
        {
         HashFeld neuHash = new HashFeld(hashGro);
         hashInfo[hashGro / hashSatzGro] = new HashInfo(hashPos, hashFeld.BewegeOben(neuHash));
         if (!HashBekannt(neuHash)) hashGro += hashSatzGro;
        }

        if (hashFeld.KannUnten)
        {
         HashFeld neuHash = new HashFeld(hashGro);
         hashInfo[hashGro / hashSatzGro] = new HashInfo(hashPos, hashFeld.BewegeUnten(neuHash));
         if (!HashBekannt(neuHash)) hashGro += hashSatzGro;
        }
       }
       #endregion

       #region # // --- alle zusätzlich erreichbare Spielerpositionen ermitteln ---
       List<int> alleSpielerPos = new List<int>();
       alleSpielerPos.Add(spielerPos); spielerFertig[spielerPos] = true;
       for (int i = 0; i < alleSpielerPos.Count; i++)
       {
        int checkPos = alleSpielerPos[i];
        foreach (int ofs in ofss)
        {
         if ((feldData[checkPos + ofs] & 3) == 0 && !alleSpielerPos.Any(p => p == checkPos + ofs))
         {
          alleSpielerPos.Add(checkPos + ofs);
          if (erlaubteBoxFelder[checkPos + ofs]) spielerFertig[checkPos + ofs] = true;
         }
        }
       }
       #endregion

       if (find)
       {
        spielerGut.AddRange(alleSpielerPos);
       }
       else
       {
        spielerSchlecht.AddRange(alleSpielerPos);
        hashGro = 0;
        hashIndex.Clear();
       }

      }

      if (spielerGut.Count == 0) erlaubteBoxFelder[boxPos] = false;
     }

     FehlerDataInit();
    } break;
    #endregion

    #region # case 2: // --- unerlaubte Zweier-Kombinationen der Boxen ermitteln ---
    case 2:
    {
     Dictionary<int, bool> spielerFertig = kannFelder.ToDictionary(p => p, p => false);

     MapReset(true);

     for (int p1 = 0; p1 < kannFelder.Length; p1++)
     {
      int boxPos1 = kannFelder[p1];
      feldData[boxPos1] ^= 2;

      feldZeichner.Zeichne(pictureBox1, feldData); Application.DoEvents();

      for (int p2 = p1 + 1; p2 < kannFelder.Length; p2++)
      {
       int boxPos2 = kannFelder[p2];
       feldData[boxPos2] ^= 2;

       List<int> spielerGut = new List<int>();
       List<int> spielerSchlecht = new List<int>();

       foreach (int p in kannFelder) spielerFertig[p] = false;

       spielerFertig[boxPos1] = true;
       spielerFertig[boxPos2] = true;

       foreach (int spielerPos in kannFelder.Where(pos => !spielerFertig[pos]))
       {
        #region # // --- Spieler setzen und Hash resetten ---
        feldData[spielerPos] ^= 8;
        HashFeld hashFeld = new HashFeld(0, feldData, true);
        hashIndex.Clear();
        hashGro = hashSatzGro;
        feldData[spielerPos] ^= 8;
        #endregion

        #region # // --- prüfen, ob Stellung gelöst werden kann ---
        bool find = false;

        for (int hashPos = 0; hashPos < hashGro; hashPos += hashSatzGro)
        {
         hashFeld = new HashFeld(hashPos);

         if (hashFeld.RestWürfel == 0) // machbare Lösung gefunden?
         {
          find = true;
          break;
         }

         if (hashGro > hashInfoMax * hashSatzGro)
         {
          hashInfoMax *= 2;
          Array.Resize(ref hashInfo, hashInfoMax + 65536);
         }

         if (hashFeld.KannLinks)
         {
          HashFeld neuHash = new HashFeld(hashGro);
          hashInfo[hashGro / hashSatzGro] = new HashInfo(hashPos, hashFeld.BewegeLinks(neuHash));
          if (!HashBekannt(neuHash)) hashGro += hashSatzGro;
         }

         if (hashFeld.KannRechts)
         {
          HashFeld neuHash = new HashFeld(hashGro);
          hashInfo[hashGro / hashSatzGro] = new HashInfo(hashPos, hashFeld.BewegeRechts(neuHash));
          if (!HashBekannt(neuHash)) hashGro += hashSatzGro;
         }

         if (hashFeld.KannOben)
         {
          HashFeld neuHash = new HashFeld(hashGro);
          hashInfo[hashGro / hashSatzGro] = new HashInfo(hashPos, hashFeld.BewegeOben(neuHash));
          if (!HashBekannt(neuHash)) hashGro += hashSatzGro;
         }

         if (hashFeld.KannUnten)
         {
          HashFeld neuHash = new HashFeld(hashGro);
          hashInfo[hashGro / hashSatzGro] = new HashInfo(hashPos, hashFeld.BewegeUnten(neuHash));
          if (!HashBekannt(neuHash)) hashGro += hashSatzGro;
         }
        }
        #endregion

        #region # // --- alle zusätzlich erreichbare Spielerpositionen ermitteln ---
        List<int> alleSpielerPos = new List<int>();
        alleSpielerPos.Add(spielerPos); spielerFertig[spielerPos] = true;
        for (int i = 0; i < alleSpielerPos.Count; i++)
        {
         int checkPos = alleSpielerPos[i];
         foreach (int ofs in ofss)
         {
          if ((feldData[checkPos + ofs] & 3) == 0 && !alleSpielerPos.Any(p => p == checkPos + ofs))
          {
           alleSpielerPos.Add(checkPos + ofs);
           if (erlaubteBoxFelder[checkPos + ofs]) spielerFertig[checkPos + ofs] = true;
          }
         }
        }
        #endregion

        if (find)
        {
         spielerGut.AddRange(alleSpielerPos);
        }
        else
        {
         spielerSchlecht.AddRange(alleSpielerPos);
        }
       }

       if (spielerGut.Count == 0 || spielerSchlecht.Count > 0)
       {
        #region # // --- Box 1 -> Box 2 ---
        List<short> dazu = new List<short>();

        dazu.Add((short)boxPos2);
        if (spielerGut.Count < spielerSchlecht.Count) // nur die guten Felder merken?
        {
         dazu.Add((short)spielerGut.Count);
         dazu.AddRange(spielerGut.Select(pos => (short)pos));
        }
        else // nur die schlechten Felder merken (da weniger)
        {
         dazu.Add((short)-spielerSchlecht.Count);
         dazu.AddRange(spielerSchlecht.Select(pos => (short)pos));
        }

        FehlerDataUpdate(ref fehlerBox2[boxPos1], dazu);
        fehlerVorhanden[boxPos1] |= 1;
        #endregion

        #region # // --- Box 2 -> Box 1 ---
        dazu.Clear();

        dazu.Add((short)boxPos1);
        if (spielerGut.Count < spielerSchlecht.Count) // nur die guten Felder merken?
        {
         dazu.Add((short)spielerGut.Count);
         dazu.AddRange(spielerGut.Select(pos => (short)pos));
        }
        else // nur die schlechten Felder merken (da weniger)
        {
         dazu.Add((short)-spielerSchlecht.Count);
         dazu.AddRange(spielerSchlecht.Select(pos => (short)pos));
        }

        FehlerDataUpdate(ref fehlerBox2[boxPos2], dazu);
        fehlerVorhanden[boxPos2] |= 1;
        #endregion
       }

       feldData[boxPos2] ^= 2;
      }
      feldData[boxPos1] ^= 2;
     }
    } break;
    #endregion

    #region # case 3: // --- unerlaubte Dreier-Kombinationen der Boxen ermitteln ---
    case 3:
    {
     Dictionary<int, bool> spielerFertig = kannFelder.ToDictionary(p => p, p => false);

     MapReset(true);

     for (int p1 = 0; p1 < kannFelder.Length; p1++)
     {
      int boxPos1 = kannFelder[p1];
      int boxPos1x = boxPos1 % feldBreite;
      int boxPos1y = boxPos1 / feldBreite;
      feldData[boxPos1] ^= 2;

      for (int p2 = p1 + 1; p2 < kannFelder.Length; p2++)
      {
       int boxPos2 = kannFelder[p2];
       if (FehlerCheckDirekt(boxPos2)) continue;
       int boxPos2x = boxPos2 % feldBreite;
       int boxPos2y = boxPos2 / feldBreite;
       if (Math.Abs(boxPos2x - boxPos1x) > 2) continue;
       if (Math.Abs(boxPos2y - boxPos1y) > 2) continue;

       feldData[boxPos2] ^= 2;

       feldZeichner.Zeichne(pictureBox1, feldData); Application.DoEvents();

       for (int p3 = p2 + 1; p3 < kannFelder.Length; p3++)
       {
        int boxPos3 = kannFelder[p3];
        if (FehlerCheckDirekt(boxPos3)) continue;
        int boxPos3x = boxPos3 % feldBreite;
        int boxPos3y = boxPos3 / feldBreite;
        if (Math.Abs(boxPos3x - boxPos2x) > 2 && Math.Abs(boxPos3x - boxPos1x) > 2) continue;
        if (Math.Abs(boxPos3y - boxPos2y) > 2 && Math.Abs(boxPos3y - boxPos1y) > 2) continue;

        feldData[boxPos3] ^= 2;

        List<int> spielerGut = new List<int>();
        List<int> spielerSchlecht = new List<int>();

        foreach (int p in kannFelder) spielerFertig[p] = false;

        spielerFertig[boxPos1] = true;
        spielerFertig[boxPos2] = true;
        spielerFertig[boxPos3] = true;

        foreach (int spielerPos in kannFelder.Where(pos => !spielerFertig[pos]))
        {
         #region # // --- Spieler setzen und Hash resetten ---
         feldData[spielerPos] ^= 8;
         HashFeld hashFeld = new HashFeld(0, feldData, true);
         hashIndex.Clear();
         hashGro = hashSatzGro;
         feldData[spielerPos] ^= 8;
         #endregion

         #region # // --- prüfen, ob Stellung gelöst werden kann ---
         bool find = false;

         for (int hashPos = 0; hashPos < hashGro; hashPos += hashSatzGro)
         {
          hashFeld = new HashFeld(hashPos);

          if (hashFeld.RestWürfel == 0) // machbare Lösung gefunden?
          {
           find = true;
           break;
          }

          if (hashGro > hashInfoMax * hashSatzGro)
          {
           hashInfoMax *= 2;
           Array.Resize(ref hashInfo, hashInfoMax + 65536);
          }

          if (hashFeld.KannLinks)
          {
           HashFeld neuHash = new HashFeld(hashGro);
           hashInfo[hashGro / hashSatzGro] = new HashInfo(hashPos, hashFeld.BewegeLinks(neuHash));
           if (!HashBekannt(neuHash)) hashGro += hashSatzGro;
          }

          if (hashFeld.KannRechts)
          {
           HashFeld neuHash = new HashFeld(hashGro);
           hashInfo[hashGro / hashSatzGro] = new HashInfo(hashPos, hashFeld.BewegeRechts(neuHash));
           if (!HashBekannt(neuHash)) hashGro += hashSatzGro;
          }

          if (hashFeld.KannOben)
          {
           HashFeld neuHash = new HashFeld(hashGro);
           hashInfo[hashGro / hashSatzGro] = new HashInfo(hashPos, hashFeld.BewegeOben(neuHash));
           if (!HashBekannt(neuHash)) hashGro += hashSatzGro;
          }

          if (hashFeld.KannUnten)
          {
           HashFeld neuHash = new HashFeld(hashGro);
           hashInfo[hashGro / hashSatzGro] = new HashInfo(hashPos, hashFeld.BewegeUnten(neuHash));
           if (!HashBekannt(neuHash)) hashGro += hashSatzGro;
          }
         }
         #endregion

         #region # // --- alle zusätzlich erreichbare Spielerpositionen ermitteln ---
         List<int> alleSpielerPos = new List<int>();
         alleSpielerPos.Add(spielerPos); spielerFertig[spielerPos] = true;
         for (int i = 0; i < alleSpielerPos.Count; i++)
         {
          int checkPos = alleSpielerPos[i];
          foreach (int ofs in ofss)
          {
           if ((feldData[checkPos + ofs] & 3) == 0 && !alleSpielerPos.Any(p => p == checkPos + ofs))
           {
            alleSpielerPos.Add(checkPos + ofs);
            if (erlaubteBoxFelder[checkPos + ofs]) spielerFertig[checkPos + ofs] = true;
           }
          }
         }
         #endregion

         if (find)
         {
          spielerGut.AddRange(alleSpielerPos);
         }
         else
         {
          spielerSchlecht.AddRange(alleSpielerPos);
         }
        }

        if (spielerGut.Count == 0 || spielerSchlecht.Count > 0)
        {
         #region # // --- Box 1 -> Box 2 + 3 ---
         List<short> dazu = new List<short>();

         dazu.Add((short)boxPos2);
         dazu.Add((short)boxPos3);
         if (spielerGut.Count < spielerSchlecht.Count) // nur die guten Felder merken?
         {
          dazu.Add((short)spielerGut.Count);
          dazu.AddRange(spielerGut.Select(pos => (short)pos));
         }
         else // nur die schlechten Felder merken (da weniger)
         {
          dazu.Add((short)-spielerSchlecht.Count);
          dazu.AddRange(spielerSchlecht.Select(pos => (short)pos));
         }

         FehlerDataUpdate(ref fehlerBox3[boxPos1], dazu);
         fehlerVorhanden[boxPos1] |= 1;
         #endregion

         #region # // --- Box 2 -> Box 1 + 3 ---
         dazu.Clear();

         dazu.Add((short)boxPos1);
         dazu.Add((short)boxPos3);
         if (spielerGut.Count < spielerSchlecht.Count) // nur die guten Felder merken?
         {
          dazu.Add((short)spielerGut.Count);
          dazu.AddRange(spielerGut.Select(pos => (short)pos));
         }
         else // nur die schlechten Felder merken (da weniger)
         {
          dazu.Add((short)-spielerSchlecht.Count);
          dazu.AddRange(spielerSchlecht.Select(pos => (short)pos));
         }

         FehlerDataUpdate(ref fehlerBox3[boxPos2], dazu);
         fehlerVorhanden[boxPos2] |= 1;
         #endregion

         #region # // --- Box 3 -> Box 1 + 2 ---
         dazu.Clear();

         dazu.Add((short)boxPos1);
         dazu.Add((short)boxPos2);
         if (spielerGut.Count < spielerSchlecht.Count) // nur die guten Felder merken?
         {
          dazu.Add((short)spielerGut.Count);
          dazu.AddRange(spielerGut.Select(pos => (short)pos));
         }
         else // nur die schlechten Felder merken (da weniger)
         {
          dazu.Add((short)-spielerSchlecht.Count);
          dazu.AddRange(spielerSchlecht.Select(pos => (short)pos));
         }

         FehlerDataUpdate(ref fehlerBox3[boxPos3], dazu);
         fehlerVorhanden[boxPos3] |= 1;
         #endregion
        }

        feldData[boxPos3] ^= 2;
       }

       feldData[boxPos2] ^= 2;
      }

      feldData[boxPos1] ^= 2;
     }
    } break;
    #endregion

    default: throw new NotSupportedException();
   }

  }
Пример #6
0
        /// <summary>
        /// Starts key exchange algorithm
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="message">Key exchange init message.</param>
        public virtual void Start(Session session, KeyExchangeInitMessage message)
        {
            Session = session;

            SendMessage(session.ClientInitMessage);

            //  Determine encryption algorithm
            var clientEncryptionAlgorithmName = (from b in session.ConnectionInfo.Encryptions.Keys
                                                 from a in message.EncryptionAlgorithmsClientToServer
                                                 where a == b
                                                 select a).FirstOrDefault();

            if (string.IsNullOrEmpty(clientEncryptionAlgorithmName))
            {
                throw new SshConnectionException("Client encryption algorithm not found", DisconnectReason.KeyExchangeFailed);
            }

            session.ConnectionInfo.CurrentClientEncryption = clientEncryptionAlgorithmName;

            //  Determine encryption algorithm
            var serverDecryptionAlgorithmName = (from b in session.ConnectionInfo.Encryptions.Keys
                                                 from a in message.EncryptionAlgorithmsServerToClient
                                                 where a == b
                                                 select a).FirstOrDefault();

            if (string.IsNullOrEmpty(serverDecryptionAlgorithmName))
            {
                throw new SshConnectionException("Server decryption algorithm not found", DisconnectReason.KeyExchangeFailed);
            }

            session.ConnectionInfo.CurrentServerEncryption = serverDecryptionAlgorithmName;

            //  Determine client hmac algorithm
            var clientHmacAlgorithmName = (from b in session.ConnectionInfo.HmacAlgorithms.Keys
                                           from a in message.MacAlgorithmsClientToServer
                                           where a == b
                                           select a).FirstOrDefault();

            if (string.IsNullOrEmpty(clientHmacAlgorithmName))
            {
                throw new SshConnectionException("Server HMAC algorithm not found", DisconnectReason.KeyExchangeFailed);
            }

            session.ConnectionInfo.CurrentClientHmacAlgorithm = clientHmacAlgorithmName;

            //  Determine server hmac algorithm
            var serverHmacAlgorithmName = (from b in session.ConnectionInfo.HmacAlgorithms.Keys
                                           from a in message.MacAlgorithmsServerToClient
                                           where a == b
                                           select a).FirstOrDefault();

            if (string.IsNullOrEmpty(serverHmacAlgorithmName))
            {
                throw new SshConnectionException("Server HMAC algorithm not found", DisconnectReason.KeyExchangeFailed);
            }

            session.ConnectionInfo.CurrentServerHmacAlgorithm = serverHmacAlgorithmName;

            //  Determine compression algorithm
            var compressionAlgorithmName = (from b in session.ConnectionInfo.CompressionAlgorithms.Keys
                                            from a in message.CompressionAlgorithmsClientToServer
                                            where a == b
                                            select a).LastOrDefault();

            if (string.IsNullOrEmpty(compressionAlgorithmName))
            {
                throw new SshConnectionException("Compression algorithm not found", DisconnectReason.KeyExchangeFailed);
            }

            session.ConnectionInfo.CurrentClientCompressionAlgorithm = compressionAlgorithmName;

            //  Determine decompression algorithm
            var decompressionAlgorithmName = (from b in session.ConnectionInfo.CompressionAlgorithms.Keys
                                              from a in message.CompressionAlgorithmsServerToClient
                                              where a == b
                                              select a).LastOrDefault();

            if (string.IsNullOrEmpty(decompressionAlgorithmName))
            {
                throw new SshConnectionException("Decompression algorithm not found", DisconnectReason.KeyExchangeFailed);
            }

            session.ConnectionInfo.CurrentServerCompressionAlgorithm = decompressionAlgorithmName;

            _clientCipherInfo  = session.ConnectionInfo.Encryptions[clientEncryptionAlgorithmName];
            _serverCipherInfo  = session.ConnectionInfo.Encryptions[serverDecryptionAlgorithmName];
            _clientHashInfo    = session.ConnectionInfo.HmacAlgorithms[clientHmacAlgorithmName];
            _serverHashInfo    = session.ConnectionInfo.HmacAlgorithms[serverHmacAlgorithmName];
            _compressionType   = session.ConnectionInfo.CompressionAlgorithms[compressionAlgorithmName];
            _decompressionType = session.ConnectionInfo.CompressionAlgorithms[decompressionAlgorithmName];
        }
Пример #7
0
  private void button6_Click(object sender, EventArgs e)
  {
   optimizeButton.Text = "suche... (1 / 5)"; optimizeButton.Update(); Application.DoEvents();
   int pos = OptiSucheEndKnoten();
   if (pos > 100)
   {
    optimizeButton.Text = "rechne... (2 / 5)"; optimizeButton.Update(); Application.DoEvents();

    int altAnzahl = hashGro / hashSatzGro;
    int altTiefe = OptiErmitteleTiefe(merkHashPos / hashSatzGro);

    Dictionary<int, int> knotenBehalten = new Dictionary<int, int>();
    for (int i = hashGro / hashSatzGro - 1; i >= pos; i--)
    {
     if (knotenBehalten.ContainsKey(i)) continue;
     int vg = hashInfo[i].vorgänger / hashSatzGro;
     knotenBehalten.Add(i, vg);
     for (; ; )
     {
      int p = vg;
      vg = hashInfo[vg].vorgänger / hashSatzGro;
      if (knotenBehalten.ContainsKey(p)) break;
      knotenBehalten.Add(p, vg);
      if (p == 0) break;
     }
    }

    optimizeButton.Text = "sortiere... (3 / 5)"; optimizeButton.Update(); Application.DoEvents();

    int[] trans = new int[altAnzahl];
    int cc = 0;
    int[] tmp = knotenBehalten.Select(satz => satz.Key).ToArray();
    Array.Sort(tmp);
    foreach (int satz in tmp) trans[satz] = cc++;
    tmp = null;
    GC.Collect();

    optimizeButton.Text = "schmelze... (4 / 5)"; optimizeButton.Update(); Application.DoEvents();

    int y = 0;
    foreach (var altKnoten in knotenBehalten.OrderBy(x => x.Key))
    {
     hashInfo[y] = new HashInfo(trans[hashInfo[altKnoten.Key].vorgänger / hashSatzGro] * hashSatzGro, hashInfo[altKnoten.Key].verschoben);
     int neuPos = y * hashSatzGro;
     int altPos = altKnoten.Key * hashSatzGro;
     for (int i = 0; i < hashSatzGro; i++) hashData[neuPos + i] = hashData[altPos + i];
     y++;
    }

    hashGro = y * hashSatzGro;

    optimizeButton.Text = "abschluss... (5 / 5)"; optimizeButton.Update(); Application.DoEvents();

    merkHashPos = OptiSucheEndKnoten(altTiefe) * hashSatzGro;

    optimizeButton.Text = "ok, " + (altAnzahl - y).ToString("#,##0") + " Knoten entfernt";
    Tick(1);
   }

   GC.Collect();
  }
Пример #8
0
  /// <summary>
  /// berechnet einen oder mehrere Schritte
  /// </summary>
  /// <param name="limit">maximal zu berechnende Schritte</param>
  void Tick(int limit)
  {
   zurückButton.Enabled = false;
   vorButton.Enabled = false;

   for (int lim = 0; lim < limit; lim++)
   {
    do
    {
     if (merkHashPos == hashGro)
     {
      tickButton.Text = "keine weiteren Knoten bekannt";
      return;
     }

     if (hashGro > hashInfoMax * hashSatzGro)
     {
      hashInfoMax *= 2;
      Array.Resize(ref hashInfo, hashInfoMax + 65536);
     }

     HashFeld h = new HashFeld(merkHashPos);

     if (h.RestWürfel == 0)
     {
      feldZeichner.Zeichne(pictureBox1, new HashFeld(merkHashPos));
      tickButton.Text = "Ziel gefunden! (" + hashIndex.Count.ToString("#,##0") + " Knoten)";
      int pos = merkHashPos;
      List<int> posListe = new List<int>();
      posListe.Add(pos);
      while (pos > 0)
      {
       pos = hashInfo[pos / hashSatzGro].vorgänger;
       posListe.Add(pos);
      }
      posListe.Reverse();
      viewListe = posListe.ToArray();
      viewPos = 0;
      zurückButton.Enabled = false;
      vorButton.Enabled = true;
      return;
     }

     if (h.KannLinks)
     {
      HashFeld neuHash = new HashFeld(hashGro);
      hashInfo[hashGro / hashSatzGro] = new HashInfo(merkHashPos, h.BewegeLinks(neuHash));
      if (!HashBekannt(neuHash)) hashGro += hashSatzGro;
     }

     if (h.KannRechts)
     {
      HashFeld neuHash = new HashFeld(hashGro);
      hashInfo[hashGro / hashSatzGro] = new HashInfo(merkHashPos, h.BewegeRechts(neuHash));
      if (!HashBekannt(neuHash)) hashGro += hashSatzGro;
     }

     if (h.KannOben)
     {
      HashFeld neuHash = new HashFeld(hashGro);
      hashInfo[hashGro / hashSatzGro] = new HashInfo(merkHashPos, h.BewegeOben(neuHash));
      if (!HashBekannt(neuHash)) hashGro += hashSatzGro;
     }

     if (h.KannUnten)
     {
      HashFeld neuHash = new HashFeld(hashGro);
      hashInfo[hashGro / hashSatzGro] = new HashInfo(merkHashPos, h.BewegeUnten(neuHash));
      if (!HashBekannt(neuHash)) hashGro += hashSatzGro;
     }

     merkHashPos += hashSatzGro;
    } while (merkHashPos < hashGro && !hashInfo[merkHashPos / hashSatzGro].verschoben);

    if (merkHashPos < hashGro)
    {
     if (lim + 1 == limit)
     {
      feldZeichner.Zeichne(pictureBox1, new HashFeld(merkHashPos));
      int schritte = OptiErmitteleTiefe(merkHashPos / hashSatzGro);
      tickButton.Text = (hashGro / hashSatzGro).ToString("#,##0") + " Felder (" + ((double)hashGro / 1048576.0).ToString("#,##0.0") + " MB) [" + schritte + "]";
      tickButton.Update();
     }
    }
    else
    {
     tickButton.Text = "keine weiteren Knoten bekannt";
     return;
    }
   }
  }
Пример #9
0
        private void VerifyHashInfo(string expectedAlgorithm, byte[] expectedHash, string expectedHashString, string expectedPath, HashInfo actualHashInfo)
        {
            Assert.AreEqual(expectedAlgorithm, actualHashInfo.Algorithm);
            StringAssert.AreEqualIgnoringCase(expectedPath, actualHashInfo.Path);
            StringAssert.AreEqualIgnoringCase(expectedHashString, actualHashInfo.HashString);

            Assert.AreEqual(expectedHash.Length, actualHashInfo.Hash.Length);
            for (int i = 0; i < expectedHash.Length; i++)
            {
                Assert.AreEqual(expectedHash[i], actualHashInfo.Hash[i]);
            }
        }
Пример #10
0
        /// <summary>
        ///   Updates the HashInfo for all of the files in the specified root directory.
        /// </summary>
        void UpdateHashes()
        {
            var files = GetFilesToHash(_rootTextureDir);
            foreach (var file in files)
            {
                try
                {
                    // Get the current info
                    var contentAssetName = ContentAssetName.FromAbsoluteFilePath(file, _rootTextureDir).Value;
                    var textureName = new TextureAssetName(contentAssetName).Value;
                    HashInfo hashInfo = null;
                    if (Contains(textureName))
                        hashInfo = this[textureName];

                    // Get the file size and last modified time
                    int size;
                    long lastMod;
                    GetFileSizeAndLastModified(file, out size, out lastMod);

                    // If we already have the hash info, and the size and last modified time have not changed,
                    // we can skip updating the hash
                    if (hashInfo != null && hashInfo.FileSize == size && hashInfo.LastModifiedTime == lastMod)
                        continue;

                    // Get the new hash and add the new file or update the existing values
                    var hash = GetFileHash(file);
                    if (hashInfo == null)
                    {
                        hashInfo = new HashInfo(hash, size, lastMod);
                        this[textureName] = hashInfo;
                    }
                    else
                    {
                        hashInfo.FileSize = size;
                        hashInfo.Hash = hash;
                        hashInfo.LastModifiedTime = lastMod;
                    }
                }
                catch (IOException)
                {
                }
                catch (UnauthorizedAccessException)
                {
                }
            }

            // Write the updates
            Save();
        }
Пример #11
0
        /// <summary>
        ///   Reads a <see cref = "KeyValuePair{T,U}" /> from an <see cref = "IValueReader" />.
        /// </summary>
        /// <param name = "r">The <see cref = "IValueReader" /> to read from.</param>
        /// <returns>The read <see cref = "KeyValuePair{T,U}" />.</returns>
        static KeyValuePair<string, HashInfo> Read(IValueReader r)
        {
            var key = r.ReadString(_textureNameValueKey);
            var hash = r.ReadString(_hashValueKey);
            var fileSize = r.ReadInt(_fileSizeValueKey);
            var lastModified = r.ReadLong(_lastModifiedValueKey);

            var hashInfo = new HashInfo(hash, fileSize, lastModified);
            return new KeyValuePair<string, HashInfo>(key, hashInfo);
        }