diff options
author | Sebastien Pouliot <sebastien@ximian.com> | 2004-05-27 16:40:08 +0400 |
---|---|---|
committer | Sebastien Pouliot <sebastien@ximian.com> | 2004-05-27 16:40:08 +0400 |
commit | ea3e5137cfa08e58d9d7dbda7b9e9996ae963b6d (patch) | |
tree | 4b12055a815fd8a06e1bd90285202e9c51d5b98c /mcs/class/Mono.Security | |
parent | ead10bbbe345498755d6bfa44e24554898e1e595 (diff) |
2004-05-27 Sebastien Pouliot <sebastien@ximian.com>
* SymmetricTransform.cs: Added missing exception handling in
TransformBlock and TransformFinalBlock.
svn path=/trunk/mcs/; revision=28259
Diffstat (limited to 'mcs/class/Mono.Security')
-rw-r--r-- | mcs/class/Mono.Security/Mono.Security.Cryptography/ChangeLog | 3 | ||||
-rwxr-xr-x | mcs/class/Mono.Security/Mono.Security.Cryptography/SymmetricTransform.cs | 43 |
2 files changed, 36 insertions, 10 deletions
diff --git a/mcs/class/Mono.Security/Mono.Security.Cryptography/ChangeLog b/mcs/class/Mono.Security/Mono.Security.Cryptography/ChangeLog index 1f378cbb8e8..508b578243f 100644 --- a/mcs/class/Mono.Security/Mono.Security.Cryptography/ChangeLog +++ b/mcs/class/Mono.Security/Mono.Security.Cryptography/ChangeLog @@ -2,7 +2,8 @@ * ARC4Managed.cs: Added missing exception handling in TransformBlock and TransformFinalBlock. - * SymmetricTransform.cs: Fixed possible integer overflow. + * SymmetricTransform.cs: Fixed possible integer overflow. Added + missing exception handling in TransformBlock and TransformFinalBlock. 2004-05-10 Sebastien Pouliot <sebastien@ximian.com> diff --git a/mcs/class/Mono.Security/Mono.Security.Cryptography/SymmetricTransform.cs b/mcs/class/Mono.Security/Mono.Security.Cryptography/SymmetricTransform.cs index 0efad25e85f..f3784c6eec3 100755 --- a/mcs/class/Mono.Security/Mono.Security.Cryptography/SymmetricTransform.cs +++ b/mcs/class/Mono.Security/Mono.Security.Cryptography/SymmetricTransform.cs @@ -182,15 +182,39 @@ namespace Mono.Security.Cryptography { throw new NotImplementedException ("CTS not yet supported"); } + private void CheckInput (byte[] inputBuffer, int inputOffset, int inputCount) + { + if (inputBuffer == null) + throw new ArgumentNullException ("inputBuffer"); + if (inputOffset < 0) + throw new ArgumentOutOfRangeException ("inputOffset", "< 0"); + if (inputCount < 0) + throw new ArgumentOutOfRangeException ("inputCount", "< 0"); + // ordered to avoid possible integer overflow + if (inputOffset > inputBuffer.Length - inputCount) + throw new ArgumentException ("inputBuffer", Locale.GetText ("Overflow")); + } + // this method may get called MANY times so this is the one to optimize - public virtual int TransformBlock (byte [] inputBuffer, int inputOffset, int inputCount, byte [] outputBuffer, int outputOffset) + public virtual int TransformBlock (byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset) { if (m_disposed) throw new ObjectDisposedException ("Object is disposed"); - // reordered to avoid possible integer overflow + CheckInput (inputBuffer, inputOffset, inputCount); + // check output parameters + if (outputBuffer == null) + throw new ArgumentNullException ("outputBuffer"); + if (outputOffset < 0) + throw new ArgumentOutOfRangeException ("outputOffset", "< 0"); + // ordered to avoid possible integer overflow if (outputOffset > outputBuffer.Length - inputCount) - throw new CryptographicException ("Insufficient output buffer size."); + throw new ArgumentException ("outputBuffer", Locale.GetText ("Overflow")); + return InternalTransformBlock (inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + } + + private int InternalTransformBlock (byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset) + { int offs = inputOffset; int full; @@ -250,7 +274,7 @@ namespace Mono.Security.Cryptography { // process all blocks except the last (final) block while (total > BlockSizeByte) { - TransformBlock (inputBuffer, inputOffset, BlockSizeByte, res, outputOffset); + InternalTransformBlock (inputBuffer, inputOffset, BlockSizeByte, res, outputOffset); inputOffset += BlockSizeByte; outputOffset += BlockSizeByte; total -= BlockSizeByte; @@ -263,15 +287,15 @@ namespace Mono.Security.Cryptography { res [i] = padding; Buffer.BlockCopy (inputBuffer, inputOffset, res, full, rem); // the last padded block will be transformed in-place - TransformBlock (res, full, BlockSizeByte, res, full); + InternalTransformBlock (res, full, BlockSizeByte, res, full); } else - TransformBlock (inputBuffer, inputOffset, BlockSizeByte, res, outputOffset); + InternalTransformBlock (inputBuffer, inputOffset, BlockSizeByte, res, outputOffset); return res; } - private byte[] FinalDecrypt (byte [] inputBuffer, int inputOffset, int inputCount) + private byte[] FinalDecrypt (byte[] inputBuffer, int inputOffset, int inputCount) { if ((inputCount % BlockSizeByte) > 0) throw new CryptographicException ("Invalid input block size."); @@ -280,7 +304,7 @@ namespace Mono.Security.Cryptography { byte[] res = new byte [total]; int outputOffset = 0; while (inputCount > 0) { - TransformBlock (inputBuffer, inputOffset, BlockSizeByte, res, outputOffset); + InternalTransformBlock (inputBuffer, inputOffset, BlockSizeByte, res, outputOffset); inputOffset += BlockSizeByte; outputOffset += BlockSizeByte; inputCount -= BlockSizeByte; @@ -307,10 +331,11 @@ namespace Mono.Security.Cryptography { return new byte [0]; } - public virtual byte [] TransformFinalBlock (byte [] inputBuffer, int inputOffset, int inputCount) + public virtual byte[] TransformFinalBlock (byte[] inputBuffer, int inputOffset, int inputCount) { if (m_disposed) throw new ObjectDisposedException ("Object is disposed"); + CheckInput (inputBuffer, inputOffset, inputCount); if (encrypt) return FinalEncrypt (inputBuffer, inputOffset, inputCount); |