From 2162178cb7e209e9f060748842e1c4782a2ab852 Mon Sep 17 00:00:00 2001 From: vnugent Date: Sat, 17 Aug 2024 21:33:23 -0400 Subject: refactor: cipher utils update and simplify --- .../src/internal/FunctionTable.cs | 74 +++++++++++++--------- .../src/internal/NCEncryptionArgs.cs | 31 --------- .../src/internal/NCMacVerifyArgs.cs | 34 ---------- 3 files changed, 44 insertions(+), 95 deletions(-) delete mode 100644 wrappers/dotnet/VNLib.Utils.Cryptography.Noscrypt/src/internal/NCEncryptionArgs.cs delete mode 100644 wrappers/dotnet/VNLib.Utils.Cryptography.Noscrypt/src/internal/NCMacVerifyArgs.cs (limited to 'wrappers/dotnet/VNLib.Utils.Cryptography.Noscrypt/src/internal') diff --git a/wrappers/dotnet/VNLib.Utils.Cryptography.Noscrypt/src/internal/FunctionTable.cs b/wrappers/dotnet/VNLib.Utils.Cryptography.Noscrypt/src/internal/FunctionTable.cs index 17b66b2..0cda5e2 100644 --- a/wrappers/dotnet/VNLib.Utils.Cryptography.Noscrypt/src/internal/FunctionTable.cs +++ b/wrappers/dotnet/VNLib.Utils.Cryptography.Noscrypt/src/internal/FunctionTable.cs @@ -34,13 +34,16 @@ namespace VNLib.Utils.Cryptography.Noscrypt.@internal public readonly NCValidateSecretKeyDelegate NCValidateSecretKey; public readonly NCSignDataDelegate NCSignData; public readonly NCVerifyDataDelegate NCVerifyData; - public readonly NCEncryptDelegate NCEncrypt; - public readonly NCDecryptDelegate NCDecrypt; - public readonly NCVerifyMacDelegate NCVerifyMac; - public readonly NCComputeMacDelegate NCComputeMac; - public readonly NCSetEncryptionDataDelegate NCSetEncryptionData; - public readonly NCSetEncryptionPropertyDelegate NCSetEncryptionProperty; - public readonly NCSetEncryptionPropertyExDelegate NCSetEncryptionPropertyEx; + public readonly NCUtilCipherAllocDelegate NCUtilCipherAlloc; + public readonly NCUtilCipherFreeDelegate NCUtilCipherFree; + public readonly NCUtilCipherInitDelegate NCUtilCipherInit; + public readonly NCUtilCipherGetFlagsDelegate NCUtilCipherGetFlags; + public readonly NCUtilCipherGetOutputSizeDelegate NCUtilCipherGetOutputSize; + public readonly NCUtilCipherReadOutputDelegate NCUtilCipherReadOutput; + public readonly NCUtilCipherSetPropertyDelegate NCUtilCipherSetProperty; + public readonly NCUtilCipherUpdateDelegate NCUtilCipherUpdate; + public readonly NCUtilCipherGetIvSizeDelegate NCUtilCipherGetIvSize; + #if DEBUG public readonly NCGetConversationKeyDelegate NCGetConversationKey; @@ -59,13 +62,17 @@ namespace VNLib.Utils.Cryptography.Noscrypt.@internal NCVerifyData = library.DangerousGetFunction(); NCSignData = library.DangerousGetFunction(); NCVerifyData = library.DangerousGetFunction(); - NCEncrypt = library.DangerousGetFunction(); - NCDecrypt = library.DangerousGetFunction(); - NCVerifyMac = library.DangerousGetFunction(); - NCComputeMac = library.DangerousGetFunction(); - NCSetEncryptionData = library.DangerousGetFunction(); - NCSetEncryptionProperty = library.DangerousGetFunction(); - NCSetEncryptionPropertyEx = library.DangerousGetFunction(); + + //Cipher util library functions + NCUtilCipherAlloc = library.DangerousGetFunction(); + NCUtilCipherFree = library.DangerousGetFunction(); + NCUtilCipherInit = library.DangerousGetFunction(); + NCUtilCipherGetFlags = library.DangerousGetFunction(); + NCUtilCipherGetOutputSize = library.DangerousGetFunction(); + NCUtilCipherReadOutput = library.DangerousGetFunction(); + NCUtilCipherSetProperty = library.DangerousGetFunction(); + NCUtilCipherUpdate = library.DangerousGetFunction(); + NCUtilCipherGetIvSize = library.DangerousGetFunction(); #if DEBUG NCGetConversationKey = library.DangerousGetFunction(); @@ -114,28 +121,35 @@ namespace VNLib.Utils.Cryptography.Noscrypt.@internal [SafeMethodName("NCVerifyData")] internal delegate NCResult NCVerifyDataDelegate(IntPtr ctx, NCPublicKey* sk, byte* data, uint dataSize, byte* sig64); - [SafeMethodName("NCEncrypt")] - internal delegate NCResult NCEncryptDelegate(IntPtr ctx, NCSecretKey* sk, NCPublicKey* pk, NCEncryptionArgs* data); + [SafeMethodName("NCGetConversationKey")] + internal delegate NCResult NCGetConversationKeyDelegate(IntPtr ctx, NCSecretKey* sk, NCPublicKey* pk, byte* keyOut32); - [SafeMethodName("NCDecrypt")] - internal delegate NCResult NCDecryptDelegate(IntPtr ctx, NCSecretKey* sk, NCPublicKey* pk, NCEncryptionArgs* data); - [SafeMethodName("NCVerifyMac")] - internal delegate NCResult NCVerifyMacDelegate(IntPtr ctx, NCSecretKey* sk, NCPublicKey* pk, NCMacVerifyArgs* args); + [SafeMethodName("NCUtilCipherAlloc")] + internal delegate IntPtr NCUtilCipherAllocDelegate(uint version, uint flags); - [SafeMethodName("NCComputeMac")] - internal delegate NCResult NCComputeMacDelegate(IntPtr ctx, byte* hmacKey32, byte* payload, uint payloadSize, byte* hmacOut32); + [SafeMethodName("NCUtilCipherFree")] + internal delegate void NCUtilCipherFreeDelegate(IntPtr cipher); - [SafeMethodName("NCGetConversationKey")] - internal delegate NCResult NCGetConversationKeyDelegate(nint ctx, NCSecretKey* sk, NCPublicKey* pk, byte* keyOut32); + [SafeMethodName("NCUtilCipherInit")] + internal delegate NCResult NCUtilCipherInitDelegate(IntPtr cipher, byte* inputData, uint inputLen); + + [SafeMethodName("NCUtilCipherGetFlags")] + internal delegate NCResult NCUtilCipherGetFlagsDelegate(IntPtr cipher); + + [SafeMethodName("NCUtilCipherGetOutputSize")] + internal delegate NCResult NCUtilCipherGetOutputSizeDelegate(IntPtr cipher); + + [SafeMethodName("NCUtilCipherReadOutput")] + internal delegate NCResult NCUtilCipherReadOutputDelegate(IntPtr cipher, byte* outputData, uint outputLen); - [SafeMethodName("NCSetEncryptionProperty")] - internal delegate NCResult NCSetEncryptionPropertyDelegate(NCEncryptionArgs* args, uint property, uint value); + [SafeMethodName("NCUtilCipherSetProperty")] + internal delegate NCResult NCUtilCipherSetPropertyDelegate(IntPtr cipher, uint property, byte* value, uint valueLen); - [SafeMethodName("NCSetEncryptionPropertyEx")] - internal delegate NCResult NCSetEncryptionPropertyExDelegate(NCEncryptionArgs* args, uint property, byte* value, uint valueLen); + [SafeMethodName("NCUtilCipherUpdate")] + internal delegate NCResult NCUtilCipherUpdateDelegate(IntPtr cipher, IntPtr libContext, NCSecretKey* secKey, NCPublicKey* pubKey); - [SafeMethodName("NCSetEncryptionData")] - internal delegate NCResult NCSetEncryptionDataDelegate(NCEncryptionArgs* args, byte* input, byte* output, uint dataSize); + [SafeMethodName("NCUtilCipherGetIvSize")] + internal delegate NCResult NCUtilCipherGetIvSizeDelegate(IntPtr cipher); } } diff --git a/wrappers/dotnet/VNLib.Utils.Cryptography.Noscrypt/src/internal/NCEncryptionArgs.cs b/wrappers/dotnet/VNLib.Utils.Cryptography.Noscrypt/src/internal/NCEncryptionArgs.cs deleted file mode 100644 index 91f0ff5..0000000 --- a/wrappers/dotnet/VNLib.Utils.Cryptography.Noscrypt/src/internal/NCEncryptionArgs.cs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2024 Vaughn Nugent -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -using System; -using System.Runtime.InteropServices; - -namespace VNLib.Utils.Cryptography.Noscrypt.@internal -{ - [StructLayout(LayoutKind.Sequential)] - internal unsafe struct NCEncryptionArgs - { - public byte* nonceData; - public byte* keyData; - public byte* inputData; - public byte* outputData; - public uint dataSize; - public uint version; - } -} diff --git a/wrappers/dotnet/VNLib.Utils.Cryptography.Noscrypt/src/internal/NCMacVerifyArgs.cs b/wrappers/dotnet/VNLib.Utils.Cryptography.Noscrypt/src/internal/NCMacVerifyArgs.cs deleted file mode 100644 index 8a9ba1f..0000000 --- a/wrappers/dotnet/VNLib.Utils.Cryptography.Noscrypt/src/internal/NCMacVerifyArgs.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (C) 2024 Vaughn Nugent -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -using System; - -namespace VNLib.Utils.Cryptography.Noscrypt.@internal -{ - internal unsafe struct NCMacVerifyArgs - { - /* The message authentication code certifying the Nip44 payload */ - public byte* mac32; - - /* The nonce used for the original message encryption */ - public byte* nonce32; - - /* The message payload data */ - public byte* payload; - - /* The size of the payload data */ - public uint payloadSize; - } -} -- cgit