You've already forked linux-packaging-mono
Imported Upstream version 4.2.0.179
Former-commit-id: 0a113cb3a6feb7873f632839b1307cc6033cd595
This commit is contained in:
committed by
Jo Shields
parent
183bba2c9a
commit
6992685b86
@@ -11,7 +11,7 @@ namespace System.Security.Cryptography {
|
||||
/// <summary>
|
||||
/// Abstract base class for implementations of the AES algorithm
|
||||
/// </summary>
|
||||
#if !FEATURE_CORECLR
|
||||
#if !FEATURE_CORECLR && !MOBILE
|
||||
[TypeForwardedFrom("System.Core, Version=3.5.0.0, Culture=Neutral, PublicKeyToken=b77a5c561934e089")]
|
||||
#else // FEATURE_CORECLR
|
||||
[TypeForwardedFrom("System.Core, Version=2.0.5.0, Culture=Neutral, PublicKeyToken=7cec85d7bea7798e")]
|
||||
@@ -34,7 +34,13 @@ namespace System.Security.Cryptography {
|
||||
}
|
||||
|
||||
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("AES");
|
||||
#endif
|
||||
}
|
||||
|
||||
public static new Aes Create(string algorithmName) {
|
||||
|
@@ -85,9 +85,13 @@ namespace System.Security.Cryptography {
|
||||
//
|
||||
|
||||
static public AsymmetricAlgorithm Create() {
|
||||
#if FULL_AOT_RUNTIME
|
||||
return new RSACryptoServiceProvider ();
|
||||
#else
|
||||
// Use the crypto config system to return an instance of
|
||||
// the default AsymmetricAlgorithm on this machine
|
||||
return Create("System.Security.Cryptography.AsymmetricAlgorithm");
|
||||
#endif
|
||||
}
|
||||
|
||||
static public AsymmetricAlgorithm Create(String algName) {
|
||||
|
@@ -75,6 +75,25 @@ namespace System.Security.Cryptography {
|
||||
public KeySizes(int minSize, int maxSize, int skipSize) {
|
||||
m_minSize = minSize; m_maxSize = maxSize; m_skipSize = skipSize;
|
||||
}
|
||||
|
||||
|
||||
#if MONO
|
||||
internal bool IsLegal (int keySize)
|
||||
{
|
||||
int ks = keySize - MinSize;
|
||||
bool result = ((ks >= 0) && (keySize <= MaxSize));
|
||||
return ((SkipSize == 0) ? result : (result && (ks % SkipSize == 0)));
|
||||
}
|
||||
|
||||
internal static bool IsLegalKeySize (KeySizes[] legalKeys, int size)
|
||||
{
|
||||
foreach (KeySizes legalKeySize in legalKeys) {
|
||||
if (legalKeySize.IsLegal (size))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
|
@@ -320,7 +320,7 @@ namespace System.Security.Cryptography {
|
||||
}
|
||||
}
|
||||
|
||||
#if FEATURE_MACL
|
||||
#if FEATURE_MACL || MONO
|
||||
private CryptoKeySecurity m_cryptoKeySecurity;
|
||||
public CryptoKeySecurity CryptoKeySecurity {
|
||||
get {
|
||||
@@ -377,7 +377,7 @@ namespace System.Security.Cryptography {
|
||||
public CspParameters (int dwTypeIn, string strProviderNameIn, string strContainerNameIn) :
|
||||
this (dwTypeIn, strProviderNameIn, strContainerNameIn, CspProviderFlags.NoFlags) {}
|
||||
|
||||
#if FEATURE_MACL && FEATURE_CRYPTO && FEATURE_X509_SECURESTRINGS
|
||||
#if MONO || (FEATURE_MACL && FEATURE_CRYPTO && FEATURE_X509_SECURESTRINGS)
|
||||
[ResourceExposure(ResourceScope.Machine)]
|
||||
[ResourceConsumption(ResourceScope.Machine)]
|
||||
public CspParameters (int providerType, string providerName, string keyContainerName,
|
||||
@@ -413,7 +413,7 @@ namespace System.Security.Cryptography {
|
||||
KeyContainerName = parameters.KeyContainerName;
|
||||
KeyNumber = parameters.KeyNumber;
|
||||
Flags = parameters.Flags;
|
||||
#if FEATURE_MACL
|
||||
#if FEATURE_MACL || MONO
|
||||
m_cryptoKeySecurity = parameters.m_cryptoKeySecurity;
|
||||
#endif // FEATURE_MACL
|
||||
#if FEATURE_CRYPTO && FEATURE_X509_SECURESTRINGS
|
||||
|
@@ -72,7 +72,11 @@ namespace System.Security.Cryptography {
|
||||
//
|
||||
|
||||
new static public DES Create() {
|
||||
#if FULL_AOT_RUNTIME
|
||||
return new System.Security.Cryptography.DESCryptoServiceProvider ();
|
||||
#else
|
||||
return Create("System.Security.Cryptography.DES");
|
||||
#endif
|
||||
}
|
||||
|
||||
new static public DES Create(String algName) {
|
||||
|
@@ -35,8 +35,11 @@ namespace System.Security.Cryptography {
|
||||
throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidKey_Weak"),"DES");
|
||||
if (IsSemiWeakKey(rgbKey))
|
||||
throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidKey_SemiWeak"),"DES");
|
||||
|
||||
#if MONO
|
||||
return new DESTransform (this, true, rgbKey, rgbIV);
|
||||
#else
|
||||
return _NewEncryptor(rgbKey, ModeValue, rgbIV, FeedbackSizeValue, CryptoAPITransformMode.Encrypt);
|
||||
#endif
|
||||
}
|
||||
|
||||
[System.Security.SecuritySafeCritical] // auto-generated
|
||||
@@ -46,7 +49,11 @@ namespace System.Security.Cryptography {
|
||||
if (IsSemiWeakKey(rgbKey))
|
||||
throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidKey_SemiWeak"),"DES");
|
||||
|
||||
#if MONO
|
||||
return new DESTransform (this, false, rgbKey, rgbIV);
|
||||
#else
|
||||
return _NewEncryptor(rgbKey, ModeValue, rgbIV, FeedbackSizeValue, CryptoAPITransformMode.Decrypt);
|
||||
#endif
|
||||
}
|
||||
|
||||
public override void GenerateKey () {
|
||||
@@ -66,7 +73,7 @@ namespace System.Security.Cryptography {
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
#if !MONO
|
||||
[System.Security.SecurityCritical] // auto-generated
|
||||
private ICryptoTransform _NewEncryptor (byte[] rgbKey, CipherMode mode, byte[] rgbIV, int feedbackSize, CryptoAPITransformMode encryptMode) {
|
||||
int cArgs = 0;
|
||||
@@ -128,5 +135,6 @@ namespace System.Security.Cryptography {
|
||||
mode, BlockSizeValue, feedbackSize, false,
|
||||
encryptMode);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@@ -52,7 +52,11 @@ namespace System.Security.Cryptography {
|
||||
//
|
||||
|
||||
new static public DSA Create() {
|
||||
#if FULL_AOT_RUNTIME
|
||||
return new System.Security.Cryptography.DSACryptoServiceProvider ();
|
||||
#else
|
||||
return Create("System.Security.Cryptography.DSA");
|
||||
#endif
|
||||
}
|
||||
|
||||
new static public DSA Create(String algName) {
|
||||
|
@@ -47,7 +47,11 @@ namespace System.Security.Cryptography {
|
||||
//
|
||||
|
||||
static public HashAlgorithm Create() {
|
||||
#if FULL_AOT_RUNTIME
|
||||
return new System.Security.Cryptography.SHA1CryptoServiceProvider ();
|
||||
#else
|
||||
return Create("System.Security.Cryptography.HashAlgorithm");
|
||||
#endif
|
||||
}
|
||||
|
||||
static public HashAlgorithm Create(String hashName) {
|
||||
|
@@ -118,7 +118,11 @@ namespace System.Security.Cryptography {
|
||||
//
|
||||
|
||||
new static public HMAC Create () {
|
||||
#if FULL_AOT_RUNTIME
|
||||
return new System.Security.Cryptography.HMACSHA1 ();
|
||||
#else
|
||||
return Create("System.Security.Cryptography.HMAC");
|
||||
#endif
|
||||
}
|
||||
|
||||
new static public HMAC Create (string algorithmName) {
|
||||
|
@@ -23,12 +23,12 @@ namespace System.Security.Cryptography {
|
||||
|
||||
public HMACSHA1 (byte[] key, bool useManagedSha1) {
|
||||
m_hashName = "SHA1";
|
||||
#if FEATURE_CRYPTO
|
||||
#if FEATURE_CRYPTO && !FULL_AOT_RUNTIME
|
||||
if (useManagedSha1) {
|
||||
#endif // FEATURE_CRYPTO
|
||||
m_hash1 = new SHA1Managed();
|
||||
m_hash2 = new SHA1Managed();
|
||||
#if FEATURE_CRYPTO
|
||||
#if FEATURE_CRYPTO && !FULL_AOT_RUNTIME
|
||||
} else {
|
||||
m_hash1 = new SHA1CryptoServiceProvider();
|
||||
m_hash2 = new SHA1CryptoServiceProvider();
|
||||
|
@@ -22,7 +22,7 @@ namespace System.Security.Cryptography {
|
||||
public HMACSHA256 (byte[] key) {
|
||||
m_hashName = "SHA256";
|
||||
|
||||
#if FEATURE_CRYPTO
|
||||
#if FEATURE_CRYPTO && !FULL_AOT_RUNTIME
|
||||
m_hash1 = GetHashAlgorithmWithFipsFallback(() => new SHA256Managed(), () => HashAlgorithm.Create("System.Security.Cryptography.SHA256CryptoServiceProvider"));
|
||||
m_hash2 = GetHashAlgorithmWithFipsFallback(() => new SHA256Managed(), () => HashAlgorithm.Create("System.Security.Cryptography.SHA256CryptoServiceProvider"));
|
||||
#else
|
||||
|
@@ -25,8 +25,13 @@ namespace System.Security.Cryptography {
|
||||
[System.Security.SecuritySafeCritical] // auto-generated
|
||||
public HMACSHA384 (byte[] key) {
|
||||
m_hashName = "SHA384";
|
||||
#if FULL_AOT_RUNTIME
|
||||
m_hash1 = new SHA384Managed();
|
||||
m_hash2 = new SHA384Managed();
|
||||
#else
|
||||
m_hash1 = GetHashAlgorithmWithFipsFallback(() => new SHA384Managed(), () => HashAlgorithm.Create("System.Security.Cryptography.SHA384CryptoServiceProvider"));
|
||||
m_hash2 = GetHashAlgorithmWithFipsFallback(() => new SHA384Managed(), () => HashAlgorithm.Create("System.Security.Cryptography.SHA384CryptoServiceProvider"));
|
||||
#endif
|
||||
HashSizeValue = 384;
|
||||
BlockSizeValue = BlockSize;
|
||||
base.InitializeKey(key);
|
||||
|
@@ -25,8 +25,13 @@ namespace System.Security.Cryptography {
|
||||
[System.Security.SecuritySafeCritical] // auto-generated
|
||||
public HMACSHA512 (byte[] key) {
|
||||
m_hashName = "SHA512";
|
||||
#if FULL_AOT_RUNTIME
|
||||
m_hash1 = new SHA512Managed();
|
||||
m_hash2 = new SHA512Managed();
|
||||
#else
|
||||
m_hash1 = GetHashAlgorithmWithFipsFallback(() => new SHA512Managed(), () => HashAlgorithm.Create("System.Security.Cryptography.SHA512CryptoServiceProvider"));
|
||||
m_hash2 = GetHashAlgorithmWithFipsFallback(() => new SHA512Managed(), () => HashAlgorithm.Create("System.Security.Cryptography.SHA512CryptoServiceProvider"));
|
||||
#endif
|
||||
HashSizeValue = 512;
|
||||
BlockSizeValue = BlockSize;
|
||||
base.InitializeKey(key);
|
||||
|
@@ -46,7 +46,11 @@ namespace System.Security.Cryptography {
|
||||
//
|
||||
|
||||
new static public KeyedHashAlgorithm Create() {
|
||||
#if FULL_AOT_RUNTIME
|
||||
return new System.Security.Cryptography.HMACSHA1 ();
|
||||
#else
|
||||
return Create("System.Security.Cryptography.KeyedHashAlgorithm");
|
||||
#endif
|
||||
}
|
||||
|
||||
new static public KeyedHashAlgorithm Create(String algName) {
|
||||
|
@@ -23,7 +23,11 @@ namespace System.Security.Cryptography {
|
||||
//
|
||||
|
||||
new static public MD5 Create() {
|
||||
#if FULL_AOT_RUNTIME
|
||||
return new System.Security.Cryptography.MD5CryptoServiceProvider ();
|
||||
#else
|
||||
return Create("System.Security.Cryptography.MD5");
|
||||
#endif
|
||||
}
|
||||
|
||||
new static public MD5 Create(String algName) {
|
||||
|
@@ -32,7 +32,7 @@ namespace System.Security.Cryptography {
|
||||
private byte[] _password;
|
||||
private HashAlgorithm _hash;
|
||||
private CspParameters _cspParams;
|
||||
|
||||
#if !MONO
|
||||
[System.Security.SecurityCritical] // auto-generated
|
||||
private SafeProvHandle _safeProvHandle = null;
|
||||
private SafeProvHandle ProvHandle {
|
||||
@@ -50,7 +50,7 @@ namespace System.Security.Cryptography {
|
||||
return _safeProvHandle;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
//
|
||||
// public constructors
|
||||
//
|
||||
@@ -137,6 +137,11 @@ namespace System.Security.Cryptography {
|
||||
// disable csharp compiler warning #0809: obsolete member overrides non-obsolete member
|
||||
#pragma warning disable 0809
|
||||
public override byte[] GetBytes(int cb) {
|
||||
#if MONO
|
||||
if (cb < 1)
|
||||
throw new IndexOutOfRangeException ("cb");
|
||||
#endif
|
||||
|
||||
int ib = 0;
|
||||
byte[] rgb;
|
||||
byte[] rgbOut = new byte[cb];
|
||||
@@ -211,7 +216,9 @@ namespace System.Security.Cryptography {
|
||||
{
|
||||
if (keySize < 0)
|
||||
throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidKeySize"));
|
||||
|
||||
#if MONO
|
||||
throw new NotSupportedException ("CspParameters are not supported by Mono");
|
||||
#else
|
||||
int algidhash = X509Utils.NameOrOidToAlgId(alghashname, OidGroup.HashAlgorithm);
|
||||
if (algidhash == 0)
|
||||
throw new CryptographicException(Environment.GetResourceString("Cryptography_PasswordDerivedBytes_InvalidAlgorithm"));
|
||||
@@ -228,19 +235,20 @@ namespace System.Security.Cryptography {
|
||||
_password, _password.Length, keySize << 16, rgbIV, rgbIV.Length,
|
||||
JitHelpers.GetObjectHandleOnStack(ref key));
|
||||
return key;
|
||||
#endif
|
||||
}
|
||||
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
#if !MONO
|
||||
[System.Security.SecurityCritical] // auto-generated
|
||||
[ResourceExposure(ResourceScope.None)]
|
||||
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
|
||||
private static extern void DeriveKey(SafeProvHandle hProv, int algid, int algidHash,
|
||||
byte[] password, int cbPassword, int dwFlags, byte[] IV, int cbIV,
|
||||
ObjectHandleOnStack retKey);
|
||||
|
||||
#endif
|
||||
private byte[] ComputeBaseValue() {
|
||||
_hash.Initialize();
|
||||
_hash.TransformBlock(_password, 0, _password.Length, _password, 0);
|
||||
|
@@ -40,6 +40,10 @@ namespace System.Security.Cryptography {
|
||||
|
||||
public override byte[] GenerateMask(byte[] rgbSeed, int cbReturn)
|
||||
{
|
||||
#if MONO
|
||||
HashAlgorithm hash = HashAlgorithm.Create (HashNameValue);
|
||||
return Mono.Security.Cryptography.PKCS1.MGF1 (hash, rgbSeed, cbReturn);
|
||||
#else
|
||||
HashAlgorithm hash = (HashAlgorithm) CryptoConfig.CreateFromName(HashNameValue);
|
||||
byte[] rgbCounter = new byte[4];
|
||||
byte[] rgbT = new byte[cbReturn];
|
||||
@@ -60,6 +64,7 @@ namespace System.Security.Cryptography {
|
||||
ib += hash.Hash.Length;
|
||||
}
|
||||
return rgbT;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -31,7 +31,11 @@ namespace System.Security.Cryptography {
|
||||
|
||||
#if (!FEATURE_CORECLR && !SILVERLIGHT) || FEATURE_LEGACYNETCFCRYPTO
|
||||
static public RandomNumberGenerator Create() {
|
||||
#if FULL_AOT_RUNTIME
|
||||
return new System.Security.Cryptography.RNGCryptoServiceProvider ();
|
||||
#else
|
||||
return Create("System.Security.Cryptography.RandomNumberGenerator");
|
||||
#endif
|
||||
}
|
||||
|
||||
static public RandomNumberGenerator Create(String rngName) {
|
||||
|
@@ -72,7 +72,11 @@ namespace System.Security.Cryptography {
|
||||
//
|
||||
|
||||
new static public RC2 Create() {
|
||||
#if FULL_AOT_RUNTIME
|
||||
return new System.Security.Cryptography.RC2CryptoServiceProvider ();
|
||||
#else
|
||||
return Create("System.Security.Cryptography.RC2");
|
||||
#endif
|
||||
}
|
||||
|
||||
new static public RC2 Create(String AlgName) {
|
||||
|
@@ -69,14 +69,22 @@ namespace System.Security.Cryptography {
|
||||
|
||||
[System.Security.SecuritySafeCritical] // auto-generated
|
||||
public override ICryptoTransform CreateEncryptor (byte[] rgbKey, byte[] rgbIV) {
|
||||
#if MONO
|
||||
return new RC2Transform (this, true, rgbKey, rgbIV);
|
||||
#else
|
||||
return _NewEncryptor(rgbKey, ModeValue, rgbIV, EffectiveKeySizeValue,
|
||||
FeedbackSizeValue, CryptoAPITransformMode.Encrypt);
|
||||
#endif
|
||||
}
|
||||
|
||||
[System.Security.SecuritySafeCritical] // auto-generated
|
||||
public override ICryptoTransform CreateDecryptor (byte[] rgbKey, byte[] rgbIV) {
|
||||
#if MONO
|
||||
return new RC2Transform (this, false, rgbKey, rgbIV);
|
||||
#else
|
||||
return _NewEncryptor(rgbKey, ModeValue, rgbIV, EffectiveKeySizeValue,
|
||||
FeedbackSizeValue, CryptoAPITransformMode.Decrypt);
|
||||
#endif
|
||||
}
|
||||
|
||||
public override void GenerateKey () {
|
||||
@@ -93,7 +101,7 @@ namespace System.Security.Cryptography {
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
#if !MONO
|
||||
[System.Security.SecurityCritical] // auto-generated
|
||||
private ICryptoTransform _NewEncryptor (byte[] rgbKey, CipherMode mode, byte[] rgbIV,
|
||||
int effectiveKeySize, int feedbackSize, CryptoAPITransformMode encryptMode) {
|
||||
@@ -172,5 +180,6 @@ namespace System.Security.Cryptography {
|
||||
mode, BlockSizeValue, feedbackSize, m_use40bitSalt,
|
||||
encryptMode);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user