From 614c02097f5f173299948df279c2d3e2f9f748f9 Mon Sep 17 00:00:00 2001 From: vnugent Date: Sun, 30 Jun 2024 22:56:29 -0400 Subject: small cleanup for context switch --- .../src/NoscryptExtensions.cs | 24 +++++++++++----------- .../src/NostrMessageCipher.cs | 1 - 2 files changed, 12 insertions(+), 13 deletions(-) (limited to 'wrappers/dotnet') diff --git a/wrappers/dotnet/VNLib.Utils.Cryptography.Noscrypt/src/NoscryptExtensions.cs b/wrappers/dotnet/VNLib.Utils.Cryptography.Noscrypt/src/NoscryptExtensions.cs index 89bd057..ccae190 100644 --- a/wrappers/dotnet/VNLib.Utils.Cryptography.Noscrypt/src/NoscryptExtensions.cs +++ b/wrappers/dotnet/VNLib.Utils.Cryptography.Noscrypt/src/NoscryptExtensions.cs @@ -14,6 +14,7 @@ // along with this program. If not, see . using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using static VNLib.Utils.Cryptography.Noscrypt.NoscryptLibrary; @@ -71,14 +72,14 @@ namespace VNLib.Utils.Cryptography.Noscrypt ArgumentNullException.ThrowIfNull(nonce32); //Spans are easer to forward references from pointers without screwing up arguments - EncryptNip44( - lib: lib, + lib.EncryptNip44( secretKey: in secretKey, publicKey: in publicKey, - nonce32: new ReadOnlySpan(nonce32, NC_ENCRYPTION_NONCE_SIZE), - plainText: new ReadOnlySpan(plainText, (int)size), - hmackKeyOut32: new Span(hmacKeyOut32, NC_HMAC_KEY_SIZE), - cipherText: new Span(cipherText, (int)size) + nonce32: in Unsafe.AsRef(nonce32), + plainText: in Unsafe.AsRef(plainText), + cipherText: ref Unsafe.AsRef(cipherText), + size: size, + hmacKeyOut32: ref Unsafe.AsRef(hmacKeyOut32) ); } @@ -175,14 +176,13 @@ namespace VNLib.Utils.Cryptography.Noscrypt ArgumentNullException.ThrowIfNull(mac32); ArgumentNullException.ThrowIfNull(payload); - //Spans are easer to forward references from pointers without screwing up arguments - return VerifyMac( - lib: lib, + return lib.VerifyMac( secretKey: in secretKey, publicKey: in publicKey, - nonce32: new Span(nonce32, NC_ENCRYPTION_NONCE_SIZE), - mac32: new Span(mac32, NC_ENCRYPTION_MAC_SIZE), - payload: new Span(payload, (int)payloadSize) + nonce32: in Unsafe.AsRef(nonce32), + mac32: in Unsafe.AsRef(mac32), + payload: in Unsafe.AsRef(payload), + payloadSize: payloadSize ); } diff --git a/wrappers/dotnet/VNLib.Utils.Cryptography.Noscrypt/src/NostrMessageCipher.cs b/wrappers/dotnet/VNLib.Utils.Cryptography.Noscrypt/src/NostrMessageCipher.cs index 0982d3a..918d196 100644 --- a/wrappers/dotnet/VNLib.Utils.Cryptography.Noscrypt/src/NostrMessageCipher.cs +++ b/wrappers/dotnet/VNLib.Utils.Cryptography.Noscrypt/src/NostrMessageCipher.cs @@ -19,7 +19,6 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Security.Authentication; -using VNLib.Utils.Extensions; using VNLib.Utils.Memory; using static VNLib.Utils.Cryptography.Noscrypt.NoscryptLibrary; -- cgit