Set ECDsaCng default hash algorithm to SHA256
authorDávid Kaya <mail@davidkaya.sk>
Sun, 29 Jul 2018 17:36:36 +0000 (19:36 +0200)
committerJeremy Barton <jbarton@microsoft.com>
Sun, 29 Jul 2018 17:36:36 +0000 (10:36 -0700)
Also added tests for both ECDsaCng and ECDiffieHellmanCng to ensure the default matches .NET Framework.

Commit migrated from https://github.com/dotnet/corefx/commit/d60303de08c9c9c4b2138f02ad597f6486648c11

src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/ECDsaCng.cs
src/libraries/System.Security.Cryptography.Cng/tests/ECDiffieHellmanCngTests.cs
src/libraries/System.Security.Cryptography.Cng/tests/ECDsaCngTests.cs

index 891afde..4a148fb 100644 (file)
@@ -10,7 +10,7 @@ namespace System.Security.Cryptography
     public sealed partial class ECDsaCng : ECDsa
     {
         private CngAlgorithmCore _core;
-        private CngAlgorithm _hashAlgorithm;
+        private CngAlgorithm _hashAlgorithm = CngAlgorithm.Sha256;
 
         /// <summary>
         ///     Hash algorithm to use when generating a signature over arbitrary data
index e219751..aea48b4 100644 (file)
@@ -173,5 +173,12 @@ namespace System.Security.Cryptography.EcDiffieHellman.Tests
                 Assert.Equal(outputCng, outputAlgorithms);
             }
         }
+
+        [Fact]
+        public static void HashAlgorithm_DefaultsToSha256()
+        {
+            using (var ecdhCng = new ECDiffieHellmanCng())
+                Assert.Equal(CngAlgorithm.Sha256, ecdhCng.HashAlgorithm);
+        }
     }
 }
index e73d9ab..9424c71 100644 (file)
@@ -151,6 +151,13 @@ namespace System.Security.Cryptography.Cng.Tests
             }
         }
 
+        [Fact]
+        public static void HashAlgorithm_DefaultsToSha256()
+        {
+            using (var cng = new ECDsaCng())
+               Assert.Equal(CngAlgorithm.Sha256, cng.HashAlgorithm);
+        }
+
 #if netcoreapp
         [Fact]
         public static void TestPositive256WithBlob()