public IntermediateRound(Settings settings, KeySchedule keySchedule) : base(new SubBytes(settings), new ShiftRows(settings), new MixColumns(settings), new AddRoundKey(settings, keySchedule)) { }
public FinalRound(Settings settings, KeySchedule keySchedule) : base( new SubBytes(settings), new ShiftRows(settings), new AddRoundKey(settings, keySchedule) ) { }
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); } }
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; } }
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); }
public InitialRound(Settings settings, KeySchedule keySchedule) : base(new AddRoundKey(settings, keySchedule)) { }
private void NewWordSize() { byte[] random = new byte[1]; KeySchedule.GetNext(8).CopyTo(random, 0); wordSize = (MinWordSize + random[0] % (MaxWordSize - MinWordSize + 1)); }
public AddRoundKey(Settings settings, KeySchedule keySchedule) : base(settings) { _KeySchedule = keySchedule; }