diff options
Diffstat (limited to 'lib/Hashing.Portable')
-rw-r--r-- | lib/Hashing.Portable/src/Argon2/VnArgon2.cs | 14 | ||||
-rw-r--r-- | lib/Hashing.Portable/src/Checksums/FNV1a.cs | 4 | ||||
-rw-r--r-- | lib/Hashing.Portable/src/Native/MonoCypher/MonoCypherLibrary.cs | 8 |
3 files changed, 13 insertions, 13 deletions
diff --git a/lib/Hashing.Portable/src/Argon2/VnArgon2.cs b/lib/Hashing.Portable/src/Argon2/VnArgon2.cs index 9d98050..b88c232 100644 --- a/lib/Hashing.Portable/src/Argon2/VnArgon2.cs +++ b/lib/Hashing.Portable/src/Argon2/VnArgon2.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Hashing.Portable @@ -24,7 +24,6 @@ using System; using System.Text; -using System.Threading; using System.Diagnostics; using System.Buffers.Text; using System.Security.Cryptography; @@ -33,6 +32,7 @@ using System.Runtime.InteropServices; using VNLib.Utils.Memory; using VNLib.Utils.Native; using VNLib.Utils.Extensions; +using VNLib.Utils.Resources; using VNLib.Hashing.Native.MonoCypher; namespace VNLib.Hashing @@ -52,12 +52,12 @@ namespace VNLib.Hashing public const string ARGON2_LIB_ENVIRONMENT_VAR_NAME = "VNLIB_ARGON2_DLL_PATH"; private static readonly Encoding LocEncoding = Encoding.Unicode; - private static readonly Lazy<IUnmangedHeap> _heap = new (static () => MemoryUtil.InitializeNewHeapForProcess(true), LazyThreadSafetyMode.PublicationOnly); - private static readonly Lazy<IArgon2Library> _nativeLibrary = new(LoadSharedLibInternal, LazyThreadSafetyMode.PublicationOnly); + private static readonly LazyInitializer<IUnmangedHeap> _heap = new (static () => MemoryUtil.InitializeNewHeapForProcess(true)); + private static readonly LazyInitializer<IArgon2Library> _nativeLibrary = new(LoadSharedLibInternal); //Private heap initialized to 10k size, and all allocated buffers will be zeroed when allocated - private static IUnmangedHeap PwHeap => _heap.Value; + private static IUnmangedHeap PwHeap => _heap.Instance; private static IArgon2Library LoadSharedLibInternal() { @@ -70,7 +70,7 @@ namespace VNLib.Hashing Trace.WriteLine("Using the native MonoCypher library for Argon2 password hashing", "VnArgon2"); //Load shared monocyphter argon2 library - return MonoCypherLibrary.Shared.Argon2CreateLibrary(_heap.Value); + return MonoCypherLibrary.Shared.Argon2CreateLibrary(_heap.Instance); } else { @@ -90,7 +90,7 @@ namespace VNLib.Hashing /// </summary> /// <returns>The shared library instance</returns> /// <exception cref="DllNotFoundException"></exception> - public static IArgon2Library GetOrLoadSharedLib() => _nativeLibrary.Value; + public static IArgon2Library GetOrLoadSharedLib() => _nativeLibrary.Instance; /// <summary> /// Loads a native Argon2 shared library from the specified path diff --git a/lib/Hashing.Portable/src/Checksums/FNV1a.cs b/lib/Hashing.Portable/src/Checksums/FNV1a.cs index 5bac86f..f150638 100644 --- a/lib/Hashing.Portable/src/Checksums/FNV1a.cs +++ b/lib/Hashing.Portable/src/Checksums/FNV1a.cs @@ -95,8 +95,8 @@ namespace VNLib.Hashing.Checksums public static ulong Compute64(ref byte data, nuint length) => Update64(FNV_OFFSET_BASIS, ref data, length); /// <summary> - /// Provides a managed software implementation of the FNV-1a 64-bit - /// non cryptographic hash algorithm + /// Computes the next 64-bit FNV-1a hash value using the current hash + /// value and the next byte of data. /// </summary> /// <param name="data">A span structure pointing to the memory block to compute the digest of</param> /// <returns>The 64bit unsigned integer representng the message sum or digest</returns> diff --git a/lib/Hashing.Portable/src/Native/MonoCypher/MonoCypherLibrary.cs b/lib/Hashing.Portable/src/Native/MonoCypher/MonoCypherLibrary.cs index 11e524b..4c6f405 100644 --- a/lib/Hashing.Portable/src/Native/MonoCypher/MonoCypherLibrary.cs +++ b/lib/Hashing.Portable/src/Native/MonoCypher/MonoCypherLibrary.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Hashing.Portable @@ -25,10 +25,10 @@ using System; using System.Diagnostics; using System.Runtime.InteropServices; -using System.Threading; using VNLib.Utils; using VNLib.Utils.Native; +using VNLib.Utils.Resources; using VNLib.Utils.Extensions; namespace VNLib.Hashing.Native.MonoCypher @@ -50,7 +50,7 @@ namespace VNLib.Hashing.Native.MonoCypher /// <returns>true if the user enabled the default library, false otherwise</returns> public static bool CanLoadDefaultLibrary() => string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(MONOCYPHER_LIB_ENVIRONMENT_VAR_NAME)) == false; - private static readonly Lazy<MonoCypherLibrary> _defaultLib = new (LoadDefaultLibraryInternal, LazyThreadSafetyMode.PublicationOnly); + private static readonly LazyInitializer<MonoCypherLibrary> _defaultLib = new (LoadDefaultLibraryInternal); /// <summary> /// Gets the default MonoCypher library for the current process @@ -59,7 +59,7 @@ namespace VNLib.Hashing.Native.MonoCypher /// this property to ensure that the default library can be loaded /// </para> /// </summary> - public static MonoCypherLibrary Shared => _defaultLib.Value; + public static MonoCypherLibrary Shared => _defaultLib.Instance; /// <summary> /// Loads a new instance of the MonoCypher library with environment defaults |