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);