Пример #1
0
        private int DecryptBlock(
            byte[] input,
            int inOff,
            byte[] outBytes,
            int outOff)
        {
            input.DeepCopy_NoChecks(inOff, _cbcNextV, 0, CipherBlockSize);

            int length = BlockCipher.ProcessBlock(input, inOff, outBytes, outOff);

            /*
             * XOR the cbcV and the output
             */
            outBytes.XorInPlaceInternal(outOff, _cbcV, 0, CipherBlockSize);

            /*
             * swap the back up buffer into next position
             */
            byte[] tmp;

            tmp       = _cbcV;
            _cbcV     = _cbcNextV;
            _cbcNextV = tmp;

            return(length);
        }
Пример #2
0
 private int EncryptBlock(
     byte[] input,
     int inOff,
     byte[] outBytes,
     int outOff)
 {
     BlockCipher.ProcessBlock(_cfbV, 0, _cfbOutV, 0);
     // XOR the cfbV with the plaintext producing the ciphertext
     input.XorInternal(inOff, _cfbOutV, 0, outBytes, outOff, _feedbackSize);
     // change over the input block.
     Array.Copy(_cfbV, _feedbackSize, _cfbV, 0, _cfbV.Length - _feedbackSize);
     Array.Copy(outBytes, outOff, _cfbV, _cfbV.Length - _feedbackSize, _feedbackSize);
     return(_feedbackSize);
 }
Пример #3
0
        /// <inheritdoc />
        internal override int ProcessBlockInternal(byte[] input, int inOff, byte[] output, int outOff)
        {
            BlockCipher.ProcessBlock(_ofbV, 0, _ofbOutV, 0);

            // XOR the ofbV with the plaintext producing the cipher text (and
            // the next input block).
            input.XorInternal(inOff, _ofbOutV, 0, output, outOff, CipherBlockSize);

            // change over the input block.
            Array.Copy(_ofbV, CipherBlockSize, _ofbV, 0, _ofbV.Length - CipherBlockSize);
            Array.Copy(_ofbOutV, 0, _ofbV, _ofbV.Length - CipherBlockSize, CipherBlockSize);

            return(CipherBlockSize);
        }
Пример #4
0
        /// <inheritdoc />
        internal override int ProcessBlockInternal(byte[] input, int inOff, byte[] output, int outOff)
        {
            BlockCipher.ProcessBlock(_counter, 0, _counterOut, 0);

            // XOR the counterOut with the plaintext producing the cipher text
            input.XorInternal(inOff, _counterOut, 0, output, outOff, CipherBlockSize);

            // Increment the counter
            int j = CipherBlockSize;

            while (--j >= 0 && ++_counter[j] == 0)
            {
            }

            return(CipherBlockSize);
        }
Пример #5
0
        private int EncryptBlock(
            byte[] input,
            int inOff,
            byte[] outBytes,
            int outOff)
        {
            /*
             * XOR the cbcV and the input,
             * then encrypt the cbcV
             */
            _cbcV.XorInPlaceInternal(0, input, inOff, CipherBlockSize);

            int length = BlockCipher.ProcessBlock(_cbcV, 0, outBytes, outOff);

            /*
             * copy ciphertext to cbcV
             */
            outBytes.DeepCopy_NoChecks(outOff, _cbcV, 0, _cbcV.Length);

            return(length);
        }