diff --git a/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanAndroid.cs b/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanAndroid.cs index e7562198ac09ffa11a68044d7138ed709e47c4f2..8f36a7e1a95260eb5ccbb52da82a961ad840b602 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 @@ internal ECDiffieHellmanAndroid(SafeEcKeyHandle ecKeyHandle) 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 b79dd9474a91dd23ede71da093ac6d5732e29bcf..a25cfcc3a4f6c769b8cab5a020a9f96268bedc85 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 @@ private void ForceSetKeySize(int newKeySize) 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 7855638b639ea32ba2c835d76cf400452c29c8d7..2f962e19fc3ef08fe560646d265d73263e3f5ade 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 @@ public ECDiffieHellmanOpenSsl(int keySize) _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 dd5a73838a1592ddbe0405e9daafeb5913ae7cfb..496ee77897037213de932db0e1c27af6fa42bfea 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 @@ internal ECDiffieHellmanSecurityTransforms(SafeSecKeyRefHandle publicKey, SafeSe 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 3b09a8045d029cc2392461830f0fe40f81fe9975..0aac5fc91d94414a89eb8d8170ea2cdb42a27fea 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 @@ private void ForceSetKeySize(int newKeySize) 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 0edc06e488069958c402b17de9ff844e2d5731b1..426a6bdd4ad051862131480f0d3175722530fd8a 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 @@ private void ForceSetKeySize(int newKeySize) 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 0e681955ae5e36e4aca34301d602cbb01e859d16..242711f8e5cf43997ac7e2139fbfdef4b250c06e 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 @@ private void ForceSetKeySize(int newKeySize) 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 7eaeb3b0b360db695da5281acb60dc544b2618d4..e02ea25ae2f0fd1fff680a474daf0e21730873f2 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 @@ internal ECDsaSecurityTransforms(SafeSecKeyRefHandle publicKey, SafeSecKeyRefHan 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 8362bd705721d8c7cb1f9c3ccd41a589549ef396..5acdad43f82eaf021c13b20fb206fe2da01ff868 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 @@ public abstract class ECAlgorithm : AsymmetricAlgorithm // 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), + }; + /// /// When overridden in a derived class, exports the named or explicit for an ECCurve. /// If the curve has a name, the Curve property will contain named curve parameters otherwise it will contain explicit parameters.