Permalink
Browse files

2005-01-06 Sebastien Pouliot <sebastien@ximian.com>

	* desweak.cs: Add test to check for regression of the bug seen in
	rev 38316. The original code that failed is no more part of the
	class library.


svn path=/trunk/mono/; revision=38469
  • Loading branch information...
1 parent 15f010b commit 0e4260ab942c183cfc4f89886b3ca98eecd316c9 Sebastien Pouliot committed Jan 6, 2005
Showing with 54 additions and 1 deletion.
  1. +6 −0 mono/tests/ChangeLog
  2. +2 −1 mono/tests/Makefile.am
  3. +46 −0 mono/tests/desweak.cs
View
@@ -1,3 +1,9 @@
+2005-01-06 Sebastien Pouliot <sebastien@ximian.com>
+
+ * desweak.cs: Add test to check for regression of the bug seen in
+ rev 38316. The original code that failed is no more part of the
+ class library.
+
2005-01-06 Zoltan Varga <vargaz@freemail.hu>
* libtest.c: Fix blittable_struct_delegate test.
View
@@ -182,7 +182,8 @@ TEST_CS_SRC= \
bug-48015.cs \
bug-42136.cs \
interlocked.cs \
- cross-domain.cs
+ cross-domain.cs \
+ desweak.cs
if X86
PLATFORM_DISABLED_TESTS=
View
@@ -0,0 +1,46 @@
+// DESTest.cs was failing with rev 38316...
+// but the DES code was changed after the fix
+// so the original code lives here forever ;-)
+
+using System;
+
+class Program {
+
+ public const int keySizeByte = 8;
+
+ internal static readonly ulong[] weakKeys = {
+ 0x0101010101010101, /* 0000000 0000000 */
+ 0xFEFEFEFEFEFEFEFE, /* FFFFFFF FFFFFFF */
+ 0x1F1F1F1F0E0E0E0E, /* 0000000 FFFFFFF */
+ 0xE0E0E0E0F1F1F1F1 /* FFFFFFF 0000000 */
+ };
+
+ internal static ulong PackKey (byte[] key)
+ {
+ byte[] paritySetKey = new byte [keySizeByte];
+ // adapted from bouncycastle - see bouncycastle.txt
+ for (int i=0; i < key.Length; i++) {
+ byte b = key [i];
+ paritySetKey [i] = (byte)((b & 0xfe) |
+ ((((b >> 1) ^ (b >> 2) ^ (b >> 3) ^ (b >> 4) ^
+ (b >> 5) ^ (b >> 6) ^ (b >> 7)) ^ 0x01) & 0x01));
+ }
+
+ ulong res = 0;
+ for (int i = 0, sh = 64; (sh = sh - 8) >= 0; i++) {
+ res |= (ulong) paritySetKey [i] << sh;
+ }
+ return res;
+ }
+
+ static int Main ()
+ {
+ byte[] wk2p = { 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E };
+ ulong lk = PackKey (wk2p);
+ foreach (ulong wk in weakKeys) {
+ if (lk == wk)
+ return 0;
+ }
+ return 1;
+ }
+}

0 comments on commit 0e4260a

Please sign in to comment.