From 9debdda1fa6526df6d8423a5536a640464a36385 Mon Sep 17 00:00:00 2001 From: JacobBarthelmeh Date: Fri, 10 Oct 2025 12:32:14 -0600 Subject: [PATCH] fix for C# wrapper Ed25519 import raw key and fix Curve25519 private key decode --- wrapper/CSharp/wolfSSL_CSharp/wolfCrypt.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/wrapper/CSharp/wolfSSL_CSharp/wolfCrypt.cs b/wrapper/CSharp/wolfSSL_CSharp/wolfCrypt.cs index 4f58139c2..7d0c378d1 100644 --- a/wrapper/CSharp/wolfSSL_CSharp/wolfCrypt.cs +++ b/wrapper/CSharp/wolfSSL_CSharp/wolfCrypt.cs @@ -2206,7 +2206,7 @@ namespace wolfSSL.CSharp try { /* Allocate memory */ - key = Marshal.AllocHGlobal(ED25519_PUB_KEY_SIZE); + key = wc_ed25519_new(IntPtr.Zero, INVALID_DEVID, IntPtr.Zero); if (key == IntPtr.Zero) { throw new OutOfMemoryException("Failed to allocate memory for the key."); @@ -2222,20 +2222,26 @@ namespace wolfSSL.CSharp ret = wc_ed25519_import_public(inMsgPtr, inLen, key); if (ret != 0) { + if (key != IntPtr.Zero) { + wc_ed25519_delete(key, IntPtr.Zero); + key = IntPtr.Zero; + } return ret; } } catch (Exception ex) { Console.WriteLine("Exception in EdImportPublic: " + ex.Message); - + if (key != IntPtr.Zero) { + wc_ed25519_delete(key, IntPtr.Zero); + key = IntPtr.Zero; + } return EXCEPTION_E; } finally { /* Cleanup */ if (inMsgPtr != IntPtr.Zero) Marshal.FreeHGlobal(inMsgPtr); - if (key != IntPtr.Zero) Marshal.FreeHGlobal(key); } return ret; @@ -2415,7 +2421,7 @@ namespace wolfSSL.CSharp try { - key = wc_ed25519_new(IntPtr.Zero, INVALID_DEVID, IntPtr.Zero); + key = wc_curve25519_new(IntPtr.Zero, INVALID_DEVID, IntPtr.Zero); if (key != IntPtr.Zero) { ret = wc_Ed25519PrivateKeyDecode(input, ref idx, key, (uint)input.Length);