Skip to content

Commit 48238f8

Browse files
committed
Use one-shot hash methods on modern .NET.
Signed-off-by: Bradley Grainger <[email protected]>
1 parent ec3619e commit 48238f8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/MySqlConnector.Authentication.Ed25519/Ed25519AuthenticationPlugin.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,12 @@ public void CreateResponseAndPasswordHash(string password, ReadOnlySpan<byte> au
8888
az[31] |= 64;
8989
*/
9090

91+
#if NET5_0_OR_GREATER
92+
byte[] az = SHA512.HashData(passwordBytes);
93+
#else
9194
using var sha512 = SHA512.Create();
9295
byte[] az = sha512.ComputeHash(passwordBytes);
96+
#endif
9397
ScalarOperations.sc_clamp(az, 0);
9498

9599
/*** Java
@@ -115,7 +119,11 @@ public void CreateResponseAndPasswordHash(string password, ReadOnlySpan<byte> au
115119
byte[] sm = new byte[64 + authenticationData.Length];
116120
authenticationData.CopyTo(sm.AsSpan().Slice(64));
117121
Buffer.BlockCopy(az, 32, sm, 32, 32);
122+
#if NET5_0_OR_GREATER
123+
byte[] nonce = SHA512.HashData(sm.AsSpan(32, authenticationData.Length + 32));
124+
#else
118125
byte[] nonce = sha512.ComputeHash(sm, 32, authenticationData.Length + 32);
126+
#endif
119127

120128
/*** Java
121129
ScalarOps scalar = new ScalarOps();
@@ -173,7 +181,11 @@ public void CreateResponseAndPasswordHash(string password, ReadOnlySpan<byte> au
173181
174182
return 0;
175183
*/
184+
#if NET5_0_OR_GREATER
185+
var hram = SHA512.HashData(sm);
186+
#else
176187
var hram = sha512.ComputeHash(sm);
188+
#endif
177189
ScalarOperations.sc_reduce(hram);
178190
var temp = new byte[32];
179191
ScalarOperations.sc_muladd(temp, hram, az, nonce);

0 commit comments

Comments
 (0)