From 6f7f4a4f03c7e62db64c01b2a0b128586bf11dad Mon Sep 17 00:00:00 2001 From: vnugent Date: Mon, 27 Mar 2023 02:20:06 -0400 Subject: Native heap api and alloc optimizations --- lib/Plugins.Essentials/src/Accounts/NonceExtensions.cs | 4 ++-- lib/Plugins.Essentials/src/Accounts/PasswordHashing.cs | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/Plugins.Essentials/src/Accounts') diff --git a/lib/Plugins.Essentials/src/Accounts/NonceExtensions.cs b/lib/Plugins.Essentials/src/Accounts/NonceExtensions.cs index 5a40d29..0d9ca10 100644 --- a/lib/Plugins.Essentials/src/Accounts/NonceExtensions.cs +++ b/lib/Plugins.Essentials/src/Accounts/NonceExtensions.cs @@ -44,7 +44,7 @@ namespace VNLib.Plugins.Essentials.Accounts public static string ComputeNonce(this T nonce, int size) where T: INonce { //Alloc bin buffer - using UnsafeMemoryHandle buffer = MemoryUtil.UnsafeAlloc(size); + using UnsafeMemoryHandle buffer = MemoryUtil.UnsafeAlloc(size); //Compute nonce nonce.ComputeNonce(buffer.Span); @@ -63,7 +63,7 @@ namespace VNLib.Plugins.Essentials.Accounts public static bool VerifyNonce(this T nonce, ReadOnlySpan base32Nonce) where T : INonce { //Alloc bin buffer - using UnsafeMemoryHandle buffer = MemoryUtil.UnsafeAlloc(base32Nonce.Length); + using UnsafeMemoryHandle buffer = MemoryUtil.UnsafeAlloc(base32Nonce.Length); //Decode base32 nonce ERRNO count = VnEncoding.TryFromBase32Chars(base32Nonce, buffer.Span); diff --git a/lib/Plugins.Essentials/src/Accounts/PasswordHashing.cs b/lib/Plugins.Essentials/src/Accounts/PasswordHashing.cs index db5b309..32e04e3 100644 --- a/lib/Plugins.Essentials/src/Accounts/PasswordHashing.cs +++ b/lib/Plugins.Essentials/src/Accounts/PasswordHashing.cs @@ -96,7 +96,7 @@ namespace VNLib.Plugins.Essentials.Accounts else { //Alloc heap buffer - using UnsafeMemoryHandle secretBuffer = MemoryUtil.UnsafeAlloc(_secret.BufferSize, true); + using UnsafeMemoryHandle secretBuffer = MemoryUtil.UnsafeAlloc(_secret.BufferSize, true); return VerifyInternal(passHash, password, secretBuffer); } @@ -130,7 +130,7 @@ namespace VNLib.Plugins.Essentials.Accounts public bool Verify(ReadOnlySpan hash, ReadOnlySpan salt, ReadOnlySpan password) { //Alloc a buffer with the same size as the hash - using UnsafeMemoryHandle hashBuf = MemoryUtil.UnsafeAlloc(hash.Length, true); + using UnsafeMemoryHandle hashBuf = MemoryUtil.UnsafeAlloc(hash.Length, true); //Hash the password with the current config Hash(password, salt, hashBuf.Span); //Compare the hashed password to the specified hash and return results @@ -143,7 +143,7 @@ namespace VNLib.Plugins.Essentials.Accounts public PrivateString Hash(ReadOnlySpan password) { //Alloc shared buffer for the salt and secret buffer - using UnsafeMemoryHandle buffer = MemoryUtil.UnsafeAlloc(SaltLen + _secret.BufferSize, true); + using UnsafeMemoryHandle buffer = MemoryUtil.UnsafeAlloc(SaltLen + _secret.BufferSize, true); try { //Split buffers @@ -170,7 +170,7 @@ namespace VNLib.Plugins.Essentials.Accounts /// A of the hashed and encoded password public PrivateString Hash(ReadOnlySpan password) { - using UnsafeMemoryHandle buffer = MemoryUtil.UnsafeAlloc(SaltLen + _secret.BufferSize, true); + using UnsafeMemoryHandle buffer = MemoryUtil.UnsafeAlloc(SaltLen + _secret.BufferSize, true); try { //Split buffers @@ -203,7 +203,7 @@ namespace VNLib.Plugins.Essentials.Accounts public void Hash(ReadOnlySpan password, ReadOnlySpan salt, Span hashOutput) { //alloc secret buffer - using UnsafeMemoryHandle secretBuffer = MemoryUtil.UnsafeAlloc(_secret.BufferSize, true); + using UnsafeMemoryHandle secretBuffer = MemoryUtil.UnsafeAlloc(_secret.BufferSize, true); try { //Get the secret from the callback -- cgit