Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Jones <kevin@vcsjones.com>2022-09-28 18:03:11 +0300
committerGitHub <noreply@github.com>2022-09-28 18:03:11 +0300
commitaf88ee90bacedb49b90f7dc62a3092b287fc6ed0 (patch)
tree77e79de9c9309e552eb7d44629e62da381041282 /src/libraries
parent331dc3a0bbb17f47e4872e2dfef2283a351e48e3 (diff)
Cache KeySizes array for EC types
Individual KeySizes instances themselves are immutable, so we can re-use instances there. Arrays are mutable, so continue to return a copy of the array each time.
Diffstat (limited to 'src/libraries')
-rw-r--r--src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanAndroid.cs6
-rw-r--r--src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanCng.cs13
-rw-r--r--src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanOpenSsl.cs6
-rw-r--r--src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanSecurityTransforms.cs14
-rw-r--r--src/libraries/Common/src/System/Security/Cryptography/ECDsaAndroid.cs13
-rw-r--r--src/libraries/Common/src/System/Security/Cryptography/ECDsaCng.cs13
-rw-r--r--src/libraries/Common/src/System/Security/Cryptography/ECDsaOpenSsl.cs13
-rw-r--r--src/libraries/Common/src/System/Security/Cryptography/ECDsaSecurityTransforms.cs13
-rw-r--r--src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/ECAlgorithm.cs6
9 files changed, 20 insertions, 77 deletions
diff --git a/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanAndroid.cs b/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanAndroid.cs
index e7562198ac0..8f36a7e1a95 100644
--- a/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanAndroid.cs
+++ b/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanAndroid.cs
@@ -35,11 +35,7 @@ namespace System.Security.Cryptography
KeySizeValue = _key.KeySize;
}
- public override KeySizes[] LegalKeySizes =>
- new[] {
- new KeySizes(minSize: 256, maxSize: 384, skipSize: 128),
- new KeySizes(minSize: 521, maxSize: 521, skipSize: 0)
- };
+ public override KeySizes[] LegalKeySizes => s_defaultKeySizes.CloneKeySizesArray();
protected override void Dispose(bool disposing)
{
diff --git a/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanCng.cs b/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanCng.cs
index b79dd9474a9..a25cfcc3a4f 100644
--- a/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanCng.cs
+++ b/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanCng.cs
@@ -66,17 +66,8 @@ namespace System.Security.Cryptography
KeySizeValue = newKeySize;
}
- public override KeySizes[] LegalKeySizes
- {
- get
- {
- // Return the three sizes that can be explicitly set (for backwards compatibility)
- return new[] {
- new KeySizes(minSize: 256, maxSize: 384, skipSize: 128),
- new KeySizes(minSize: 521, maxSize: 521, skipSize: 0),
- };
- }
- }
+ // Return the three sizes that can be explicitly set (for backwards compatibility)
+ public override KeySizes[] LegalKeySizes => s_defaultKeySizes.CloneKeySizesArray();
public override byte[] DeriveKeyFromHash(
ECDiffieHellmanPublicKey otherPartyPublicKey,
diff --git a/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanOpenSsl.cs b/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanOpenSsl.cs
index 7855638b639..2f962e19fc3 100644
--- a/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanOpenSsl.cs
+++ b/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanOpenSsl.cs
@@ -45,11 +45,7 @@ namespace System.Security.Cryptography
_key = new ECOpenSsl(this);
}
- public override KeySizes[] LegalKeySizes =>
- new[] {
- new KeySizes(minSize: 256, maxSize: 384, skipSize: 128),
- new KeySizes(minSize: 521, maxSize: 521, skipSize: 0)
- };
+ public override KeySizes[] LegalKeySizes => s_defaultKeySizes.CloneKeySizesArray();
protected override void Dispose(bool disposing)
{
diff --git a/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanSecurityTransforms.cs b/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanSecurityTransforms.cs
index dd5a73838a1..496ee778970 100644
--- a/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanSecurityTransforms.cs
+++ b/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanSecurityTransforms.cs
@@ -27,18 +27,8 @@ namespace System.Security.Cryptography
KeySizeValue = _ecc.SetKeyAndGetSize(SecKeyPair.PublicPrivatePair(publicKey, privateKey));
}
- public override KeySizes[] LegalKeySizes
- {
- get
- {
- // Return the three sizes that can be explicitly set (for backwards compatibility)
- return new[]
- {
- new KeySizes(minSize: 256, maxSize: 384, skipSize: 128),
- new KeySizes(minSize: 521, maxSize: 521, skipSize: 0),
- };
- }
- }
+ // Return the three sizes that can be explicitly set (for backwards compatibility)
+ public override KeySizes[] LegalKeySizes => s_defaultKeySizes.CloneKeySizesArray();
public override int KeySize
{
diff --git a/src/libraries/Common/src/System/Security/Cryptography/ECDsaAndroid.cs b/src/libraries/Common/src/System/Security/Cryptography/ECDsaAndroid.cs
index 3b09a8045d0..0aac5fc91d9 100644
--- a/src/libraries/Common/src/System/Security/Cryptography/ECDsaAndroid.cs
+++ b/src/libraries/Common/src/System/Security/Cryptography/ECDsaAndroid.cs
@@ -68,17 +68,8 @@ namespace System.Security.Cryptography
KeySizeValue = newKeySize;
}
- public override KeySizes[] LegalKeySizes
- {
- get
- {
- // Return the three sizes that can be explicitly set (for backwards compatibility)
- return new[] {
- new KeySizes(minSize: 256, maxSize: 384, skipSize: 128),
- new KeySizes(minSize: 521, maxSize: 521, skipSize: 0),
- };
- }
- }
+ // Return the three sizes that can be explicitly set (for backwards compatibility)
+ public override KeySizes[] LegalKeySizes => s_defaultKeySizes.CloneKeySizesArray();
public override byte[] SignHash(byte[] hash)
{
diff --git a/src/libraries/Common/src/System/Security/Cryptography/ECDsaCng.cs b/src/libraries/Common/src/System/Security/Cryptography/ECDsaCng.cs
index 0edc06e4880..426a6bdd4ad 100644
--- a/src/libraries/Common/src/System/Security/Cryptography/ECDsaCng.cs
+++ b/src/libraries/Common/src/System/Security/Cryptography/ECDsaCng.cs
@@ -83,16 +83,7 @@ namespace System.Security.Cryptography
KeySizeValue = newKeySize;
}
- public override KeySizes[] LegalKeySizes
- {
- get
- {
- // Return the three sizes that can be explicitly set (for backwards compatibility)
- return new[] {
- new KeySizes(minSize: 256, maxSize: 384, skipSize: 128),
- new KeySizes(minSize: 521, maxSize: 521, skipSize: 0),
- };
- }
- }
+ // Return the three sizes that can be explicitly set (for backwards compatibility)
+ public override KeySizes[] LegalKeySizes => s_defaultKeySizes.CloneKeySizesArray();
}
}
diff --git a/src/libraries/Common/src/System/Security/Cryptography/ECDsaOpenSsl.cs b/src/libraries/Common/src/System/Security/Cryptography/ECDsaOpenSsl.cs
index 0e681955ae5..242711f8e5c 100644
--- a/src/libraries/Common/src/System/Security/Cryptography/ECDsaOpenSsl.cs
+++ b/src/libraries/Common/src/System/Security/Cryptography/ECDsaOpenSsl.cs
@@ -78,17 +78,8 @@ namespace System.Security.Cryptography
KeySizeValue = newKeySize;
}
- public override KeySizes[] LegalKeySizes
- {
- get
- {
- // Return the three sizes that can be explicitly set (for backwards compatibility)
- return new[] {
- new KeySizes(minSize: 256, maxSize: 384, skipSize: 128),
- new KeySizes(minSize: 521, maxSize: 521, skipSize: 0),
- };
- }
- }
+ // Return the three sizes that can be explicitly set (for backwards compatibility)
+ public override KeySizes[] LegalKeySizes => s_defaultKeySizes.CloneKeySizesArray();
public override byte[] SignHash(byte[] hash)
{
diff --git a/src/libraries/Common/src/System/Security/Cryptography/ECDsaSecurityTransforms.cs b/src/libraries/Common/src/System/Security/Cryptography/ECDsaSecurityTransforms.cs
index 7eaeb3b0b36..e02ea25ae2f 100644
--- a/src/libraries/Common/src/System/Security/Cryptography/ECDsaSecurityTransforms.cs
+++ b/src/libraries/Common/src/System/Security/Cryptography/ECDsaSecurityTransforms.cs
@@ -28,17 +28,8 @@ namespace System.Security.Cryptography
KeySizeValue = _ecc.SetKeyAndGetSize(SecKeyPair.PublicPrivatePair(publicKey, privateKey));
}
- public override KeySizes[] LegalKeySizes
- {
- get
- {
- // Return the three sizes that can be explicitly set (for backwards compatibility)
- return new[] {
- new KeySizes(minSize: 256, maxSize: 384, skipSize: 128),
- new KeySizes(minSize: 521, maxSize: 521, skipSize: 0),
- };
- }
- }
+ // Return the three sizes that can be explicitly set (for backwards compatibility)
+ public override KeySizes[] LegalKeySizes => s_defaultKeySizes.CloneKeySizesArray();
public override int KeySize
{
diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/ECAlgorithm.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/ECAlgorithm.cs
index 8362bd70572..5acdad43f82 100644
--- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/ECAlgorithm.cs
+++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/ECAlgorithm.cs
@@ -19,6 +19,12 @@ namespace System.Security.Cryptography
// ECDH and ECMQV are not valid in this context.
};
+ private protected static readonly KeySizes[] s_defaultKeySizes =
+ {
+ new KeySizes(minSize: 256, maxSize: 384, skipSize: 128),
+ new KeySizes(minSize: 521, maxSize: 521, skipSize: 0),
+ };
+
/// <summary>
/// When overridden in a derived class, exports the named or explicit <see cref="ECParameters" /> for an ECCurve.
/// If the curve has a name, the Curve property will contain named curve parameters otherwise it will contain explicit parameters.