[Mono-list] TripleDES differences between Mono 0.28 & .NET

Sébastien Pouliot spouliot@videotron.ca
Fri, 03 Oct 2003 20:30:32 -0400


Carlos,

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.
I'll update bugzilla and, hopefully, correct CryptoStream this weekend.

Sebastien Pouliot
Security Architect, Motus Technologies, http://www.motus.com
work: spouliot@motus.com
home: spouliot@videotron.ca
blog: http://pages.infinit.net/ctech/poupou.html


-----Original Message-----
From: mono-list-admin@lists.ximian.com
[mailto:mono-list-admin@lists.ximian.com]On Behalf Of Carlos Guzman
Alvarez
Sent: 3 octobre 2003 06:56
To: Mono-List
Subject: [Mono-list] 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.

The test case is based on a piece of code from my TLS Library ( that as
i said some time ago is working well under Windows with MS.NET but not
with Mono on Linux ):

Output of the test case using MS.NET:

9c99568e753e02955b5c468bcff82721535f3dd81695823d889b9a47da979086500e48eee79b
2541
1400000cb58608e6b94b1381658e76be
2a94e53ab9f99a839d4fb0a88f470076050a5f08


Output of the Test case using Mono 0.28 (Windows)

9c99568e753e02955b5c468bcff82721535f3dd81695823d889b9a47da9790868f3e78b6ef62
4695
1400000cb58608e6b94b1381
658e76be2a94e53ab9f99a839d4fb0a88f470076


Output of the Test case using Mono 0.28 (Linux Red Hat 8)

9c99568e753e02955b5c468bcff82721535f3dd81695823d889b9a47da9790868f3e78b6ef62
4695
1400000cb58608e6b94b1381
658e76be2a94e53ab9f99a839d4fb0a88f470076


Output of the case using the exe built with mono 0.28 and the MS .NET
runtime ( runnig test.exe directly in the console seems to be using the
MS.NET framework )

9c99568e753e02955b5c468bcff82721535f3dd81695823d889b9a47da979086500e48eee79b
2541
1400000cb58608e6b94b1381658e76be
2a94e53ab9f99a839d4fb0a88f470076050a5f08


If anybody can confirm this i will fill a bug report in mono bugzilla.

The test case source code is attached to this email.




--
Best regards

Carlos Guzmán Álvarez
Vigo-Spain


"Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las
mismas cosas."

Albert Einstein.