public IntermediateRound(Settings settings, KeySchedule keySchedule)
     : base(new SubBytes(settings),
            new ShiftRows(settings),
            new MixColumns(settings),
            new AddRoundKey(settings, keySchedule))
 {
 }
Пример #2
0
 public FinalRound(Settings settings, KeySchedule keySchedule)
     : base(
         new SubBytes(settings),
         new ShiftRows(settings),
         new AddRoundKey(settings, keySchedule)
         )
 {
 }
Пример #3
0
        private void ShuffleWordTransforms()
        {
            int count = transforms.Length;

            byte[] random = new byte[count];
            KeySchedule.GetNext(count * 8).CopyTo(random, 0);
            for (int i = 0; i < count; i++)
            {
                int r = random[i] % count;
                transforms.Swap(i, r);
            }
        }
Пример #4
0
        private void InstantiateWordTransforms()
        {
            int count = PossibleTransforms.Length;

            transforms = new IWordEncoder[count];
            for (int i = 0; i < count; i++)
            {
                IWordEncoder transform = (IWordEncoder)Activator.CreateInstance(PossibleTransforms[i]);
                transform.WordSize = wordSize;
                if (transform.SeedSize != 0)
                {
                    transform.Seed = KeySchedule.GetNext(transform.SeedSize);
                }

                transforms[i] = transform;
            }
        }
Пример #5
0
        public EncodingPlan GetEncodingPlan(int blockLength)
        {
            EncodingPlan result = new EncodingPlan();

            result.WordSize = wordSize;
            int  transformsCount = Transforms.Length;
            int  bitsInBlock     = blockLength * 8;
            int  remainder       = bitsInBlock % wordSize;
            bool hasRemainder    = remainder != 0;
            int  wordCount       = (int)Math.Ceiling((double)bitsInBlock / wordSize);

            for (int index = 0; index < wordCount; index++)
            {
                int          wordLength = (index == wordCount - 1 && hasRemainder ? remainder : wordSize);
                IWordEncoder encoder    = (IWordEncoder)Activator.CreateInstance(transforms[index % transformsCount].GetType());
                encoder.WordSize = wordLength;
                encoder.Seed     = KeySchedule.GetNext(encoder.SeedSize);
                result.Transformations.Add(encoder);
            }
            return(result);
        }
Пример #6
0
 public InitialRound(Settings settings, KeySchedule keySchedule)
     : base(new AddRoundKey(settings, keySchedule))
 {
 }
Пример #7
0
 private void NewWordSize()
 {
     byte[] random = new byte[1];
     KeySchedule.GetNext(8).CopyTo(random, 0);
     wordSize = (MinWordSize + random[0] % (MaxWordSize - MinWordSize + 1));
 }
Пример #8
0
 public AddRoundKey(Settings settings, KeySchedule keySchedule)
     : base(settings)
 {
     _KeySchedule = keySchedule;
 }