Changeset 1162


Ignore:
Timestamp:
Feb 21, 2010, 8:25:11 PM (12 years ago)
Author:
Arno Wacker
Message:

KeySearcher:

  • Removed creation of CryptoolStream for each trial key -> performance boost
  • Re-integrated the usage of only the partial encrypted message for trial decryption (byteToUse). Now the value set in the costFunction will determine how many bytes will be used. This value shall be moved in the future to the KeySearcher settings.

IControlEncryption

  • Added an extended method for Decrypt to IControlEncryption for usage with bytesToUse

AES/DES/SDES

  • Updated for compatibility with IControlEncryption-changes (the new parameter is also used by all three)

Samples

  • Updated KeySearcher-Sample-DES to use only 128 bytes for bruteforcing instead of 256 (increase performance a little)

Note: providing a value for bytesToUse smaller than the blocksize of the algorithm used is an error case - not sure if every case is already covered.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPluginBase/Control/IControlEncryption.cs

    r1157 r1162  
    2525    {
    2626        byte[] Encrypt(byte[] key, int blocksize);
     27        byte[] Decrypt(byte[] ciphertext, byte[] key, int bytesToUse);
    2728        byte[] Decrypt(byte[] ciphertext, byte[] key);
    2829        string getKeyPattern();
  • trunk/CrypPlugins/AES/AES.cs

    r1157 r1162  
    496496        }
    497497
    498        
    499 
    500498        public byte[] Decrypt(byte[] ciphertext, byte[] key)
    501499        {
     500            return Decrypt(ciphertext, key, ciphertext.Length);
     501        }
     502
     503        public byte[] Decrypt(byte[] ciphertext, byte[] key, int bytesToUse)
     504        {
    502505            CryptoStream crypto_stream = null;
    503             byte[] output = new byte[ciphertext.Length];
     506            int size = bytesToUse > ciphertext.Length ? ciphertext.Length : bytesToUse;
     507
     508            byte[] output = new byte[size];
    504509
    505510
     
    532537                }
    533538
    534                 crypto_stream = new CryptoStream(new MemoryStream(ciphertext), p_decryptor, CryptoStreamMode.Read);
     539                crypto_stream = new CryptoStream(new MemoryStream(ciphertext, 0, size), p_decryptor, CryptoStreamMode.Read);
    535540
    536541                byte[] buffer = new byte[aes_algorithm.BlockSize / 8];
  • trunk/CrypPlugins/DES/DES.cs

    r1157 r1162  
    545545        }
    546546
     547        public byte[] Decrypt(byte[] ciphertext, byte[] key)
     548        {
     549            return Decrypt(ciphertext, key, ciphertext.Length);
     550        }
     551
    547552        // TODO: add override with iv, mode, blocksize
    548         public byte[] Decrypt(byte[] ciphertext, byte[] key)
     553        public byte[] Decrypt(byte[] ciphertext, byte[] key, int bytesToUse)
    549554        {
    550555            CryptoStream crypto_stream = null;
    551             byte[] output = new byte[ciphertext.Length];
     556            int size = bytesToUse > ciphertext.Length ? ciphertext.Length : bytesToUse;
     557
     558            byte[] output = new byte[size];
    552559           
    553560            // always recreating this instance is thread-safe, but may cost us some performance
     
    595602            }
    596603
    597             crypto_stream = new CryptoStream(new MemoryStream(ciphertext), p_decryptor, CryptoStreamMode.Read);
     604            crypto_stream = new CryptoStream(new MemoryStream(ciphertext,0,size), p_decryptor, CryptoStreamMode.Read);
    598605
    599606            int read, readOverall = 0;
  • trunk/CrypPlugins/KeySearcher/KeySearcher.cs

    r1161 r1162  
    105105                {
    106106                    this.csEncryptedData = value;
    107                     cryptoolStreamChanged = true;
     107                    this.encryptedData = GetByteFromCryptoolStream(value);
    108108                    OnPropertyChanged("CSEncryptedData");
    109109                }
     
    121121                {
    122122                    this.encryptedData = value;
    123                     cryptoolStreamChanged = true;
    124123                    OnPropertyChanged("EncryptedData");
    125124                }
     
    130129        /// When the Input-Slot changed, set this variable to true, so the new Stream will be transformed to byte[]
    131130        /// </summary>
    132         private bool cryptoolStreamChanged = false;
    133         private byte[] encryptedByteData;
    134131        private byte[] GetByteFromCryptoolStream(CryptoolStream cryptoolStream)
    135132        {
    136             // only transform CryptoolStream to Byte[], if there is a new CryptoolStream
    137             // or decryptedByteData is Null
    138             if (cryptoolStreamChanged || encryptedByteData == null)
     133            byte[] encryptedByteData = null;
     134
     135            if (cryptoolStream != null)
    139136            {
    140137                CryptoolStream cs = new CryptoolStream();
     
    228225        {
    229226            //either byte[] CStream input or CryptoolStream Object input
    230             if (this.EncryptedData != null || this.CSEncryptedData != null) //to prevent execution on initialization
     227            if (this.encryptedData != null || this.csEncryptedData != null) //to prevent execution on initialization
    231228            {
    232229                if (this.ControlMaster != null)
     
    446443            try
    447444            {
    448                 CryptoolStream cs = new CryptoolStream();
    449                 if (this.CSEncryptedData == null)
    450                 {
    451                     cs.OpenRead(this.EncryptedData);
    452                     valueKey.decryption = sender.Decrypt(this.EncryptedData, keya);
     445                if (this.encryptedData != null && this.encryptedData.Length > 0)
     446                {
     447                    valueKey.decryption = sender.Decrypt(this.encryptedData, keya, bytesToUse);
    453448                }
    454449                else
    455450                {
    456                     cs.OpenRead(this.CSEncryptedData.FileName);
    457                     byte[] byteCS = new byte[cs.Length];
    458                     cs.Read(byteCS, 0, byteCS.Length);
    459                     //this.CSEncryptedData.Read(byteCS, 0, byteCS.Length);
    460                     valueKey.decryption = sender.Decrypt(byteCS, keya);
    461                 }
     451                    GuiLogMessage("Can't bruteforce empty input!", NotificationLevel.Error);
     452                    return false;
     453                }
     454                //CryptoolStream cs = new CryptoolStream();
     455                //if (this.CSEncryptedData == null)
     456                //{
     457                //    cs.OpenRead(this.EncryptedData);
     458                //    valueKey.decryption = sender.Decrypt(this.EncryptedData, keya);
     459                //}
     460                //else
     461                //{
     462                //    cs.OpenRead(this.CSEncryptedData.FileName);
     463                //    byte[] byteCS = new byte[cs.Length];
     464                //    cs.Read(byteCS, 0, byteCS.Length);
     465                //    //this.CSEncryptedData.Read(byteCS, 0, byteCS.Length);
     466                //    valueKey.decryption = sender.Decrypt(byteCS, keya);
     467                //}
    462468
    463469                //valueKey.decryption = sender.Decrypt(keya, bytesToUse);
     
    860866        {
    861867            /* Begin: New stuff because of changing the IControl data flow - Arnie 2010.01.18 */
    862             this.EncryptedData = encryptedData;
    863             this.InitVector = initVector;
     868            this.encryptedData = encryptedData;
     869            this.initVector = initVector;
    864870            /* End: New stuff because of changing the IControl data flow - Arnie 2010.01.18 */
    865871           
  • trunk/CrypPlugins/SDES/SDES.cs

    r1157 r1162  
    589589        /// Called by a Master to start decryption with ciphertext
    590590        /// </summary>
     591        /// <param name="ciphertext">encrypted text</param>
    591592        /// <param name="key">key</param>
    592593        /// <param name="bytesToUse">bytesToUse</param>
     594        /// <returns>decrypted text</returns>
     595        public byte[] Decrypt(byte[] ciphertext, byte[] key, int bytesToUse)
     596        {
     597            return execute(ciphertext, key, bytesToUse, 1);
     598        }
     599
     600        /// <summary>
     601        /// Called by a Master to start decryption with ciphertext
     602        /// </summary>
     603        /// <param name="ciphertext">encrypted text</param>
     604        /// <param name="key">key</param>
    593605        /// <returns>decrypted text</returns>
    594606        public byte[] Decrypt(byte[] ciphertext, byte[] key)
Note: See TracChangeset for help on using the changeset viewer.