From 4893645536af64b01884ce5f3c392ad63513d04b Mon Sep 17 00:00:00 2001 From: Kevin Jones Date: Mon, 22 Feb 2021 15:54:33 -0500 Subject: [PATCH] Use SHA256 one-shot for CrlCache Co-authored-by: Jeremy Barton --- .../src/Internal/Cryptography/Pal.Unix/CrlCache.cs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Unix/CrlCache.cs b/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Unix/CrlCache.cs index d1c6aa7..eddad46 100644 --- a/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Unix/CrlCache.cs +++ b/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Unix/CrlCache.cs @@ -28,9 +28,6 @@ namespace Internal.Cryptography.Pal private const ulong X509_R_CERT_ALREADY_IN_HASH_TABLE = 0x0B07D065; - [ThreadStatic] - private static HashAlgorithm? ts_urlHash; - public static void AddCrlForCertificate( SafeX509Handle cert, SafeX509StoreHandle store, @@ -215,21 +212,15 @@ namespace Internal.Cryptography.Pal } uint persistentHash = unchecked((uint)persistentHashLong); - - if (ts_urlHash == null) - { - ts_urlHash = SHA256.Create(); - } - Span hash = stackalloc byte[256 >> 3]; // Endianness isn't important, it just needs to be consistent. // (Even if the same storage was used for two different endianness systems it'd stabilize at two files). ReadOnlySpan utf16Url = MemoryMarshal.AsBytes(crlUrl.AsSpan()); - if (!ts_urlHash.TryComputeHash(utf16Url, hash, out int written) || written != hash.Length) + if (SHA256.HashData(utf16Url, hash) != hash.Length) { - Debug.Fail("TryComputeHash failed or produced an incorrect length output"); + Debug.Fail("HashData failed or produced an incorrect length output"); throw new CryptographicException(); } -- 2.7.4