+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
//
// (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
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-using System;
using System.Collections;
using System.Globalization;
using System.IO;
// 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";
// 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);
// 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
#if NET_2_0
-using System;
+using System.Security.AccessControl;
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; }
}
}
-#endif
\ No newline at end of file
+#endif
//\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
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
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-using System;
using System.Globalization;
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)
// 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
}
}
}
// 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
#if NET_2_0
-using System;
-
using Mono.Security.Cryptography;
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);
//
// 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
// 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);
private TripleDES tdes;
private MACAlgorithm mac;
private bool m_disposed;
- private PaddingMode _padding;
public MACTripleDES ()
{
// 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
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-using System;
using System.Globalization;
using System.Text;
}
}
+#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
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
SaltValue = null;
else
SaltValue = (byte[]) rgbSalt.Clone ();
-#endif
HashName = strHashName;
IterationCount = iterations;
state = 0;
}
+#endif
public string HashName {
get { return HashNameValue; }
// 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
#if NET_2_0
-using System;
using System.Runtime.InteropServices;
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.
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() {
// 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
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-using System;
using System.Globalization;
using Mono.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)
// 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
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-using System;
using Mono.Security.Cryptography;
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;
}
}
// 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
#if NET_2_0
-using System;
using System.Text;
using Mono.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)
{
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)
{
}
}
-#endif
\ No newline at end of file
+#endif
// 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
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-using System;
using System.Globalization;
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"));