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); } }
public static KeySizes[] GetBlockSizes(object algo) { SymmetricAlgorithm sa = algo as SymmetricAlgorithm; if (sa != null) { return(sa.LegalBlockSizes); } Org.BouncyCastle.Crypto.IBlockCipher cipher = algo as Org.BouncyCastle.Crypto.IBlockCipher; if (cipher == null) { throw new NotSupportedException(); } return(new KeySizes[] { new KeySizes(128, 128, 0) }); }
// ['blockcontents' 'LENGTH in bytes'] // [magicbytes 4][version 4][salt 16][hmacsha512 64][hmacsha3_512 64][aesiv 16][ciphertext (variable length)] // embedded in the ciphertext are an additional 24 for the xsalsa20 IV, twofish removed! 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); } }