Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@@ -0,0 +1,82 @@
//
// System.Security.Cryptography.Aes.cs
// based on mcs/class/corlib/System.Security.Cryptography/Rijndael.cs
//
// Authors:
// Dan Lewis (dihlewis@yahoo.co.uk)
// Andrew Birkett (andy@nobugs.org)
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2002
// Copyright (C) 2004-2006,2008 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
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace System.Security.Cryptography {
// References:
// a. FIPS PUB 197: Advanced Encryption Standard
// http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf
// since 4.0 (both FX and SL) this type now resides inside mscorlib.dll and link back to System.Core.dll
#if MOBILE
// version has not changed between SL3 (System.Core) and SL4
[TypeForwardedFrom (Consts.AssemblySystem_Core)]
#else
// use 3.5 version
[TypeForwardedFrom ("System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
#endif
public abstract class Aes : SymmetricAlgorithm {
public static new Aes Create ()
{
#if FULL_AOT_RUNTIME
// The Aes base class was moved from System.Core to mscorlib - so we can't just return a new AesCryptoServiceProvider instance
// note: the linker is aware of this condition
return (Aes) Activator.CreateInstance (Type.GetType ("System.Security.Cryptography.AesManaged, " + Consts.AssemblySystem_Core));
#else
return Create ("System.Security.Cryptography.AesCryptoServiceProvider, " + Consts.AssemblySystem_Core);
#endif
}
public static new Aes Create (string algorithmName)
{
return (Aes) CryptoConfig.CreateFromName (algorithmName);
}
protected Aes ()
{
KeySizeValue = 256;
BlockSizeValue = 128;
FeedbackSizeValue = 128;
LegalKeySizesValue = new KeySizes [1];
LegalKeySizesValue [0] = new KeySizes (128, 256, 64);
LegalBlockSizesValue = new KeySizes [1];
LegalBlockSizesValue [0] = new KeySizes (128, 128, 0);
}
}
}

View File

@@ -65,11 +65,7 @@ namespace System.Security.Cryptography {
get;
}
#if NET_4_0
public void Dispose ()
#else
void IDisposable.Dispose ()
#endif
{
Dispose (true);
GC.SuppressFinalize (this); // Finalization is now unnecessary
@@ -80,13 +76,9 @@ namespace System.Security.Cryptography {
Dispose (false);
}
#if NET_4_0
protected virtual void Dispose (bool disposing)
{
}
#else
protected abstract void Dispose (bool disposing);
#endif
public abstract void FromXmlString (string xmlString);
public abstract string ToXmlString (bool includePrivateParameters);

View File

@@ -67,11 +67,7 @@ namespace System.Security.Cryptography {
get { return 0; }
}
#if NET_4_0
public void Dispose ()
#else
void IDisposable.Dispose ()
#endif
{
Dispose (true);
GC.SuppressFinalize (this); // Finalization is now unnecessary

View File

@@ -222,7 +222,6 @@ public partial class CryptoConfig {
// new (2.0) X509 Chain
private const string nameX509Chain = "X509Chain";
private const string defaultX509Chain = defaultNamespace + "X509Certificates.X509Chain, " + Consts.AssemblySystem;
#if NET_4_0
// AES
const string system_core_assembly = ", System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
const string nameAES_1 = "AES";
@@ -273,7 +272,6 @@ public partial class CryptoConfig {
// SHA512 provider
const string nameSHA512Provider = "System.Security.Cryptography.SHA512CryptoServiceProvider";
const string defaultSHA512Provider = "System.Security.Cryptography.SHA512CryptoServiceProvider" + system_core_assembly;
#endif
static CryptoConfig ()
{
// lock(this) is bad
@@ -393,7 +391,6 @@ public partial class CryptoConfig {
unresolved_algorithms.Add (oidX509EnhancedKeyUsage, nameX509EnhancedKeyUsage);
// note: the default X.509Chain can also be created this way
unresolved_algorithms.Add (nameX509Chain, defaultX509Chain);
#if NET_4_0
unresolved_algorithms.Add (nameAES_1, defaultAES_1);
unresolved_algorithms.Add (nameAES_2, defaultAES_1);
unresolved_algorithms.Add (nameAESManaged_1, defaultAESManaged);
@@ -415,7 +412,6 @@ public partial class CryptoConfig {
unresolved_algorithms.Add (nameSHA384Provider, defaultSHA384Provider);
unresolved_algorithms.Add (nameSHA512Cng, defaultSHA512Cng);
unresolved_algorithms.Add (nameSHA512Provider, defaultSHA512Provider);
#endif
Dictionary<string,string> oid = new Dictionary<string, string> (StringComparer.OrdinalIgnoreCase);
// comments here are to match with MS implementation (but not with doc)
@@ -531,7 +527,6 @@ public partial class CryptoConfig {
return result;
}
#if NET_4_0
[MonoLimitation ("nothing is FIPS certified so it never make sense to restrict to this (empty) subset")]
public static bool AllowOnlyFipsAlgorithms {
get { return false; }
@@ -564,7 +559,6 @@ public partial class CryptoConfig {
oids [oid] = name;
}
}
#endif
class CryptoHandler: SmallXmlParser.IContentHandler {

View File

@@ -31,10 +31,8 @@
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
#if NET_4_5
using System.Threading;
using System.Threading.Tasks;
#endif
namespace System.Security.Cryptography {
@@ -357,13 +355,10 @@ namespace System.Security.Cryptography {
}
}
#if NET_4_0
public bool HasFlushedFinalBlock {
get { return _flushedFinalBlock; }
}
#endif
#if NET_4_5
public override Task FlushAsync (CancellationToken cancellationToken)
{
return base.FlushAsync (cancellationToken);
@@ -378,6 +373,5 @@ namespace System.Security.Cryptography {
{
return base.WriteAsync (buffer, offset, count, cancellationToken);
}
#endif
}
}

View File

@@ -43,9 +43,7 @@ namespace System.Security.Cryptography {
UseArchivableKey = 16,
UseNonExportableKey = 4,
UseUserProtectedKey = 32,
#if NET_4_0
CreateEphemeralKey = 128
#endif
}
}

View File

@@ -31,11 +31,7 @@ using System.Runtime.InteropServices;
namespace System.Security.Cryptography {
[ComVisible (true)]
#if NET_4_0
public abstract class DeriveBytes : IDisposable {
#else
public abstract class DeriveBytes {
#endif
protected DeriveBytes ()
{
}
@@ -44,7 +40,6 @@ namespace System.Security.Cryptography {
public abstract void Reset ();
#if NET_4_0
private bool m_disposed;
public void Dispose ()
@@ -61,6 +56,5 @@ namespace System.Security.Cryptography {
m_disposed = true;
}
}
#endif
}
}

View File

@@ -88,11 +88,7 @@ namespace System.Security.Cryptography {
Dispose (true);
}
#if NET_4_0
public void Dispose ()
#else
void IDisposable.Dispose ()
#endif
{
Dispose (true);
GC.SuppressFinalize (this); // Finalization is now unnecessary

View File

@@ -38,7 +38,7 @@ namespace System.Security.Cryptography {
public class HMACRIPEMD160 : HMAC {
public HMACRIPEMD160 ()
: this (KeyBuilder.Key (8))
: this (KeyBuilder.Key (64))
{
}

View File

@@ -52,7 +52,7 @@ namespace System.Security.Cryptography {
public class HMACSHA1 : HMAC {
public HMACSHA1 ()
: this (KeyBuilder.Key (8))
: this (KeyBuilder.Key (64))
{
}

View File

@@ -38,7 +38,7 @@ namespace System.Security.Cryptography {
public class HMACSHA256 : HMAC {
public HMACSHA256 ()
: this (KeyBuilder.Key (8))
: this (KeyBuilder.Key (64))
{
}

View File

@@ -49,7 +49,7 @@ namespace System.Security.Cryptography {
#endif
public HMACSHA384 ()
: this (KeyBuilder.Key (8))
: this (KeyBuilder.Key (128))
{
}

View File

@@ -49,7 +49,7 @@ namespace System.Security.Cryptography {
#endif
public HMACSHA512 ()
: this (KeyBuilder.Key (8))
: this (KeyBuilder.Key (128))
{
}

View File

@@ -157,11 +157,7 @@ namespace System.Security.Cryptography {
get { return 1; }
}
#if NET_4_0
public void Dispose ()
#else
void IDisposable.Dispose ()
#endif
{
Dispose (true);
GC.SuppressFinalize (this); // Finalization is now unnecessary

View File

@@ -110,7 +110,6 @@ public class PasswordDeriveBytes : DeriveBytes {
}
}
#if NET_4_0
protected override void Dispose (bool disposing)
{
// zeroize buffer
@@ -125,7 +124,6 @@ public class PasswordDeriveBytes : DeriveBytes {
}
base.Dispose (disposing);
}
#endif
private void Prepare (string strPassword, byte[] rgbSalt, string strHashName, int iterations)
{

View File

@@ -146,11 +146,9 @@ namespace System.Security.Cryptography {
}
}
#if NET_4_0
protected override void Dispose (bool disposing)
{
base.Dispose (disposing);
}
#endif
}
}

View File

@@ -35,9 +35,7 @@ namespace System.Security.Cryptography {
[ComVisible (true)]
#endif
public abstract class RandomNumberGenerator
#if NET_4_0
: IDisposable
#endif
{
protected RandomNumberGenerator ()
@@ -61,17 +59,12 @@ namespace System.Security.Cryptography {
public abstract void GetBytes (byte[] data);
#if NET_4_5
public virtual void GetNonZeroBytes (byte[] data)
{
throw new NotImplementedException ();
}
#else
public abstract void GetNonZeroBytes (byte[] data);
#endif
#if NET_4_0
public void Dispose ()
{
Dispose (true);
@@ -79,6 +72,5 @@ namespace System.Security.Cryptography {
protected virtual void Dispose (bool disposing)
{}
#endif
}
}

View File

@@ -187,7 +187,6 @@ namespace System.Security.Cryptography {
_pos = 0;
_f = 0;
}
#if NET_4_0
protected override void Dispose (bool disposing)
{
Array.Clear (_buffer, 0, _buffer.Length);
@@ -195,7 +194,6 @@ namespace System.Security.Cryptography {
_hmac.Clear ();
base.Dispose (disposing);
}
#endif
}
}

View File

@@ -77,11 +77,7 @@ namespace System.Security.Cryptography {
{
}
#if NET_4_0
public void Dispose ()
#else
void IDisposable.Dispose ()
#endif
{
_st.Clear ();
}

View File

@@ -53,11 +53,7 @@ namespace System.Security.Cryptography {
PaddingValue = PaddingMode.PKCS7;
}
#if NET_4_0
public void Dispose ()
#else
void IDisposable.Dispose ()
#endif
{
Dispose (true);
GC.SuppressFinalize (this); // Finalization is now unnecessary
@@ -179,7 +175,7 @@ namespace System.Security.Cryptography {
public virtual CipherMode Mode {
get { return this.ModeValue; }
set {
if (!Enum.IsDefined (ModeValue.GetType (), value)) {
if ((value < CipherMode.CBC) || (CipherMode.CFB < value)) {
throw new CryptographicException (
Locale.GetText ("Cipher mode not available"));
}

Some files were not shown because too many files have changed in this diff Show More