2002-12-27 Sebastien Pouliot <spouliot@videotron.ca>
authorSebastien Pouliot <sebastien@ximian.com>
Fri, 27 Dec 2002 18:32:44 +0000 (18:32 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Fri, 27 Dec 2002 18:32:44 +0000 (18:32 -0000)
* CryptoTools.cs: New. Shared classes for cryptography. Now
includes a KeyBuilder to generate symmetric keys and IV.
* DES.cs: Modified Key validation.
* DESCryptoServiceProvider.cs: Implemented Key and IV using
KeyBuilder.
* RC2CryptoServiceProvider.cs: Implemented Key and IV using
KeyBuilder (and removed TODO).
* RijndaelManaged.cs: Implemented Key and IV using KeyBuilder
(and removed TODO).
* SHA384Managed.cs: Changed code to remove compiler warning.
* SHA512Managed.cs: Changed code to remove compiler warning.
* SymmetricAlgorithm.cs: Removed TODO on IV.
* TripleDESCryptoServiceProvider.cs: Implemented Key and IV
using KeyBuilder (and removed TODO).

svn path=/trunk/mcs/; revision=9933

mcs/class/corlib/Mono.Security.Cryptography/CryptoTools.cs [new file with mode: 0644]
mcs/class/corlib/System.Security.Cryptography/ChangeLog
mcs/class/corlib/System.Security.Cryptography/CryptoTools.cs [new file with mode: 0644]
mcs/class/corlib/System.Security.Cryptography/DES.cs
mcs/class/corlib/System.Security.Cryptography/DESCryptoServiceProvider.cs
mcs/class/corlib/System.Security.Cryptography/RC2CryptoServiceProvider.cs
mcs/class/corlib/System.Security.Cryptography/RijndaelManaged.cs
mcs/class/corlib/System.Security.Cryptography/SHA384Managed.cs
mcs/class/corlib/System.Security.Cryptography/SHA512Managed.cs
mcs/class/corlib/System.Security.Cryptography/SymmetricAlgorithm.cs
mcs/class/corlib/System.Security.Cryptography/TripleDESCryptoServiceProvider.cs

diff --git a/mcs/class/corlib/Mono.Security.Cryptography/CryptoTools.cs b/mcs/class/corlib/Mono.Security.Cryptography/CryptoTools.cs
new file mode 100644 (file)
index 0000000..8b98202
--- /dev/null
@@ -0,0 +1,39 @@
+//
+// System.Security.Cryptography.CryptoTools
+//     Shared class for common cryptographic functionalities
+//
+// Authors:
+//   Sebastien Pouliot (spouliot@motus.com)
+//
+// Portions (C) 2002 Motus Technologies Inc. (http://www.motus.com)
+//
+
+using System;
+
+namespace System.Security.Cryptography {
+
+internal class KeyBuilder {
+
+       static private RandomNumberGenerator rng;
+
+       static KeyBuilder () 
+       {
+               rng = RandomNumberGenerator.Create ();
+       }
+
+       static public byte[] Key (int size) 
+       {
+               byte[] key = new byte [size];
+               rng.GetBytes (key);
+               return key;
+       }
+
+       static public byte[] IV (int size) 
+       {
+               byte[] iv = new byte [size];
+               rng.GetBytes (iv);
+               return iv;
+       }
+}
+
+}
index a6ac0292f86ba554ead2048fe8e9c6368343afc0..9b55810cb85f44d2df0413d90b1eca83f5b15ffc 100644 (file)
@@ -1,3 +1,20 @@
+2002-12-27  Sebastien Pouliot  <spouliot@videotron.ca>
+
+       * CryptoTools.cs: New. Shared classes for cryptography. Now
+       includes a KeyBuilder to generate symmetric keys and IV.
+       * DES.cs: Modified Key validation.
+       * DESCryptoServiceProvider.cs: Implemented Key and IV using
+       KeyBuilder.
+       * RC2CryptoServiceProvider.cs: Implemented Key and IV using
+       KeyBuilder (and removed TODO).
+       * RijndaelManaged.cs: Implemented Key and IV using KeyBuilder 
+       (and removed TODO).
+       * SHA384Managed.cs: Changed code to remove compiler warning.
+       * SHA512Managed.cs: Changed code to remove compiler warning.
+       * SymmetricAlgorithm.cs: Removed TODO on IV.
+       * TripleDESCryptoServiceProvider.cs: Implemented Key and IV
+       using KeyBuilder (and removed TODO).
+
 2002-11-20  Sebastien Pouliot  <spouliot@videotron.ca>
 
        * AsymmetricSignatureDeformatter.cs: Added exception handling in
diff --git a/mcs/class/corlib/System.Security.Cryptography/CryptoTools.cs b/mcs/class/corlib/System.Security.Cryptography/CryptoTools.cs
new file mode 100644 (file)
index 0000000..8b98202
--- /dev/null
@@ -0,0 +1,39 @@
+//
+// System.Security.Cryptography.CryptoTools
+//     Shared class for common cryptographic functionalities
+//
+// Authors:
+//   Sebastien Pouliot (spouliot@motus.com)
+//
+// Portions (C) 2002 Motus Technologies Inc. (http://www.motus.com)
+//
+
+using System;
+
+namespace System.Security.Cryptography {
+
+internal class KeyBuilder {
+
+       static private RandomNumberGenerator rng;
+
+       static KeyBuilder () 
+       {
+               rng = RandomNumberGenerator.Create ();
+       }
+
+       static public byte[] Key (int size) 
+       {
+               byte[] key = new byte [size];
+               rng.GetBytes (key);
+               return key;
+       }
+
+       static public byte[] IV (int size) 
+       {
+               byte[] iv = new byte [size];
+               rng.GetBytes (iv);
+               return iv;
+       }
+}
+
+}
index c3e7982ae224b9df3e5f8cab455aafca52b90b3e..16cc456f1f067aa53efd5f7a106032ac3b628457 100644 (file)
@@ -83,7 +83,7 @@ public abstract class DES : SymmetricAlgorithm {
        public static bool IsWeakKey (byte [] rgbKey)
        {
                if (rgbKey.Length == (blockSizeByte >> 3))
-                       throw new CryptographicException ();
+                       throw new CryptographicException ("Wrong Key Length");
 
                ulong lk = PackKey (rgbKey);
                foreach (ulong wk in weakKeys) {
@@ -95,7 +95,7 @@ public abstract class DES : SymmetricAlgorithm {
        public static bool IsSemiWeakKey (byte [] rgbKey)
        {
                if (rgbKey.Length == (blockSizeByte >> 3))
-                       throw new CryptographicException ();
+                       throw new CryptographicException ("Wrong Key Length");
 
                ulong lk = PackKey (rgbKey);
                foreach (ulong swk in semiweakKeys) {
@@ -105,22 +105,13 @@ public abstract class DES : SymmetricAlgorithm {
        }
 
        public override byte[] Key {
-               get { 
-                       if (KeyValue == null)
-                               return base.Key;
-                       else
-                               return KeyValue;
-               }
+               get { return base.Key; }
                set {
                        if (value == null)
                                throw new ArgumentNullException ();
-                       if (value.Length != (blockSizeByte >> 3))
-                               throw new ArgumentException ();
                        if (IsWeakKey (value) || IsSemiWeakKey (value))
                                throw new CryptographicException ();
-
-                       KeyValue = new byte [8];
-                       Array.Copy (value, 0, KeyValue, 0, blockSizeByte);
+                       base.Key = value;
                }
        }
 
index 9605619f234c8d9c9855d06b379894b481cd9309..f5846fcd1804528f71e26d8a8e5ce8448882566b 100644 (file)
@@ -1,7 +1,7 @@
 //
 // System.Security.Cryptography.DESCryptoServiceProvider
 //
-// Author:
+// Authors:
 //   Sergey Chaban (serge@wildwestsoftware.com)
 //   Sebastien Pouliot (spouliot@motus.com)
 //
@@ -10,7 +10,6 @@
 
 
 using System;
-using System.Security.Cryptography;
 
 namespace System.Security.Cryptography {
 
@@ -431,37 +430,33 @@ internal class DESTransform : SymmetricTransform {
 } 
 
 public sealed class DESCryptoServiceProvider : DES {
-       private RandomNumberGenerator rng;
 
-       public DESCryptoServiceProvider () : base ()
-       {
-               // there are no constructor accepting a secret key
-               // so we always need the RNG (using the default one)
-               rng = RandomNumberGenerator.Create ();
-       }
+       public DESCryptoServiceProvider () : base () {}
 
        public override ICryptoTransform CreateDecryptor (byte[] rgbKey, byte[] rgbIV) 
        {
+               Key = rgbKey;
+               IV = rgbIV;
                return new DESTransform (this, false, rgbKey, rgbIV);
        }
 
        public override ICryptoTransform CreateEncryptor (byte[] rgbKey, byte[] rgbIV) 
        {
+               Key = rgbKey;
+               IV = rgbIV;
                return new DESTransform (this, true, rgbKey, rgbIV);
        }
 
        public override void GenerateIV () 
        {
-               IVValue = new byte [(BlockSizeValue >> 3)];
-               rng.GetBytes (IVValue);
+               IVValue = KeyBuilder.IV (BlockSizeValue >> 3);
        }
 
        public override void GenerateKey () 
        {
-               KeyValue = new byte [(KeySizeValue >> 3)];
-               rng.GetBytes (KeyValue);
+               KeyValue = KeyBuilder.Key (KeySizeValue >> 3);
                while (IsWeakKey (KeyValue) || IsSemiWeakKey (KeyValue))
-                       rng.GetBytes (KeyValue);
+                       KeyValue = KeyBuilder.Key (KeySizeValue >> 3);
        }
 
 } // DESCryptoServiceProvider
index c0df11b99252738bb3ba2f3422b97131ecbe8872..20b981137253204ced6ac667b4619e0a4d88151c 100644 (file)
@@ -11,14 +11,16 @@ public sealed class RC2CryptoServiceProvider : RC2 {
        public RC2CryptoServiceProvider() {}\r\r  // included to (exactly) match corlib\r  public override int EffectiveKeySize {\r         get { return base.EffectiveKeySize; }\r          set { base.EffectiveKeySize = value; }\r }\r
        public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[] rgbIV)\r  {\r              Key = rgbKey;\r          IV = rgbIV;\r            return new RC2Transform (this, false);\r }\r
        public override ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[] rgbIV)\r  {\r              Key = rgbKey;\r          IV = rgbIV;\r            return new RC2Transform (this, true);\r  }\r
-       [MonoTODO]\r     public override void GenerateIV()\r      {\r              IVValue = new byte[BlockSizeValue / 8];\r                for (int i=0; i < IVValue.Length; i++) IVValue[i] = 0;\r }\r
-       [MonoTODO]\r     public override void GenerateKey()\r     {\r              KeyValue = new byte[KeySizeValue / 8];\r         for (int i=0; i < KeyValue.Length; i++) KeyValue[i] = 0;\r       }\r}\r
-       internal class RC2Transform : SymmetricTransform\r       {\r              public RC2Transform (RC2 rc2Algo, bool encryption) : base (rc2Algo, encryption, rc2Algo.IV)\r            {\r                      R = new UInt32 [4];\r                    KeySetup (rc2Algo.Key, rc2Algo.EffectiveKeySize);\r              }\r
-               private void KeySetup (byte[] key, int t1) \r            {               \r                       // Expand key into a byte array, then convert to word\r                  // array since we always access the key in 16bit chunks.\r                       byte[] L = new byte [128];\r     \r                       int t = key.Length;\r                    int t8 = ((t1 + 7) >> 3); // divide by 8\r                       int tm = 255 % (2 << (8 + t1 - 8*t8 - 1));\r     \r                       Array.Copy (key, 0, L, 0, t);\r  \r                       for (int i=t; i < 128; i++) \r                           L [i] = (byte) (pitable [(L [i-1] + L [i-t]) & 0xff]);\r \r                       L [128-t8] = pitable [L [128-t8] & tm];\r        \r                       for (int i=127-t8; i >= 0; i--) \r                               L [i] = pitable [L [i+1] ^ L [i+t8]];\r  \r                       K = new UInt32 [64];\r                   int pos = 0;\r                   for (int i=0; i < 64; i++) \r                            K [i] = (UInt32) (L [pos++] + L [pos++] * 256);\r                }\r
-               protected override void ECB (byte[] input, byte[] output) 
-               {
-                       // unrolled loop, eliminated mul
-                       R [0] = (UInt32) (input [0] + (input [1] << 8));\r                       R [1] = (UInt32) (input [2] + (input [3] << 8));\r                       R [2] = (UInt32) (input [4] + (input [5] << 8));\r                       R [3] = (UInt32) (input [6] + (input [7] << 8));\r       \r                       if (encrypt) {\r                         j = 0;\r                         Mix(); Mix(); Mix(); Mix(); Mix();\r                             Mash();\r                                Mix(); Mix(); Mix(); Mix(); Mix(); Mix();\r                              Mash();\r                                Mix(); Mix(); Mix(); Mix(); Mix();\r                     } \r                     else {\r                         j = 63;\r                                RMix(); RMix(); RMix(); RMix(); RMix();\r                                RMash();\r                               RMix(); RMix(); RMix(); RMix(); RMix(); RMix();\r                                RMash();\r                               RMix(); RMix(); RMix(); RMix(); RMix();\r                        }\r\r                     // unrolled loop
-                       output[0] = (byte) (R [0] & 0xff);\r                     output[1] = (byte) ((R [0] >> 8) & 0xff);\r                      output[2] = (byte) (R [1] & 0xff);\r                     output[3] = (byte) ((R [1] >> 8) & 0xff);\r                      output[4] = (byte) (R [2] & 0xff);\r                     output[5] = (byte) ((R [2] >> 8) & 0xff);\r                      output[6] = (byte) (R [3] & 0xff);\r                     output[7] = (byte) ((R [3] >> 8) & 0xff);\r              }\r\r             static public byte[] pitable = {\r                       0xd9, 0x78, 0xf9, 0xc4, 0x19, 0xdd, 0xb5, 0xed, \r                       0x28, 0xe9, 0xfd, 0x79, 0x4a, 0xa0, 0xd8, 0x9d,\r                        0xc6, 0x7e, 0x37, 0x83, 0x2b, 0x76, 0x53, 0x8e, \r                       0x62, 0x4c, 0x64, 0x88, 0x44, 0x8b, 0xfb, 0xa2,\r                        0x17, 0x9a, 0x59, 0xf5, 0x87, 0xb3, 0x4f, 0x13, \r                       0x61, 0x45, 0x6d, 0x8d, 0x09, 0x81, 0x7d, 0x32,\r                        0xbd, 0x8f, 0x40, 0xeb, 0x86, 0xb7, 0x7b, 0x0b, \r                       0xf0, 0x95, 0x21, 0x22, 0x5c, 0x6b, 0x4e, 0x82,\r                        0x54, 0xd6, 0x65, 0x93, 0xce, 0x60, 0xb2, 0x1c, \r                       0x73, 0x56, 0xc0, 0x14, 0xa7, 0x8c, 0xf1, 0xdc,\r                        0x12, 0x75, 0xca, 0x1f, 0x3b, 0xbe, 0xe4, 0xd1, \r                       0x42, 0x3d, 0xd4, 0x30, 0xa3, 0x3c, 0xb6, 0x26,\r                        0x6f, 0xbf, 0x0e, 0xda, 0x46, 0x69, 0x07, 0x57, \r                       0x27, 0xf2, 0x1d, 0x9b, 0xbc, 0x94, 0x43, 0x03,\r                        0xf8, 0x11, 0xc7, 0xf6, 0x90, 0xef, 0x3e, 0xe7, \r                       0x06, 0xc3, 0xd5, 0x2f, 0xc8, 0x66, 0x1e, 0xd7,\r                        0x08, 0xe8, 0xea, 0xde, 0x80, 0x52, 0xee, 0xf7, \r                       0x84, 0xaa, 0x72, 0xac, 0x35, 0x4d, 0x6a, 0x2a,\r                        0x96, 0x1a, 0xd2, 0x71, 0x5a, 0x15, 0x49, 0x74, \r                       0x4b, 0x9f, 0xd0, 0x5e, 0x04, 0x18, 0xa4, 0xec,\r                        0xc2, 0xe0, 0x41, 0x6e, 0x0f, 0x51, 0xcb, 0xcc, \r                       0x24, 0x91, 0xaf, 0x50, 0xa1, 0xf4, 0x70, 0x39,\r                        0x99, 0x7c, 0x3a, 0x85, 0x23, 0xb8, 0xb4, 0x7a, \r                       0xfc, 0x02, 0x36, 0x5b, 0x25, 0x55, 0x97, 0x31,\r                        0x2d, 0x5d, 0xfa, 0x98, 0xe3, 0x8a, 0x92, 0xae, \r                       0x05, 0xdf, 0x29, 0x10, 0x67, 0x6c, 0xba, 0xc9,\r                        0xd3, 0x00, 0xe6, 0xcf, 0xe1, 0x9e, 0xa8, 0x2c, \r                       0x63, 0x16, 0x01, 0x3f, 0x58, 0xe2, 0x89, 0xa9,\r                        0x0d, 0x38, 0x34, 0x1b, 0xab, 0x33, 0xff, 0xb0, \r                       0xbb, 0x48, 0x0c, 0x5f, 0xb9, 0xb1, 0xcd, 0x2e,\r                        0xc5, 0xf3, 0xdb, 0x47, 0xe5, 0xa5, 0x9c, 0x77, \r                       0x0a, 0xa6, 0x20, 0x68, 0xfe, 0x7f, 0xc1, 0xad };\r      \r               // The expanded key (in bottom 16 bits of each word)\r           public UInt32[] K;\r     \r               // The state (again in bottom 16 bits, although we only\r                // clear the top 16 bits if needed)\r            private UInt32[] R;\r    \r               // Key indexer\r         private int j;\r \r               private void Mix() \r            {\r                      R[0] += K[j]   + (R[3] & R[2]) + ((~R[3]) & R[1]);\r                     R[0] = (R[0] << 1) | (R[0]>>15 & 0x1);\r \r                       R[1] += K[j+1] + (R[0] & R[3]) + ((~R[0]) & R[2]);\r                     R[1] = (R[1] << 2) | (R[1]>>14 & 0x3);\r \r                       R[2] += K[j+2] + (R[1] & R[0]) + ((~R[1]) & R[3]);\r                     R[2] = (R[2] << 3) | (R[2]>>13 & 0x7);\r \r                       R[3] += K[j+3] + (R[2] & R[1]) + ((~R[2]) & R[0]);\r                     R[3] = (R[3] << 5) | (R[3]>>11 & 0x1f);\r                        j += 4;\r                }\r      \r               private void RMix() \r           {\r                      R[3] &= 0xffff;\r                        R[3] = (R[3] >> 5) | ((R[3] & 0x1f) << 11);\r                    R[3] -= K[j] + (R[2] & R[1]) + ((~R[2]) & R[0]);\r       \r                       R[2] &= 0xffff;\r                        R[2] = (R[2] >> 3) | ((R[2] & 0x7) << 13);\r                     R[2] -= K[j-1] + (R[1] & R[0]) + ((~R[1]) & R[3]);\r\r                    R[1] &= 0xffff;\r                        R[1] = (R[1] >> 2) | ((R[1] & 0x3) << 14);\r                     R[1] -= K[j-2] + (R[0] & R[3]) + ((~R[0]) & R[2]);\r     \r                       R[0] &= 0xffff;\r                        R[0] = (R[0] >> 1) | ((R[0] & 0x1) << 15);\r                     R[0] -= K[j-3] + (R[3] & R[2]) + ((~R[3]) & R[1]);\r     \r                       j -= 4;\r                }\r
-               private void Mash ()\r           {\r                      R [0] += K [R [3] & 63];\r                       R [1] += K [R [0] & 63];\r                       R [2] += K [R [1] & 63];\r                       R [3] += K [R [2] & 63];\r               }\r
-               private void RMash ()\r          {\r                      R [3] -= K [R [2] & 63];\r                       R [2] -= K [R [1] & 63];\r                       R [1] -= K [R [0] & 63];\r                       R [0] -= K [R [3] & 63];\r               }\r      }\r}\r
\ No newline at end of file
+       public override void GenerateIV ()\r     {\r              IVValue = KeyBuilder.IV (BlockSizeValue >> 3);
+       }\r
+       public override void GenerateKey ()\r    {\r              KeyValue = KeyBuilder.Key (KeySizeValue >> 3);
+       }\r}\r
+internal class RC2Transform : SymmetricTransform\r{\r    public RC2Transform (RC2 rc2Algo, bool encryption) : base (rc2Algo, encryption, rc2Algo.IV)\r    {\r              R = new UInt32 [4];\r            KeySetup (rc2Algo.Key, rc2Algo.EffectiveKeySize);\r      }\r
+       private void KeySetup (byte[] key, int t1) \r    {               \r               // Expand key into a byte array, then convert to word\r          // array since we always access the key in 16bit chunks.\r               byte[] L = new byte [128];\r\r            int t = key.Length;\r            int t8 = ((t1 + 7) >> 3); // divide by 8\r               int tm = 255 % (2 << (8 + t1 - 8*t8 - 1));\r\r            Array.Copy (key, 0, L, 0, t);\r\r         for (int i=t; i < 128; i++) \r                   L [i] = (byte) (pitable [(L [i-1] + L [i-t]) & 0xff]);\r\r                L [128-t8] = pitable [L [128-t8] & tm];\r\r               for (int i=127-t8; i >= 0; i--) \r                       L [i] = pitable [L [i+1] ^ L [i+t8]];\r\r         K = new UInt32 [64];\r           int pos = 0;\r           for (int i=0; i < 64; i++) \r                    K [i] = (UInt32) (L [pos++] + L [pos++] * 256);\r        }\r
+       protected override void ECB (byte[] input, byte[] output) 
+       {
+               // unrolled loop, eliminated mul
+               R [0] = (UInt32) (input [0] + (input [1] << 8));\r               R [1] = (UInt32) (input [2] + (input [3] << 8));\r               R [2] = (UInt32) (input [4] + (input [5] << 8));\r               R [3] = (UInt32) (input [6] + (input [7] << 8));\r\r              if (encrypt) {\r                 j = 0;\r                 Mix(); Mix(); Mix(); Mix(); Mix();\r                     Mash();\r                        Mix(); Mix(); Mix(); Mix(); Mix(); Mix();\r                      Mash();\r                        Mix(); Mix(); Mix(); Mix(); Mix();\r             } \r             else {\r                 j = 63;\r                        RMix(); RMix(); RMix(); RMix(); RMix();\r                        RMash();\r                       RMix(); RMix(); RMix(); RMix(); RMix(); RMix();\r                        RMash();\r                       RMix(); RMix(); RMix(); RMix(); RMix();\r                }\r\r             // unrolled loop
+               output[0] = (byte) (R [0] & 0xff);\r             output[1] = (byte) ((R [0] >> 8) & 0xff);\r              output[2] = (byte) (R [1] & 0xff);\r             output[3] = (byte) ((R [1] >> 8) & 0xff);\r              output[4] = (byte) (R [2] & 0xff);\r             output[5] = (byte) ((R [2] >> 8) & 0xff);\r              output[6] = (byte) (R [3] & 0xff);\r             output[7] = (byte) ((R [3] >> 8) & 0xff);\r      }\r\r     static public byte[] pitable = {\r               0xd9, 0x78, 0xf9, 0xc4, 0x19, 0xdd, 0xb5, 0xed, \r               0x28, 0xe9, 0xfd, 0x79, 0x4a, 0xa0, 0xd8, 0x9d,\r                0xc6, 0x7e, 0x37, 0x83, 0x2b, 0x76, 0x53, 0x8e, \r               0x62, 0x4c, 0x64, 0x88, 0x44, 0x8b, 0xfb, 0xa2,\r                0x17, 0x9a, 0x59, 0xf5, 0x87, 0xb3, 0x4f, 0x13, \r               0x61, 0x45, 0x6d, 0x8d, 0x09, 0x81, 0x7d, 0x32,\r                0xbd, 0x8f, 0x40, 0xeb, 0x86, 0xb7, 0x7b, 0x0b, \r               0xf0, 0x95, 0x21, 0x22, 0x5c, 0x6b, 0x4e, 0x82,\r                0x54, 0xd6, 0x65, 0x93, 0xce, 0x60, 0xb2, 0x1c, \r               0x73, 0x56, 0xc0, 0x14, 0xa7, 0x8c, 0xf1, 0xdc,\r                0x12, 0x75, 0xca, 0x1f, 0x3b, 0xbe, 0xe4, 0xd1, \r               0x42, 0x3d, 0xd4, 0x30, 0xa3, 0x3c, 0xb6, 0x26,\r                0x6f, 0xbf, 0x0e, 0xda, 0x46, 0x69, 0x07, 0x57, \r               0x27, 0xf2, 0x1d, 0x9b, 0xbc, 0x94, 0x43, 0x03,\r                0xf8, 0x11, 0xc7, 0xf6, 0x90, 0xef, 0x3e, 0xe7, \r               0x06, 0xc3, 0xd5, 0x2f, 0xc8, 0x66, 0x1e, 0xd7,\r                0x08, 0xe8, 0xea, 0xde, 0x80, 0x52, 0xee, 0xf7, \r               0x84, 0xaa, 0x72, 0xac, 0x35, 0x4d, 0x6a, 0x2a,\r                0x96, 0x1a, 0xd2, 0x71, 0x5a, 0x15, 0x49, 0x74, \r               0x4b, 0x9f, 0xd0, 0x5e, 0x04, 0x18, 0xa4, 0xec,\r                0xc2, 0xe0, 0x41, 0x6e, 0x0f, 0x51, 0xcb, 0xcc, \r               0x24, 0x91, 0xaf, 0x50, 0xa1, 0xf4, 0x70, 0x39,\r                0x99, 0x7c, 0x3a, 0x85, 0x23, 0xb8, 0xb4, 0x7a, \r               0xfc, 0x02, 0x36, 0x5b, 0x25, 0x55, 0x97, 0x31,\r                0x2d, 0x5d, 0xfa, 0x98, 0xe3, 0x8a, 0x92, 0xae, \r               0x05, 0xdf, 0x29, 0x10, 0x67, 0x6c, 0xba, 0xc9,\r                0xd3, 0x00, 0xe6, 0xcf, 0xe1, 0x9e, 0xa8, 0x2c, \r               0x63, 0x16, 0x01, 0x3f, 0x58, 0xe2, 0x89, 0xa9,\r                0x0d, 0x38, 0x34, 0x1b, 0xab, 0x33, 0xff, 0xb0, \r               0xbb, 0x48, 0x0c, 0x5f, 0xb9, 0xb1, 0xcd, 0x2e,\r                0xc5, 0xf3, 0xdb, 0x47, 0xe5, 0xa5, 0x9c, 0x77, \r               0x0a, 0xa6, 0x20, 0x68, 0xfe, 0x7f, 0xc1, 0xad };\r\r     // The expanded key (in bottom 16 bits of each word)\r   public UInt32[] K;\r\r    // The state (again in bottom 16 bits, although we only\r        // clear the top 16 bits if needed)\r    private UInt32[] R;\r\r   // Key indexer\r private int j;\r\r        private void Mix() \r    {\r              R[0] += K[j]   + (R[3] & R[2]) + ((~R[3]) & R[1]);\r             R[0] = (R[0] << 1) | (R[0]>>15 & 0x1);\r\r                R[1] += K[j+1] + (R[0] & R[3]) + ((~R[0]) & R[2]);\r             R[1] = (R[1] << 2) | (R[1]>>14 & 0x3);\r\r                R[2] += K[j+2] + (R[1] & R[0]) + ((~R[1]) & R[3]);\r             R[2] = (R[2] << 3) | (R[2]>>13 & 0x7);\r\r                R[3] += K[j+3] + (R[2] & R[1]) + ((~R[2]) & R[0]);\r             R[3] = (R[3] << 5) | (R[3]>>11 & 0x1f);\r                j += 4;\r        }\r\r     private void RMix() \r   {\r              R[3] &= 0xffff;\r                R[3] = (R[3] >> 5) | ((R[3] & 0x1f) << 11);\r            R[3] -= K[j] + (R[2] & R[1]) + ((~R[2]) & R[0]);\r\r              R[2] &= 0xffff;\r                R[2] = (R[2] >> 3) | ((R[2] & 0x7) << 13);\r             R[2] -= K[j-1] + (R[1] & R[0]) + ((~R[1]) & R[3]);\r\r            R[1] &= 0xffff;\r                R[1] = (R[1] >> 2) | ((R[1] & 0x3) << 14);\r             R[1] -= K[j-2] + (R[0] & R[3]) + ((~R[0]) & R[2]);\r\r            R[0] &= 0xffff;\r                R[0] = (R[0] >> 1) | ((R[0] & 0x1) << 15);\r             R[0] -= K[j-3] + (R[3] & R[2]) + ((~R[3]) & R[1]);\r\r            j -= 4;\r        }\r
+       private void Mash ()\r   {\r              R [0] += K [R [3] & 63];\r               R [1] += K [R [0] & 63];\r               R [2] += K [R [1] & 63];\r               R [3] += K [R [2] & 63];\r       }\r
+       private void RMash ()\r  {\r              R [3] -= K [R [2] & 63];\r               R [2] -= K [R [1] & 63];\r               R [1] -= K [R [0] & 63];\r               R [0] -= K [R [3] & 63];\r       }\r}\r\r}\r
\ No newline at end of file
index 32222860658eb347e4a5323c3acb9a7849153810..d2b8391a43bb5c1b2800b27cf6755525e2afe919 100644 (file)
@@ -10,7 +10,6 @@
 //
 
 using System;
-using System.Security.Cryptography;
 
 /// <summary>
 /// Rijndael is a symmetric block cipher supporting block and key sizes
@@ -28,21 +27,17 @@ public sealed class RijndaelManaged : Rijndael {
        /// <summary>
        /// RijndaelManaged constructor.
        /// </summary>
-       public RijndaelManaged() 
-       {
-       }
+       public RijndaelManaged() {}
        
        /// <summary>
        /// Generates a random IV for block feedback modes
        /// </summary>
        /// <remarks>
        /// Method is inherited from SymmetricAlgorithm
-       ///
        /// </remarks>
-       [MonoTODO]
        public override void GenerateIV () 
        {
-               throw new System.NotImplementedException();
+               IVValue = KeyBuilder.IV (BlockSizeValue >> 3);
        }
        
        /// <summary>
@@ -50,12 +45,10 @@ public sealed class RijndaelManaged : Rijndael {
        /// </summary>
        /// <remarks>
        /// Inherited method from base class SymmetricAlgorithm
-       ///
        /// </remarks>
-       [MonoTODO]
        public override void GenerateKey () 
        {
-               KeyValue = new byte [KeySizeValue / 8];
+               KeyValue = KeyBuilder.Key (KeySizeValue >> 3);
        }
        
        /// <summary>
index 48657a9072a088b5e08eada1c38491c103fccd7e..e6255d598ee4bbd900c14ed08058668bb7ddd505 100644 (file)
@@ -129,14 +129,14 @@ public class SHA384Managed : SHA384 {
 
        private void processWord (byte[] input, int inOff)
        {
-               W [wOff++] = ( (ulong) (input [inOff] & 0xff) << 56)
-                       | ( (ulong) (input [inOff + 1] & 0xff) << 48)
-                       | ( (ulong) (input [inOff + 2] & 0xff) << 40)
-                       | ( (ulong) (input [inOff + 3] & 0xff) << 32)
-                       | ( (ulong) (input [inOff + 4] & 0xff) << 24)
-                       | ( (ulong) (input [inOff + 5] & 0xff) << 16)
-                       | ( (ulong) (input [inOff + 6] & 0xff) << 8)
-                       | ( (ulong) (input [inOff + 7] & 0xff)); 
+               W [wOff++] = ( (ulong) input [inOff] << 56)
+                       | ( (ulong) input [inOff + 1] << 48)
+                       | ( (ulong) input [inOff + 2] << 40)
+                       | ( (ulong) input [inOff + 3] << 32)
+                       | ( (ulong) input [inOff + 4] << 24)
+                       | ( (ulong) input [inOff + 5] << 16)
+                       | ( (ulong) input [inOff + 6] << 8)
+                       | ( (ulong) input [inOff + 7]); 
                if (wOff == 16)
                        processBlock ();
        }
index 960eac5ee413c20681bf454954fdd6d7a311445e..b3e193963d3fc65d79e7a8f40d195c212cf94b22 100644 (file)
@@ -128,14 +128,14 @@ public class SHA512Managed : SHA512 {
 
        private void processWord (byte[] input, int inOff) 
        {
-               W [wOff++] = ( (ulong) (input [inOff] & 0xff) << 56)
-                       | ( (ulong) (input [inOff + 1] & 0xff) << 48)
-                       | ( (ulong) (input [inOff + 2] & 0xff) << 40)
-                       | ( (ulong) (input [inOff + 3] & 0xff) << 32)
-                       | ( (ulong) (input [inOff + 4] & 0xff) << 24)
-                       | ( (ulong) (input [inOff + 5] & 0xff) << 16)
-                       | ( (ulong) (input [inOff + 6] & 0xff) << 8)
-                       | ( (ulong) (input [inOff + 7] & 0xff)); 
+               W [wOff++] = ( (ulong) input [inOff] << 56)
+                       | ( (ulong) input [inOff + 1] << 48)
+                       | ( (ulong) input [inOff + 2] << 40)
+                       | ( (ulong) input [inOff + 3] << 32)
+                       | ( (ulong) input [inOff + 4] << 24)
+                       | ( (ulong) input [inOff + 5] << 16)
+                       | ( (ulong) input [inOff + 6] << 8)
+                       | ( (ulong) input [inOff + 7]); 
                if (wOff == 16)
                        processBlock ();
        }
@@ -154,7 +154,7 @@ public class SHA512Managed : SHA512 {
 
        // adjust the byte counts so that byteCount2 represents the
        // upper long (less 3 bits) word of the byte count.
-       private void adjustByteCounts() 
+       private void adjustByteCounts () 
        {
                if (byteCount1 > 0x1fffffffffffffffL) {
                        byteCount2 += (byteCount1 >> 61);
index 2fcadb06f01546df515502700a8d06d645367e12..8908c81278a2022d7b37b6e147fa20f4d713c3d0 100755 (executable)
@@ -356,7 +356,6 @@ namespace System.Security.Cryptography {
                /// <summary>
                /// Gets or sets the actual Initial Vector
                /// </summary>
-               [MonoTODO]
                public virtual byte[] IV {
                        get {
                                if (this.IVValue == null)
@@ -372,7 +371,7 @@ namespace System.Security.Cryptography {
                                        throw new CryptographicException ("IV length must match block size");
                                
                                this.IVValue = new byte [value.Length];
-                               System.Array.Copy (value, 0, this.IVValue, 0, value.Length);
+                               Array.Copy (value, 0, this.IVValue, 0, value.Length);
                        }
                }
 
@@ -395,7 +394,7 @@ namespace System.Security.Cryptography {
 
                                this.KeySizeValue = value.Length * 8;
                                this.KeyValue = new byte [value.Length];
-                               System.Array.Copy (value, 0, this.KeyValue, 0, value.Length);
+                               Array.Copy (value, 0, this.KeyValue, 0, value.Length);
                        }
                }
                
index bbdc664610d4d51e4409341ddcabbaf771d00da4..69ee3f063a019654b741220218686c480c505f67 100644 (file)
@@ -8,7 +8,6 @@
 //
 
 using System;
-using System.Security.Cryptography;
 
 namespace System.Security.Cryptography {
 
@@ -21,20 +20,16 @@ namespace System.Security.Cryptography {
 
 public sealed class TripleDESCryptoServiceProvider : TripleDES {
 
-       public TripleDESCryptoServiceProvider () 
-       {
-       }
+       public TripleDESCryptoServiceProvider () {}
 
-       [MonoTODO]
        public override void GenerateIV () 
        {
-               throw new System.NotImplementedException ();
+               IVValue = KeyBuilder.IV (BlockSizeValue >> 3);
        }
        
-       [MonoTODO]
        public override void GenerateKey () 
        {
-               KeyValue = new byte [KeySizeValue / 8];
+               KeyValue = KeyBuilder.Key (KeySizeValue >> 3);
        }
        
        public override ICryptoTransform CreateDecryptor (byte[] rgbKey, byte[] rgbIV)