Esempio n. 1
0
        // [blockcontents LENGTH]
        // [magicbytes 4][version 4][salt 16][hmacsha512 64][hmackeccak512 64][aesiv 16][ciphertext (variable length)]
        // embedded in the ciphertext are an additional 16 bytes for the twofish IV, and 24 for the xsalsa20 IV

        internal static void ProcessArray(BC.Crypto.IBlockCipher Cipher, byte[] Data, byte[] Output)
        {
            if (Data == null || Output == null || Cipher == null)
                throw new InvalidOperationException("Null parameters not allowed.");
            int blockSize = Cipher.GetBlockSize();
            byte[] XOR_ME = new byte[Cipher.GetBlockSize()];
            for (int i = 0; i < Data.Length; i += blockSize)
            {
                int count = Math.Min(blockSize, Data.Length - i);
                Buffer.BlockCopy(Data, i, XOR_ME, 0, count);
                Cipher.ProcessBlock(XOR_ME, 0, XOR_ME, 0);
                Buffer.BlockCopy(XOR_ME, 0, Output, i, count);
            }
        }
Esempio n. 2
0
 internal static void ProcessArray(BC.Crypto.IBlockCipher Cipher, byte[] Data, int DataOffset, byte[] Output, int OutputOffset, int Length)
 {
     if (Data == null || Output == null || Cipher == null)
         throw new InvalidOperationException("Null parameters not allowed.");
     if (Length + DataOffset > Data.Length)
         throw new ArgumentOutOfRangeException("Length + DataOffset > Data.Length");
     if (DataOffset >= Data.Length)
         throw new ArgumentOutOfRangeException("DataOffset > Data.Length");
     if (Length + OutputOffset > Output.Length)
         throw new ArgumentOutOfRangeException("Length + OutputOffset > Output.Length");
     if (OutputOffset >= Output.Length)
         throw new ArgumentOutOfRangeException("OutputOffset > Output.Length");
     int blockSize = Cipher.GetBlockSize();
     byte[] XOR_ME = new byte[Cipher.GetBlockSize()];
     for (int i = 0; i < Length && i < Data.Length; i += blockSize)
     {
         int count = Math.Min(blockSize, Length - i);
         Buffer.BlockCopy(Data, i + DataOffset, XOR_ME, 0, count);
         Cipher.ProcessBlock(XOR_ME, 0, XOR_ME, 0);
         Buffer.BlockCopy(XOR_ME, 0, Output, i + OutputOffset, count);
     }
 }