Changeset 2114


Ignore:
Timestamp:
Nov 20, 2010, 11:41:36 AM (11 years ago)
Author:
Sven Rech
Message:

reverted my changes (they don't seem to work too well)

Location:
trunk
Files:
1 deleted
7 edited

Legend:

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

    r2110 r2114  
    7272        /// </summary>
    7373        /// <param name="code"></param>
    74         /// <param name="approximateNumberOfKeys"></param>
     74        /// <param name="maxKeys"></param>
    7575        /// <returns></returns>
    76         string ModifyOpenCLCode(string code, int approximateNumberOfKeys);
     76        string ModifyOpenCLCode(string code, int maxKeys);
    7777
    7878        /// <summary>
  • trunk/CrypPlugins/AES/OpenCL/AESOpenCL.cl

    r2110 r2114  
    881881}
    882882
    883 kernel void bruteforceKernel(global unsigned char *userKey, global float *results, int add)
     883kernel void bruteforceKernel(global unsigned char *userKey, global float *results)
    884884{
    885885        size_t x = get_global_id(0);
    886886       
    887887        AES_KEY key;   
    888         AES_set_decrypt_key(userKey, $$BITS$$, &(key), (x+add));
     888        AES_set_decrypt_key(userKey, $$BITS$$, &(key), x);
    889889
    890890        //possibility for cost function to initialize some stuff here:
  • trunk/CrypPlugins/KeySearcher/KeySearcher.cs

    r2112 r2114  
    371371
    372372            KeySearcherOpenCLCode keySearcherOpenCLCode = null;
    373             KeySearcherOpenCLSubbatchOptimizer keySearcherOpenCLSubbatchOptimizer = null;
    374373            if (useOpenCL)
    375             {
    376                 keySearcherOpenCLCode = new KeySearcherOpenCLCode(this, encryptedData, sender, CostMaster, 256 * 256 * 256 * 16);
    377                 keySearcherOpenCLSubbatchOptimizer = new KeySearcherOpenCLSubbatchOptimizer(oclManager.CQ[settings.OpenCLDevice].Device.MaxWorkItemSizes.Aggregate(1, (x, y) => (x * (int)y)));
    378             }
     374                keySearcherOpenCLCode = new KeySearcherOpenCLCode(this, encryptedData, sender, CostMaster, 256 * 64);
    379375
    380376            try
     
    403399                            try
    404400                            {
    405                                 finish = BruteforceOpenCL(keySearcherOpenCLCode, keySearcherOpenCLSubbatchOptimizer, keyTranslator, sender, bytesToUse, parameters);
     401                                finish = BruteforceOpenCL(keySearcherOpenCLCode, keyTranslator, sender, bytesToUse);
    406402                            }
    407403                            catch (Exception)
     
    414410                        int progress = keyTranslator.GetProgress();
    415411
    416                         if (!useOpenCL)
    417                         {
    418                             doneKeysArray[threadid] += progress;
    419                             keycounterArray[threadid] += progress;
    420                             keysLeft[threadid] -= progress;
    421                         }
     412                        doneKeysArray[threadid] += progress;
     413                        keycounterArray[threadid] += progress;
     414                        keysLeft[threadid] -= progress;
    422415
    423416                    } while (!finish && !stop);
     
    436429        }
    437430
    438         private unsafe bool BruteforceOpenCL(KeySearcherOpenCLCode keySearcherOpenCLCode, KeySearcherOpenCLSubbatchOptimizer keySearcherOpenCLSubbatchOptimizer, IKeyTranslator keyTranslator, IControlEncryption sender, int bytesToUse, object[] parameters)
    439         {
    440             int threadid = (int)parameters[1];
    441             BigInteger[] doneKeysArray = (BigInteger[])parameters[2];
    442             BigInteger[] keycounterArray = (BigInteger[])parameters[3];
    443             BigInteger[] keysLeft = (BigInteger[])parameters[4];
     431        private unsafe bool BruteforceOpenCL(KeySearcherOpenCLCode keySearcherOpenCLCode, IKeyTranslator keyTranslator, IControlEncryption sender, int bytesToUse)
     432        {
     433            float[] costArray = null;
    444434            try
    445435            {
    446436                Kernel bruteforceKernel = keySearcherOpenCLCode.GetBruteforceKernel(oclManager, keyTranslator);
    447                
     437                costArray = new float[keyTranslator.GetOpenCLBatchSize()];
    448438                int deviceIndex = settings.OpenCLDevice;
    449439               
     440                Mem costs = oclManager.Context.CreateBuffer(MemFlags.READ_ONLY, costArray.Length * 4);
     441                IntPtr[] globalWorkSize = { (IntPtr)keyTranslator.GetOpenCLBatchSize() };
     442
    450443                Mem userKey;
    451444                var key = keyTranslator.GetKey();
     
    454447
    455448                bruteforceKernel.SetArg(0, userKey);
    456 
    457                 int subbatches = keySearcherOpenCLSubbatchOptimizer.GetAmountOfSubbatches(keyTranslator);
    458                 GuiLogMessage(string.Format("Now using {0} subbatches", subbatches), NotificationLevel.Info);
    459 
    460                 int subbatchSize = keyTranslator.GetOpenCLBatchSize() / subbatches;
    461                 float[] costArray = new float[subbatchSize];
    462                 Mem costs = oclManager.Context.CreateBuffer(MemFlags.READ_WRITE, costArray.Length * 4);
    463449                bruteforceKernel.SetArg(1, costs);
    464450
    465                 IntPtr[] globalWorkSize = { (IntPtr)subbatchSize };
    466 
    467                 keySearcherOpenCLSubbatchOptimizer.BeginMeasurement();
    468 
    469                 for (int i = 0; i < subbatches; i++)
    470                 {
    471                     bruteforceKernel.SetArg(2, i * subbatchSize);
    472                     oclManager.CQ[deviceIndex].EnqueueNDRangeKernel(bruteforceKernel, 1, null, globalWorkSize, null);
    473                     oclManager.CQ[deviceIndex].EnqueueBarrier();
    474 
    475                     Event e;
    476                     fixed (float* costa = costArray)
    477                         oclManager.CQ[deviceIndex].EnqueueReadBuffer(costs, true, 0, costArray.Length * 4, new IntPtr((void*)costa), 0, null, out e);
    478 
    479                     e.Wait();
    480 
    481                     checkOpenCLResults(keyTranslator, costArray, sender, bytesToUse, i * subbatchSize);
    482 
    483                     doneKeysArray[threadid] += subbatchSize;
    484                     keycounterArray[threadid] += subbatchSize;
    485                     keysLeft[threadid] -= subbatchSize;
    486                 }
    487 
    488                 keySearcherOpenCLSubbatchOptimizer.EndMeasurement();
    489 
     451                oclManager.CQ[deviceIndex].EnqueueNDRangeKernel(bruteforceKernel, 1, null, globalWorkSize, null);
     452                oclManager.CQ[deviceIndex].EnqueueBarrier();
     453
     454                Event e;
     455                fixed (float* costa = costArray)
     456                    oclManager.CQ[deviceIndex].EnqueueReadBuffer(costs, true, 0, costArray.Length * 4, new IntPtr((void*)costa), 0, null, out e);
     457
     458                e.Wait();
    490459                costs.Dispose();
    491460            }
     
    497466            }
    498467
    499             return !keyTranslator.NextOpenCLBatch();
    500         }
    501 
    502         private void checkOpenCLResults(IKeyTranslator keyTranslator, float[] costArray, IControlEncryption sender, int bytesToUse, int add)
    503         {
     468            //Check results:
    504469            var op = this.costMaster.getRelationOperator();
    505470            for (int i = 0; i < costArray.Length; i++)
     
    509474                    || (op == RelationOperator.LessThen) && (cost < value_threshold))
    510475                {
    511                     ValueKey valueKey = new ValueKey { value = cost, key = keyTranslator.GetKeyRepresentation(i + add) };
     476                    ValueKey valueKey = new ValueKey {value = cost, key = keyTranslator.GetKeyRepresentation(i)};
    512477                    valueKey.keya = keyTranslator.GetKeyFromRepresentation(valueKey.key);
    513478                    valueKey.decryption = sender.Decrypt(this.encryptedData, valueKey.keya, InitVector, bytesToUse);
     
    515480                }
    516481            }
     482
     483            return !keyTranslator.NextOpenCLBatch();
    517484        }
    518485
     
    747714            while (!stop)
    748715            {
    749                 Thread.Sleep(2000);
     716                Thread.Sleep(1000);
    750717
    751718                updateToplist();
  • trunk/CrypPlugins/KeySearcher/KeySearcher.csproj

    r2110 r2114  
    120120    <Compile Include="KeyPattern\KeyMovement.cs" />
    121121    <Compile Include="KeySearcher.cs" />
    122     <Compile Include="OpenCL\KeySearcherOpenCLSubbatchOptimizer.cs" />
    123122    <Compile Include="KeyTranslators\ByteArrayKeyTranslator.cs" />
    124123    <Compile Include="OpenCL\KeySearcherOpenCLCode.cs" />
  • trunk/CrypPlugins/KeySearcher/KeyTranslators/ByteArrayKeyTranslator.cs

    r2111 r2114  
    228228        }
    229229
    230         public string ModifyOpenCLCode(string code, int approximateNumberOfKeys)
     230        public string ModifyOpenCLCode(string code, int maxKeys)
    231231        {
    232232            string[] byteReplaceStrings = new string[32];
     
    236236            //Find out how many wildcards/keys we can bruteforce at once:
    237237            int j = movementStatus.Length - 1;
    238             long size = 1;
    239             while ((j >= 0) && ((size * keyMovements[j].Count()) <= approximateNumberOfKeys) && (movementStatus[j] == 0))
     238            int size = 1;
     239            while ((size < maxKeys) && (j >= 0) && (movementStatus[j] == 0))
    240240                size *= keyMovements[j--].Count();
    241241
    242242            if (size < 256)
    243                 throw new Exception("Amount of keys to small to process with OpenCL.");    //it's futile to use OpenCL for so few keys
     243                return null;    //it's futile to use OpenCL for so few keys
    244244
    245245            //generate the key movement string:
     
    296296            //progress:
    297297            openCLIndex = j;
    298             openCLSize = (int)size;
     298            openCLSize = size;
    299299
    300300            return code;
  • trunk/CrypPlugins/KeySearcher/OpenCL/KeySearcherOpenCLCode.cs

    r2110 r2114  
    1515        private IControlCost controlCost;
    1616        private IControlEncryption encryptionController;
    17         private int approximateNumberOfKeys;
     17        private int maxKeys;
    1818
    1919        private IKeyTranslator keyTranslatorOfCode = null;
     
    2121        private Kernel openCLKernel = null;
    2222
    23         public KeySearcherOpenCLCode(KeySearcher keySearcher, byte[] encryptedData, IControlEncryption encryptionController, IControlCost controlCost, int approximateNumberOfKeys)
     23        public KeySearcherOpenCLCode(KeySearcher keySearcher, byte[] encryptedData, IControlEncryption encryptionController, IControlCost controlCost, int maxKeys)
    2424        {
    2525            this.keySearcher = keySearcher;
     
    2727            this.encryptionController = encryptionController;
    2828            this.controlCost = controlCost;
    29             this.approximateNumberOfKeys = approximateNumberOfKeys;
     29            this.maxKeys = maxKeys;
    3030        }
    3131
     
    5959
    6060            //put key movement of pattern into code:
    61             code = keyTranslator.ModifyOpenCLCode(code, approximateNumberOfKeys);
     61            code = keyTranslator.ModifyOpenCLCode(code, maxKeys);
    6262
    6363            keyTranslatorOfCode = keyTranslator;
  • trunk/CrypPlugins/SDES/SDES.cs

    r2110 r2114  
    789789        }
    790790
    791         public string ModifyOpenCLCode(string code, int approximateNumberOfKeys)
     791        public string ModifyOpenCLCode(string code, int maxKeys)
    792792        {
    793793            throw new NotImplementedException();
Note: See TracChangeset for help on using the changeset viewer.