[Mono-bugs] [Bug 49323][Nor] Changed - CryptoStream (was TripleDES) differences between Mono 0.28 & .NET

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Fri, 3 Oct 2003 20:35:49 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by spouliot@videotron.ca.

http://bugzilla.ximian.com/show_bug.cgi?id=49323

--- shadow/49323	2003-10-03 19:41:33.000000000 -0400
+++ shadow/49323.tmp.3432	2003-10-03 20:35:49.000000000 -0400
@@ -1,23 +1,23 @@
 Bug#: 49323
 Product: Mono/Class Libraries
 Version: unspecified
-OS: other
+OS: All
 OS Details: Linux Red Hat 8 & Windows
 Status: NEW   
 Resolution: 
-Severity: 
+Severity: Unknown
 Priority: Normal
-Component: System
-AssignedTo: mono-bugs@ximian.com                            
+Component: CORLIB
+AssignedTo: spouliot@videotron.ca                            
 ReportedBy: carlosga@telefonica.net               
 QAContact: mono-bugs@ximian.com
 TargetMilestone: ---
 URL: 
 Cc: 
-Summary: TripleDES differences between Mono 0.28 & .NET
+Summary: CryptoStream (was TripleDES) differences between Mono 0.28 & .NET
 
 Hello:
 
 I have made a little test case for test TripleDES using mono & ms.net and
 there are differences in the results.
 
@@ -180,6 +180,32 @@
 				Console.Write("{0}", content[i].ToString("x2"));
 			}
 			Console.WriteLine();
 		}
 	}
 }
+
+------- Additional Comments From spouliot@videotron.ca  2003-10-03 20:35 -------
+I'm happy to report that there are no bug in TripleDES ;-).
+The actual problem (still to be found) lies in CryptoStream.
+
+For a quick fix you can rewrite your code to avoid CryptoStream like:
+
+	// Encryption ( fragment + mac [+ padding + padding_length] )
+	MemoryStream ms = new MemoryStream();
+	ms.Write (fragment, 0, fragment.Length);
+	ms.Write (mac, 0, mac.Length);
+	if (cipherMode == CipherMode.CBC) {
+		// Calculate padding_length
+		int fragmentLength	= fragment.Length + mac.Length + 1;
+		int padding			= (((fragmentLength/blockSize)*8) + blockSize) -
+fragmentLength;
+		// Write padding length byte
+		ms.WriteByte((byte)padding);
+	}
+	byte[] data = ms.ToArray ();
+	byte[] ecrFragment = encryptionCipher.TransformFinalBlock (data, 0,
+data.Length);
+	// Show result
+	Print(ecrFragment);
+
+This should work correctly on both Mono and MS framework.