2005-01-10 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Tue, 11 Jan 2005 01:18:39 +0000 (01:18 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Tue, 11 Jan 2005 01:18:39 +0000 (01:18 -0000)
* CryptoConfig.cs: Change the OID for SHA-2 algorithms to match 2.0
and added new OID for asymmetric and symmetric algorithms.
* CspKeyContainerInfo.cs: Added CryptoKeySecurity property. This will
always return null until we support access control for key containers.
* CspParameters.cs: Added new constructors and propertys for access
control and password (2.0).
* DSASignatureDeformatter.cs: Throw ArgumentNullException in NET_2_0
if a null key is specified.
* DSASignatureFormatter.cs: Throw ArgumentNullException in NET_2_0 if
a null key is specified.
* HashAlgorithm.cs: Fix the reported exceptions for output buffers.
* HMAC.cs: Change the .Clear (which calls Dispose) to a .Initialize.
* MACTripleDES.cs: Removed unrequired private field _padding.
* PasswordDeriveBytes.cs: Added 4 new constructors where the password
is a byte[] (as it seems MS won't be using SecureString for this).
* RIPEMD160Managed.cs: Removed overriden Dispose method to match 2.0.
Clear buffers when initializing (e.g. re-using the hash instance).
* Rfc2898DeriveBytes.cs: Added a new constructor where the password
is a byte[] (as it seems MS won't be using SecureString for this).
* RSAPKCS1SignatureDeformatter.cs: Throw ArgumentNullException in
NET_2_0 if a null key is specified.
* RSAPKCS1SignatureFormatter.cs: Throw ArgumentNullException in
NET_2_0 if a null key is specified.
* ToBase64Transform.cs: Fix the reported exceptions for output buffers.

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

15 files changed:
mcs/class/corlib/System.Security.Cryptography/ChangeLog
mcs/class/corlib/System.Security.Cryptography/CryptoConfig.cs
mcs/class/corlib/System.Security.Cryptography/CspKeyContainerInfo.cs
mcs/class/corlib/System.Security.Cryptography/CspParameters.cs
mcs/class/corlib/System.Security.Cryptography/DSASignatureDeformatter.cs
mcs/class/corlib/System.Security.Cryptography/DSASignatureFormatter.cs
mcs/class/corlib/System.Security.Cryptography/HMAC.cs
mcs/class/corlib/System.Security.Cryptography/HashAlgorithm.cs
mcs/class/corlib/System.Security.Cryptography/MACTripleDES.cs
mcs/class/corlib/System.Security.Cryptography/PasswordDeriveBytes.cs
mcs/class/corlib/System.Security.Cryptography/RIPEMD160Managed.cs
mcs/class/corlib/System.Security.Cryptography/RSAPKCS1SignatureDeformatter.cs
mcs/class/corlib/System.Security.Cryptography/RSAPKCS1SignatureFormatter.cs
mcs/class/corlib/System.Security.Cryptography/Rfc2898DeriveBytes.cs
mcs/class/corlib/System.Security.Cryptography/ToBase64Transform.cs

index 84b38943992fe01f008a266e4619ced083c59fec..aff042967e46245767148081e0af60cfb3705cff 100644 (file)
@@ -1,3 +1,30 @@
+2005-01-10  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * CryptoConfig.cs: Change the OID for SHA-2 algorithms to match 2.0
+       and added new OID for asymmetric and symmetric algorithms.
+       * CspKeyContainerInfo.cs: Added CryptoKeySecurity property. This will
+       always return null until we support access control for key containers.
+       * CspParameters.cs: Added new constructors and propertys for access 
+       control and password (2.0).
+       * DSASignatureDeformatter.cs: Throw ArgumentNullException in NET_2_0 
+       if a null key is specified.
+       * DSASignatureFormatter.cs: Throw ArgumentNullException in NET_2_0 if
+       a null key is specified.
+       * HashAlgorithm.cs: Fix the reported exceptions for output buffers.
+       * HMAC.cs: Change the .Clear (which calls Dispose) to a .Initialize.
+       * MACTripleDES.cs: Removed unrequired private field _padding.
+       * PasswordDeriveBytes.cs: Added 4 new constructors where the password
+       is a byte[] (as it seems MS won't be using SecureString for this).
+       * RIPEMD160Managed.cs: Removed overriden Dispose method to match 2.0.
+       Clear buffers when initializing (e.g. re-using the hash instance).
+       * Rfc2898DeriveBytes.cs: Added a new constructor where the password
+       is a byte[] (as it seems MS won't be using SecureString for this).
+       * RSAPKCS1SignatureDeformatter.cs: Throw ArgumentNullException in
+       NET_2_0 if a null key is specified.
+       * RSAPKCS1SignatureFormatter.cs: Throw ArgumentNullException in
+       NET_2_0 if a null key is specified.
+       * ToBase64Transform.cs: Fix the reported exceptions for output buffers.
+
 2005-01-06  Sebastien Pouliot  <sebastien@ximian.com> 
 
        * DES.cs: Change wek and semi-weak key checking to avoid memory 
index b9291d8e95d2a7797fdec26a2d064d4f07d961e8..86997f52358f5d009256647e6050678624d887b1 100644 (file)
@@ -7,11 +7,7 @@
 //
 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
 // Copyright (C) Tim Coleman, 2004
-// (C) 2004 Novell (http://www.novell.com)
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2005 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
@@ -33,7 +29,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using System;
 using System.Collections;
 using System.Globalization;
 using System.IO;
@@ -108,9 +103,22 @@ public class CryptoConfig {
        // Oddly OID seems only available for hash algorithms
        private const string oidSHA1 = "1.3.14.3.2.26";
        private const string oidMD5 = "1.2.840.113549.2.5";
+#if NET_2_0
+       // changed in 2.0
+       private const string oidSHA256 = "2.16.840.1.101.3.4.2.1";
+       private const string oidSHA384 = "2.16.840.1.101.3.4.2.2";
+       private const string oidSHA512 = "2.16.840.1.101.3.4.2.3";
+       // new in 2.0
+       private const string oidRSA = "1.2.840.113549.1.1.1";
+       private const string oidDSA = "1.2.840.10040.4.1";
+       private const string oidDES = "1.3.14.3.2.7";
+       private const string oid3DES = "1.2.840.113549.3.7";
+       private const string oidRC2 = "1.2.840.113549.3.2";
+#else
        private const string oidSHA256 = "2.16.840.1.101.3.4.1";
        private const string oidSHA384 = "2.16.840.1.101.3.4.2";
        private const string oidSHA512 = "2.16.840.1.101.3.4.3";
+#endif
        // LAMESPEC: only documentated in ".NET Framework Security" book
        private const string oid3DESKeyWrap = "1.2.840.113549.1.9.16.3.6";
 
@@ -306,6 +314,15 @@ public class CryptoConfig {
                // surprise! documented in ".NET Framework Security" book
                oid.Add (name3DESKeyWrap, oid3DESKeyWrap);
 
+#if NET_2_0
+               oid.Add (nameRSAa, oidRSA);
+               oid.Add (nameDSAa, oidDSA);
+               oid.Add (nameDESa, oidDES);
+               oid.Add (name3DESa, oid3DES);
+               oid.Add (name3DESb, oid3DES);
+               oid.Add (nameRC2a, oidRC2);
+#endif
+
                // Add/modify the config as specified by machine.config
                string config = Environment.GetMachineConfigPath ();
                LoadConfig (config);
index ba0d544007513be549e8c5eccf3c0db6c750b36a..5b66db2a80d9d047b644f6e2b2a6857ba0b024cf 100755 (executable)
@@ -2,13 +2,10 @@
 // CspKeyContainerInfo.cs: Information about CSP based key containers
 //
 // Author:
-//     Sebastien Pouliot (spouliot@motus.com)
+//     Sebastien Pouliot  <sebastien@ximian.com>
 //
 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2005 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
@@ -32,7 +29,7 @@
 
 #if NET_2_0
 
-using System;
+using System.Security.AccessControl;
 
 namespace System.Security.Cryptography {
 
@@ -55,7 +52,12 @@ namespace System.Security.Cryptography {
                public bool Accessible {
                        get { return true; }
                }
-               
+
+               // always null for Mono
+               public CryptoKeySecurity CryptoKeySecurity {
+                       get { return null; }
+               }
+
                // always true for Mono
                public bool Exportable {
                        get { return true; }
@@ -108,4 +110,4 @@ namespace System.Security.Cryptography {
        }
 }
 
-#endif
\ No newline at end of file
+#endif
index db5a592c348b3ee9e6bb6a8a53022c0129798934..8cb3e1c519b15c039ed8f0150b69890a5503e486 100755 (executable)
@@ -1,14 +1,11 @@
 //\r
 // System.Security.Cryptography CspParameters.cs\r
 //\r
-// Author:\r
-//   Thomas Neidhart (tome@sbox.tugraz.at)\r
+// Authors:\r
+//     Thomas Neidhart (tome@sbox.tugraz.at)\r
+//     Sebastien Pouliot  <sebastien@ximian.com>
 //\r
-// (C) 2004 Novell (http://www.novell.com)
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2005 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
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-\r
-using System;\r
+
+#if NET_2_0
+using System.Security.AccessControl;
+#endif
 \r
 namespace System.Security.Cryptography {\r
 \r
@@ -74,6 +73,45 @@ namespace System.Security.Cryptography {
                public CspProviderFlags Flags {\r
                        get { return _Flags; }\r
                        set { _Flags = value; }\r
-               }\r
+               }
+
+#if NET_2_0
+               private SecureString _password;
+               private IntPtr _windowHandle;
+
+               public CspParameters (int dwTypeIn, string strProviderNameIn, string strContainerNameIn, 
+                       CryptoKeySecurity cryptoKeySecurity, IntPtr parentWindowHandle)
+                       : this (dwTypeIn, strProviderNameIn, strContainerNameIn)
+               {
+                       if (cryptoKeySecurity != null)
+                               CryptoKeySecurity = cryptoKeySecurity;
+                       _windowHandle = parentWindowHandle;
+               }
+
+               public CspParameters (int dwTypeIn, string strProviderNameIn, string strContainerNameIn, 
+                       CryptoKeySecurity cryptoKeySecurity, SecureString keyPassword)
+                       : this (dwTypeIn, strProviderNameIn, strContainerNameIn)
+               {
+                       if (cryptoKeySecurity != null)
+                               CryptoKeySecurity = cryptoKeySecurity;
+                       _password = keyPassword;
+               }
+
+               [MonoTODO ("access control isn't implemented")]
+               public CryptoKeySecurity CryptoKeySecurity {
+                       get { throw new NotImplementedException (); }
+                       set { throw new NotImplementedException (); }
+               }
+
+               public SecureString KeyPassword {
+                       get { return _password; }
+                       set { _password = value; }
+               }
+
+               public IntPtr ParentWindowHandle {
+                       get { return _windowHandle; }
+                       set { _windowHandle = value; }
+               }
+#endif\r
        }\r
 }\r
index b3138ae638480f70287b78bf06bd70b9d47432cd..bbc69b4b855b9f916b3c7945d90c55e64605e1b8 100755 (executable)
@@ -28,7 +28,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using System;
 using System.Globalization;
 
 namespace System.Security.Cryptography {
@@ -68,7 +67,12 @@ namespace System.Security.Cryptography {
                                // a DSA keypair
                                dsa = (DSA) key;
                        }
-                       // here null is accepted!
+#if NET_2_0
+                       else
+                               throw new ArgumentNullException ("key");
+#else
+                       // null is accepted in 1.0/1.1
+#endif
                }
 
                public override bool VerifySignature (byte[] rgbHash, byte[] rgbSignature)
index 660b068a8f1aecdb972b8291008beea79477a710..893d93c321d1b306c80ccc6df8f5c786699ec628 100755 (executable)
@@ -77,7 +77,12 @@ namespace System.Security.Cryptography {
                                // a DSA keypair
                                dsa = (DSA) key;
                        }
-                       // here null is accepted!
+#if NET_2_0
+                       else
+                               throw new ArgumentNullException ("key");
+#else
+                       // null is accepted in 1.0/1.1
+#endif
                }
        }
 }
index a72fb7b4ee36fdc097974a71d198b7c27accb134..a73e690ac51731564363e3295e0e25d2ba3fc98f 100755 (executable)
@@ -2,12 +2,9 @@
 // HMAC.cs: Generic HMAC inplementation
 //
 // Author:
-//     Sebastien Pouliot (spouliot@motus.com)
+//     Sebastien Pouliot  <sebastien@ximian.com>
 //
 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-//
-
-//
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
@@ -32,8 +29,6 @@
 
 #if NET_2_0
 
-using System;
-
 using Mono.Security.Cryptography;
 
 namespace System.Security.Cryptography {
@@ -137,7 +132,7 @@ namespace System.Security.Cryptography {
                        _algo.TransformBlock (buf, 0, buf.Length, buf, 0);
                        _algo.TransformFinalBlock (intermediate, 0, intermediate.Length);
                        byte[] hash = _algo.Hash;
-                       _algo.Clear ();
+                       _algo.Initialize ();
                        // zeroize sensitive data
                        Array.Clear (buf, 0, buf.Length);       
                        Array.Clear (intermediate, 0, intermediate.Length);
index a58905a9952f350d057fdfdd7f6013d63f6d2f82..2ab98e393ef2c198cea8b340a671d1a416c176f6 100644 (file)
@@ -7,11 +7,7 @@
 //
 // Copyright 2001 by Matthew S. Ford.
 // Portions (C) 2002 Motus Technologies Inc. (http://www.motus.com)
-// (C) 2004 Novell (http://www.novell.com)
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2005 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
@@ -176,9 +172,22 @@ namespace System.Security.Cryptography {
                        // ordered to avoid possible integer overflow
                        if ((inputOffset < 0) || (inputOffset > inputBuffer.Length - inputCount))
                                throw new ArgumentException ("inputBuffer");
-                       // ordered to avoid possible integer overflow
-                       if ((outputOffset < 0) || (outputOffset > outputBuffer.Length - inputCount))
+                       if (outputOffset < 0) {
+#if NET_2_0
+                               throw new ArgumentOutOfRangeException ("outputOffset", "< 0");
+#else
                                throw new IndexOutOfRangeException ("outputBuffer");
+#endif
+                       }
+                       if (outputOffset > outputBuffer.Length - inputCount) {
+#if NET_2_0
+                               throw new ArgumentException ("outputOffset + inputCount", 
+                                       Locale.GetText ("Overflow"));
+#else
+                               throw new IndexOutOfRangeException ("outputBuffer");
+#endif
+                       }
+                       // ordered to avoid possible integer overflow
 
                        // note: other exceptions are handled by Buffer.BlockCopy
                        Buffer.BlockCopy (inputBuffer, inputOffset, outputBuffer, outputOffset, inputCount);
index c33d914a66ffe1cf2117e4d2d7b3c981a8771528..f24dad755527248c83502492b1986a7da60d0d25 100644 (file)
@@ -44,7 +44,6 @@ namespace System.Security.Cryptography {
                private TripleDES tdes;
                private MACAlgorithm mac;
                private bool m_disposed;
-               private PaddingMode _padding;
        
                public MACTripleDES ()
                {
index ca4b001edf2560170fc483991807fd30221420db..0dd5e368808297d5535156d49bae085a7c0ce0c1 100644 (file)
@@ -5,7 +5,7 @@
 //     Sebastien Pouliot (sebastien@ximian.com)
 //
 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2005 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
@@ -27,7 +27,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using System;
 using System.Globalization;
 using System.Text;
 
@@ -81,6 +80,36 @@ public class PasswordDeriveBytes : DeriveBytes {
                }
        }
 
+#if NET_2_0
+       public PasswordDeriveBytes (byte[] password, byte[] salt) 
+       {
+               Prepare (password, salt, "SHA1", 100);
+       }
+
+       public PasswordDeriveBytes (byte[] password, byte[] salt, CspParameters cspParams) 
+       {
+               Prepare (password, salt, "SHA1", 100);
+               if (cspParams != null) {
+                       throw new NotSupportedException (
+                               Locale.GetText ("CspParameters not supported by Mono for PasswordDeriveBytes."));
+               }
+       }
+
+       public PasswordDeriveBytes (byte[] password, byte[] salt, string hashName, int iterations) 
+       {
+               Prepare (password, salt, hashName, iterations);
+       }
+
+       public PasswordDeriveBytes (byte[] password, byte[] salt, string hashName, int iterations, CspParameters cspParams) 
+       {
+               Prepare (password, salt, hashName, iterations);
+               if (cspParams != null) {
+                       throw new NotSupportedException (
+                               Locale.GetText ("CspParameters not supported by Mono for PasswordDeriveBytes."));
+               }
+       }
+#endif
+
        ~PasswordDeriveBytes () 
        {
                // zeroize buffer
@@ -92,15 +121,33 @@ public class PasswordDeriveBytes : DeriveBytes {
                Array.Clear (password, 0, password.Length);
        }
 
+#if NET_2_0
        private void Prepare (string strPassword, byte[] rgbSalt, string strHashName, int iterations) 
        {
-#if NET_2_0
                if (strPassword == null)
                        throw new ArgumentNullException ("strPassword");
-               password = Encoding.UTF8.GetBytes (strPassword);
+
+               byte[] pwd = Encoding.UTF8.GetBytes (strPassword);
+               Prepare (pwd, rgbSalt, strHashName, iterations);
+               Array.Clear (pwd, 0, pwd.Length);
+       }
+
+       private void Prepare (byte[] password, byte[] rgbSalt, string strHashName, int iterations)
+       {
+               if (password == null)
+                       throw new ArgumentNullException ("password");
+
+               this.password = (byte[]) password.Clone ();
 
                Salt = rgbSalt;
+
+               HashName = strHashName;
+               IterationCount = iterations;
+               state = 0;
+       }
 #else
+       private void Prepare (string strPassword, byte[] rgbSalt, string strHashName, int iterations)
+       {
                if (strPassword == null)
                        password = null;
                else
@@ -110,12 +157,12 @@ public class PasswordDeriveBytes : DeriveBytes {
                        SaltValue = null;
                else
                        SaltValue = (byte[]) rgbSalt.Clone ();
-#endif
 
                HashName = strHashName;
                IterationCount = iterations;
                state = 0;
        }
+#endif
 
        public string HashName {
                get { return HashNameValue; } 
index cc017f56c6fcdc055d626e8b6e783143d72058b1..bdb22deb34edd571b7476663b6f33cd17c2f3c12 100755 (executable)
@@ -4,13 +4,10 @@
 // Author:
 //     Pieter Philippaerts (Pieter@mentalis.org)
 //
-// (C) 2003 The Mentalis.org Team (http://www.mentalis.org/)
-//
 //   References:
 //     - http://www.esat.kuleuven.ac.be/~cosicart/ps/AB-9601/
 //
-
-//
+// (C) 2003 The Mentalis.org Team (http://www.mentalis.org/)
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
@@ -35,7 +32,6 @@
 
 #if NET_2_0
 
-using System;
 using System.Runtime.InteropServices;
 
 namespace System.Security.Cryptography {
@@ -64,6 +60,8 @@ namespace System.Security.Cryptography {
                        _HashValue[4] = 0xc3d2e1f0;
                        _Length = 0;
                        _ProcessingBufferCount = 0;
+                       Array.Clear (_X, 0, _X.Length);
+                       Array.Clear (_ProcessingBuffer, 0, _ProcessingBuffer.Length);
                }
                /// <summary>
                /// Routes data written to the object into the <see cref="RIPEMD160"/> hash algorithm for computing the hash.
@@ -114,13 +112,6 @@ namespace System.Security.Cryptography {
                        return hash;
                }
                /// <summary>
-               /// Releases the resources used by the <see cref="RIPEMD160Managed"/>.
-               /// </summary>
-               /// <param name="disposing"><b>true</b> to release both managed and unmanaged resources; <b>false</b> to release only unmanaged resources.</param>
-               protected override void Dispose(bool disposing) {
-                       // nothing todo
-               }
-               /// <summary>
                /// Finalizes the RIPEMD160Managed.
                /// </summary>
                ~RIPEMD160Managed() {
index f608fcbf37d7c5ce41f8c4ab35324f307cd0e69e..3da5da568f862b152766bf1e9a0a215b2d75aec5 100644 (file)
@@ -5,11 +5,7 @@
 //     Sebastien Pouliot <sebastien@ximian.com>
 //
 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
-// (C) 2004 Novell (http://www.novell.com)
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2005 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
@@ -31,7 +27,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using System;
 using System.Globalization;
 using Mono.Security.Cryptography;
 
@@ -60,8 +55,13 @@ namespace System.Security.Cryptography {
        
                public override void SetKey (AsymmetricAlgorithm key) 
                {
+#if NET_2_0
+                       if (key == null)
+                               throw new ArgumentNullException ("key");
+#else
+                       // 1.0/1.1 accepted null without an ArgumentNullException!
+#endif
                        rsa = (RSA) key;
-                       // here null is accepted without an ArgumentNullException!
                }
        
                public override bool VerifySignature (byte[] rgbHash, byte[] rgbSignature) 
index 20695fe9794ec12e342934b6011c06fd9e868470..3ae6ac5ae330c831379ce5864f6b8608184a57fc 100644 (file)
@@ -5,11 +5,7 @@
 //     Sebastien Pouliot <sebastien@ximian.com>
 //
 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
-// (C) 2004 Novell (http://www.novell.com)
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2005 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
@@ -31,7 +27,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using System;
 using Mono.Security.Cryptography;
 
 namespace System.Security.Cryptography { 
@@ -73,6 +68,12 @@ namespace System.Security.Cryptography {
        
                public override void SetKey (AsymmetricAlgorithm key) 
                {
+#if NET_2_0
+                       if (key == null)
+                               throw new ArgumentNullException ("key");
+#else
+                       // 1.0/1.1 accepted null without an ArgumentNullException!
+#endif
                        rsa = (RSA) key;
                }
        }
index 91da95c247eaed3ee7f2838cf204a924e321d450..65232d808744e31fe4f44a57ff0982020b4168f1 100755 (executable)
@@ -2,13 +2,10 @@
 // Rfc2898DeriveBytes.cs: RFC2898 (PKCS#5 v2) Key derivation for Password Based Encryption 
 //
 // Author:
-//     Sebastien Pouliot (spouliot@motus.com)
+//     Sebastien Pouliot (sebastien@ximian.com)
 //
 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2005 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
@@ -32,7 +29,6 @@
 
 #if NET_2_0
 
-using System;
 using System.Text;
 
 using Mono.Security.Cryptography;
@@ -53,7 +49,9 @@ namespace System.Security.Cryptography {
                // constructors
 
                public Rfc2898DeriveBytes (string password, byte[] salt) 
-                       : this (password, salt, defaultIterations) {}
+                       : this (password, salt, defaultIterations)
+               {
+               }
                
                public Rfc2898DeriveBytes (string password, byte[] salt, int iterations) 
                {
@@ -64,9 +62,21 @@ namespace System.Security.Cryptography {
                        IterationCount = iterations;
                        _hmac = new HMACSHA1 (Encoding.UTF8.GetBytes (password));
                }
+
+               public Rfc2898DeriveBytes (byte[] password, byte[] salt, int iterations) 
+               {
+                       if (password == null)
+                               throw new ArgumentNullException ("password");
+
+                       Salt = salt;
+                       IterationCount = iterations;
+                       _hmac = new HMACSHA1 (password);
+               }
                
                public Rfc2898DeriveBytes (string password, int saltSize)
-                       : this (password, saltSize, defaultIterations) {}
+                       : this (password, saltSize, defaultIterations)
+               {
+               }
                
                public Rfc2898DeriveBytes (string password, int saltSize, int iterations)
                {
@@ -170,4 +180,4 @@ namespace System.Security.Cryptography {
        } 
 }
 
-#endif
\ No newline at end of file
+#endif
index 4a8f992574507f70c1151ed5abcad3b283072afd..0d6a8c4b4c050649b31a3e09f4b9a39430b0686a 100644 (file)
@@ -5,9 +5,6 @@
 //   Sergey Chaban (serge@wildwestsoftware.com)
 //
 // (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
@@ -30,7 +27,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using System;
 using System.Globalization;
 
 namespace System.Security.Cryptography {
@@ -107,8 +103,15 @@ namespace System.Security.Cryptography {
                        if (inputOffset > inputBuffer.Length - inputCount)
                                throw new ArgumentException ("inputOffset", Locale.GetText ("Overflow"));
                        // ordered to avoid possible integer overflow
+#if NET_2_0
+                       if (outputOffset < 0)
+                               throw new ArgumentOutOfRangeException ("outputOffset", "< 0");
+                       if (outputOffset > outputBuffer.Length - inputCount)
+                               throw new ArgumentException ("outputOffset", Locale.GetText ("Overflow"));
+#else
                        if ((outputOffset < 0) || (outputOffset > outputBuffer.Length - inputCount))
                                throw new IndexOutOfRangeException ("outputOffset");
+#endif
 /// To match MS implementation
 //                     if (inputCount != this.InputBlockSize)
 //                             throw new CryptographicException (Locale.GetText ("Invalid input length"));