diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-07-21 11:17:15 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-07-21 11:17:15 +0700 |
commit | 59d03bc3a805274c5ef855f6f8099cb9c2a8319d (patch) | |
tree | 46399a661edd902c51d1514b8a31f8ed1058883e /crypto | |
parent | De-tabify (diff) | |
download | BouncyCastle.NET-ed25519-59d03bc3a805274c5ef855f6f8099cb9c2a8319d.tar.xz |
De-tabify
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/src/crypto/modes/SicBlockCipher.cs | 176 |
1 files changed, 88 insertions, 88 deletions
diff --git a/crypto/src/crypto/modes/SicBlockCipher.cs b/crypto/src/crypto/modes/SicBlockCipher.cs index 07c5d1978..da7ed7859 100644 --- a/crypto/src/crypto/modes/SicBlockCipher.cs +++ b/crypto/src/crypto/modes/SicBlockCipher.cs @@ -5,52 +5,52 @@ using Org.BouncyCastle.Math; namespace Org.BouncyCastle.Crypto.Modes { - /** - * Implements the Segmented Integer Counter (SIC) mode on top of a simple - * block cipher. - */ - public class SicBlockCipher - : IBlockCipher - { - private readonly IBlockCipher cipher; - private readonly int blockSize; - private readonly byte[] IV; - private readonly byte[] counter; - private readonly byte[] counterOut; + /** + * Implements the Segmented Integer Counter (SIC) mode on top of a simple + * block cipher. + */ + public class SicBlockCipher + : IBlockCipher + { + private readonly IBlockCipher cipher; + private readonly int blockSize; + private readonly byte[] IV; + private readonly byte[] counter; + private readonly byte[] counterOut; - /** - * Basic constructor. - * - * @param c the block cipher to be used. - */ - public SicBlockCipher(IBlockCipher cipher) - { - this.cipher = cipher; - this.blockSize = cipher.GetBlockSize(); - this.IV = new byte[blockSize]; - this.counter = new byte[blockSize]; - this.counterOut = new byte[blockSize]; - } + /** + * Basic constructor. + * + * @param c the block cipher to be used. + */ + public SicBlockCipher(IBlockCipher cipher) + { + this.cipher = cipher; + this.blockSize = cipher.GetBlockSize(); + this.IV = new byte[blockSize]; + this.counter = new byte[blockSize]; + this.counterOut = new byte[blockSize]; + } - /** - * return the underlying block cipher that we are wrapping. - * - * @return the underlying block cipher that we are wrapping. - */ - public IBlockCipher GetUnderlyingCipher() - { - return cipher; - } + /** + * return the underlying block cipher that we are wrapping. + * + * @return the underlying block cipher that we are wrapping. + */ + public IBlockCipher GetUnderlyingCipher() + { + return cipher; + } - public void Init( - bool forEncryption, //ignored by this CTR mode - ICipherParameters parameters) - { - if (parameters is ParametersWithIV) - { - ParametersWithIV ivParam = (ParametersWithIV) parameters; - byte[] iv = ivParam.GetIV(); - Array.Copy(iv, 0, IV, 0, IV.Length); + public void Init( + bool forEncryption, //ignored by this CTR mode + ICipherParameters parameters) + { + if (parameters is ParametersWithIV) + { + ParametersWithIV ivParam = (ParametersWithIV) parameters; + byte[] iv = ivParam.GetIV(); + Array.Copy(iv, 0, IV, 0, IV.Length); Reset(); @@ -59,57 +59,57 @@ namespace Org.BouncyCastle.Crypto.Modes { cipher.Init(true, ivParam.Parameters); } - } - else - { - throw new ArgumentException("SIC mode requires ParametersWithIV", "parameters"); - } - } + } + else + { + throw new ArgumentException("SIC mode requires ParametersWithIV", "parameters"); + } + } - public string AlgorithmName - { - get { return cipher.AlgorithmName + "/SIC"; } - } + public string AlgorithmName + { + get { return cipher.AlgorithmName + "/SIC"; } + } - public bool IsPartialBlockOkay - { - get { return true; } - } + public bool IsPartialBlockOkay + { + get { return true; } + } - public int GetBlockSize() - { - return cipher.GetBlockSize(); - } + public int GetBlockSize() + { + return cipher.GetBlockSize(); + } - public int ProcessBlock( - byte[] input, - int inOff, - byte[] output, - int outOff) - { - cipher.ProcessBlock(counter, 0, counterOut, 0); + public int ProcessBlock( + byte[] input, + int inOff, + byte[] output, + int outOff) + { + cipher.ProcessBlock(counter, 0, counterOut, 0); - // - // XOR the counterOut with the plaintext producing the cipher text - // - for (int i = 0; i < counterOut.Length; i++) - { - output[outOff + i] = (byte)(counterOut[i] ^ input[inOff + i]); - } + // + // XOR the counterOut with the plaintext producing the cipher text + // + for (int i = 0; i < counterOut.Length; i++) + { + output[outOff + i] = (byte)(counterOut[i] ^ input[inOff + i]); + } - // Increment the counter - int j = counter.Length; - while (--j >= 0 && ++counter[j] == 0) - { - } + // Increment the counter + int j = counter.Length; + while (--j >= 0 && ++counter[j] == 0) + { + } - return counter.Length; - } + return counter.Length; + } - public void Reset() - { - Array.Copy(IV, 0, counter, 0, counter.Length); - cipher.Reset(); - } - } + public void Reset() + { + Array.Copy(IV, 0, counter, 0, counter.Length); + cipher.Reset(); + } + } } |