Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastien Pouliot <sebastien@ximian.com>2004-06-23 18:29:59 +0400
committerSebastien Pouliot <sebastien@ximian.com>2004-06-23 18:29:59 +0400
commit4ba33a11f2aee2d6b3163c3c39a458941130ffaf (patch)
tree2c6e909cc84e147c0957260b61a22a78f1f9f308 /mcs/class/Mono.Security
parent0d0a71719036a15e5b64a457dcdfcf5ba2c09543 (diff)
2004-06-23 Sebastien Pouliot <sebastien@ximian.com>
* SymmetricTransform.cs: Reduce by one the number of block when decrypting. This operation was in CryptoStream before but is only required for decryption (which CryptoStream can't know). Fix bug #60573. svn path=/trunk/mcs/; revision=30199
Diffstat (limited to 'mcs/class/Mono.Security')
-rw-r--r--mcs/class/Mono.Security/Mono.Security.Cryptography/ChangeLog7
-rwxr-xr-xmcs/class/Mono.Security/Mono.Security.Cryptography/SymmetricTransform.cs56
2 files changed, 61 insertions, 2 deletions
diff --git a/mcs/class/Mono.Security/Mono.Security.Cryptography/ChangeLog b/mcs/class/Mono.Security/Mono.Security.Cryptography/ChangeLog
index 508b578243f..5299183d037 100644
--- a/mcs/class/Mono.Security/Mono.Security.Cryptography/ChangeLog
+++ b/mcs/class/Mono.Security/Mono.Security.Cryptography/ChangeLog
@@ -1,3 +1,10 @@
+2004-06-23 Sebastien Pouliot <sebastien@ximian.com>
+
+ * SymmetricTransform.cs: Reduce by one the number of block when
+ decrypting. This operation was in CryptoStream before but is only
+ required for decryption (which CryptoStream can't know).
+ Fix bug #60573.
+
2004-05-27 Sebastien Pouliot <sebastien@ximian.com>
* ARC4Managed.cs: Added missing exception handling in TransformBlock
diff --git a/mcs/class/Mono.Security/Mono.Security.Cryptography/SymmetricTransform.cs b/mcs/class/Mono.Security/Mono.Security.Cryptography/SymmetricTransform.cs
index f3784c6eec3..c93637ce746 100755
--- a/mcs/class/Mono.Security/Mono.Security.Cryptography/SymmetricTransform.cs
+++ b/mcs/class/Mono.Security/Mono.Security.Cryptography/SymmetricTransform.cs
@@ -9,6 +9,29 @@
// (C) 2004 Novell (http://www.novell.com)
//
+//
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
using System;
using System.Security.Cryptography;
@@ -34,6 +57,7 @@ namespace Mono.Security.Cryptography {
private int FeedBackByte;
private int FeedBackIter;
private bool m_disposed = false;
+ private bool lastBlock;
public SymmetricTransform (SymmetricAlgorithm symmAlgo, bool encryption, byte[] rgbIV)
{
@@ -229,7 +253,19 @@ namespace Mono.Security.Cryptography {
else
full = 1;
+ if (!encrypt)
+ full--;
+
int total = 0;
+
+ if (lastBlock) {
+ Transform (workBuff, workout);
+ Buffer.BlockCopy (workout, 0, outputBuffer, outputOffset, BlockSizeByte);
+ outputOffset += BlockSizeByte;
+ total += BlockSizeByte;
+ lastBlock = false;
+ }
+
for (int i = 0; i < full; i++) {
Buffer.BlockCopy (inputBuffer, offs, workBuff, 0, BlockSizeByte);
Transform (workBuff, workout);
@@ -239,6 +275,11 @@ namespace Mono.Security.Cryptography {
total += BlockSizeByte;
}
+ if (!encrypt) {
+ Buffer.BlockCopy (inputBuffer, offs, workBuff, 0, BlockSizeByte);
+ lastBlock = true;
+ }
+
return total;
}
@@ -301,15 +342,26 @@ namespace Mono.Security.Cryptography {
throw new CryptographicException ("Invalid input block size.");
int total = inputCount;
+ if (lastBlock)
+ total += BlockSizeByte;
+
byte[] res = new byte [total];
int outputOffset = 0;
+
while (inputCount > 0) {
- InternalTransformBlock (inputBuffer, inputOffset, BlockSizeByte, res, outputOffset);
+ int len = InternalTransformBlock (inputBuffer, inputOffset, BlockSizeByte, res, outputOffset);
inputOffset += BlockSizeByte;
- outputOffset += BlockSizeByte;
+ outputOffset += len;
inputCount -= BlockSizeByte;
}
+ if (lastBlock) {
+ Transform (workBuff, workout);
+ Buffer.BlockCopy (workout, 0, res, outputOffset, BlockSizeByte);
+ outputOffset += BlockSizeByte;
+ lastBlock = false;
+ }
+
switch (algo.Padding) {
case PaddingMode.None: // nothing to do - it's a multiple of block size
case PaddingMode.Zeros: // nothing to do - user must unpad himself