Exemple #1
0
        static void AttackLastRound()
        {
            Encryption encryption = new Encryption();
            Analysis   analysis   = new Analysis();

            Console.WriteLine("Current keys: " + encryption.PrintKeys());

            //analysis the sbox
            List <Differential> diffList = analysis.CountDifferentialsSingleSBox();

            bool[] attackSBox = new bool[] { true };

            //Check the attack new
            CipherThreeDifferentialKeyRecoveryAttack keyRecoveryConfiguration = new CipherThreeDifferentialKeyRecoveryAttack();

            SearchPolicy   curSearchPolicy   = SearchPolicy.FirstBestCharacteristicDepthSearch;
            AbortingPolicy curAbortingPolicy = AbortingPolicy.Threshold;

            //attack round 3
            DifferentialAttackRoundConfiguration configRound3SBox1 = analysis.GenerateConfigurationAttack(3, attackSBox, curAbortingPolicy, curSearchPolicy, diffList, keyRecoveryConfiguration, encryption);
            DifferentialAttackRoundResult        resultRound3SBox1 = analysis.RecoverKeyInformation(keyRecoveryConfiguration, configRound3SBox1, encryption);

            keyRecoveryConfiguration.RoundConfigurations.Add(configRound3SBox1);
            keyRecoveryConfiguration.RoundResults.Add(resultRound3SBox1);

            //Result
            keyRecoveryConfiguration.Subkey3          = resultRound3SBox1.PossibleKey;
            keyRecoveryConfiguration.RecoveredSubkey3 = true;
            Console.WriteLine(keyRecoveryConfiguration.printRecoveredSubkeyBits());
        }
Exemple #2
0
        public int PartialDecrypt(DifferentialKeyRecoveryAttack attack, int block)
        {
            CipherThreeDifferentialKeyRecoveryAttack cipherThreeAttack = attack as CipherThreeDifferentialKeyRecoveryAttack;
            int result = block;

            if (cipherThreeAttack != null && cipherThreeAttack.RecoveredSubkey3)
            {
                result = DecryptSingleRound(result, cipherThreeAttack.Subkey3, false, true);
            }

            if (cipherThreeAttack != null && cipherThreeAttack.RecoveredSubkey2)
            {
                result = DecryptSingleRound(result, cipherThreeAttack.Subkey2, true, false);
            }

            if (cipherThreeAttack != null && cipherThreeAttack.RecoveredSubkey1)
            {
                result = DecryptSingleRound(result, cipherThreeAttack.Subkey1, false, false);
            }

            return(result);
        }
Exemple #3
0
        public List <Pair> FilterPairs(DifferentialAttackRoundConfiguration roundConfig, List <Differential> diffListOfSBox,
                                       DifferentialKeyRecoveryAttack attack, IEncryption encryption, int expectedDifferential)
        {
            //cast to use the object
            CipherThreeDifferentialKeyRecoveryAttack cipherFourAttack = attack as CipherThreeDifferentialKeyRecoveryAttack;

            if (cipherFourAttack == null)
            {
                throw new ArgumentNullException(nameof(attack));
            }

            //contains the filtered pairs
            List <Pair> resultList = new List <Pair>();

            List <int>[] arrayOfPossibleDifferentialsForSBoxes      = new List <int> [CipherThreeConfiguration.SBOXNUM];
            int[]        arrayOfExpectedInputDifferentialsForSBoxes = new int[CipherThreeConfiguration.SBOXNUM];

            for (int i = 0; i < CipherThreeConfiguration.SBOXNUM; i++)
            {
                arrayOfPossibleDifferentialsForSBoxes[i]      = new List <int>();
                arrayOfExpectedInputDifferentialsForSBoxes[i] = expectedDifferential;

                if (arrayOfExpectedInputDifferentialsForSBoxes[i] == 0)
                {
                    arrayOfPossibleDifferentialsForSBoxes[i].Add(0);
                }
            }

            //iterate over the differentials
            foreach (var curDiff in diffListOfSBox)
            {
                //Skip 0 InputDiff / OutputDiff
                if (curDiff.InputDifferential == 0)
                {
                    continue;
                }

                for (int i = 0; i < CipherThreeConfiguration.SBOXNUM; i++)
                {
                    if (arrayOfExpectedInputDifferentialsForSBoxes[i] == curDiff.InputDifferential)
                    {
                        arrayOfPossibleDifferentialsForSBoxes[i].Add(curDiff.OutputDifferential);
                    }
                }
            }

            //check all pairs for the conditions
            foreach (var curPair in roundConfig.UnfilteredPairList)
            {
                int cipherTextLeftMember  = encryption.EncryptBlock(curPair.LeftMember);
                int cipherTextRightMember = encryption.EncryptBlock(curPair.RightMember);

                cipherTextLeftMember  = PartialDecrypt(attack, cipherTextLeftMember);
                cipherTextRightMember = PartialDecrypt(attack, cipherTextRightMember);

                int diffOfCipherText = (cipherTextLeftMember ^ cipherTextRightMember);

                int[]  diffOfCipherTextSBoxes = new int[CipherThreeConfiguration.SBOXNUM];
                bool[] conditionsOfSBoxes     = new bool[CipherThreeConfiguration.SBOXNUM];
                for (int i = 0; i < CipherThreeConfiguration.SBOXNUM; i++)
                {
                    diffOfCipherTextSBoxes[i] = diffOfCipherText;
                    conditionsOfSBoxes[i]     = false;
                }

                for (int i = 0; i < CipherThreeConfiguration.SBOXNUM; i++)
                {
                    foreach (var possibleOutputDiff in arrayOfPossibleDifferentialsForSBoxes[i])
                    {
                        if (possibleOutputDiff == diffOfCipherTextSBoxes[i])
                        {
                            conditionsOfSBoxes[i] = true;
                        }
                    }
                }

                bool satisfied = true;
                for (int i = 0; i < CipherThreeConfiguration.SBOXNUM; i++)
                {
                    if (conditionsOfSBoxes[i] == false)
                    {
                        satisfied = false;
                    }
                }

                if (satisfied)
                {
                    resultList.Add(curPair);
                }
            }

            return(resultList);
        }