private void Encrypt(IModeBlockCipherParameters param, int numberOfSegments, byte[] outBuffer) { var payLoad = param.Payload.GetDeepCopy().ToBytes(); var iv = param.Iv.GetDeepCopy().ToBytes(); var ivOutBuffer = new byte[iv.Length]; // For each segment for (int i = 0; i < numberOfSegments; i++) { _engine.ProcessSingleBlock(iv, ivOutBuffer, 0); // XORs the current segment of payload onto the first segment of the ivOutBuffer _shiftRegisterStrategy.SetSegmentInProcessedBlock(payLoad, i, ivOutBuffer); // Sets the outbuffer segment equal to the first segment of the ivOutBuffer _shiftRegisterStrategy.SetOutBufferSegmentFromIvXorPayload(ivOutBuffer, i, outBuffer); // Sets up the iv for the next segment _shiftRegisterStrategy.SetNextRoundIv(ivOutBuffer, 0, iv); } // Update the Param.Iv for the next call for (int i = 0; i < _engine.BlockSizeBytes; i++) { param.Iv[i] = iv[i]; } }
private void Encrypt(IModeBlockCipherParameters param, int numberOfSegments, BitString[] ivs, byte[] outBuffer) { var payLoad = param.Payload.ToBytes(); var ivOutBuffer = new byte[_engine.BlockSizeBytes]; var iv = ivs[0].ToBytes(); // For each segment for (int i = 0; i < numberOfSegments; i++) { _engine.ProcessSingleBlock(iv, ivOutBuffer, 0); // XORs the current segment of payload onto the first segment of the ivOutBuffer _shiftRegisterStrategy.SetSegmentInProcessedBlock(payLoad, i, ivOutBuffer); // Sets the outbuffer segment equal to the first segment of the ivOutBuffer _shiftRegisterStrategy.SetOutBufferSegmentFromIvXorPayload(ivOutBuffer, i, outBuffer); if (i + 1 < PARTITIONS) { iv = ivs[(i + 1) % PARTITIONS].ToBytes(); } else { iv = new BitString(iv) .MSBSubstring(_shiftRegisterStrategy.ShiftSize, 64 - _shiftRegisterStrategy.ShiftSize) .ConcatenateBits( new BitString(outBuffer) .MSBSubstring((i + 1 - PARTITIONS) * _shiftRegisterStrategy.ShiftSize, _shiftRegisterStrategy.ShiftSize) ).ToBytes(); } } // Update the Param.Iv for the next call for (int i = 0; i < _engine.BlockSizeBytes; i++) { param.Iv[i] = iv[i]; } }