Skip to content

Commit 9debdda

Browse files
fix for C# wrapper Ed25519 import raw key and fix Curve25519 private key decode
1 parent a081a03 commit 9debdda

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

wrapper/CSharp/wolfSSL_CSharp/wolfCrypt.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,7 +2206,7 @@ public static int Ed25519ImportPublic(byte[] inMsg, uint inLen, out IntPtr key)
22062206
try
22072207
{
22082208
/* Allocate memory */
2209-
key = Marshal.AllocHGlobal(ED25519_PUB_KEY_SIZE);
2209+
key = wc_ed25519_new(IntPtr.Zero, INVALID_DEVID, IntPtr.Zero);
22102210
if (key == IntPtr.Zero)
22112211
{
22122212
throw new OutOfMemoryException("Failed to allocate memory for the key.");
@@ -2222,20 +2222,26 @@ public static int Ed25519ImportPublic(byte[] inMsg, uint inLen, out IntPtr key)
22222222
ret = wc_ed25519_import_public(inMsgPtr, inLen, key);
22232223
if (ret != 0)
22242224
{
2225+
if (key != IntPtr.Zero) {
2226+
wc_ed25519_delete(key, IntPtr.Zero);
2227+
key = IntPtr.Zero;
2228+
}
22252229
return ret;
22262230
}
22272231
}
22282232
catch (Exception ex)
22292233
{
22302234
Console.WriteLine("Exception in EdImportPublic: " + ex.Message);
2231-
2235+
if (key != IntPtr.Zero) {
2236+
wc_ed25519_delete(key, IntPtr.Zero);
2237+
key = IntPtr.Zero;
2238+
}
22322239
return EXCEPTION_E;
22332240
}
22342241
finally
22352242
{
22362243
/* Cleanup */
22372244
if (inMsgPtr != IntPtr.Zero) Marshal.FreeHGlobal(inMsgPtr);
2238-
if (key != IntPtr.Zero) Marshal.FreeHGlobal(key);
22392245
}
22402246

22412247
return ret;
@@ -2415,7 +2421,7 @@ public static IntPtr Curve25519PrivateKeyDecode(byte[] input)
24152421

24162422
try
24172423
{
2418-
key = wc_ed25519_new(IntPtr.Zero, INVALID_DEVID, IntPtr.Zero);
2424+
key = wc_curve25519_new(IntPtr.Zero, INVALID_DEVID, IntPtr.Zero);
24192425
if (key != IntPtr.Zero)
24202426
{
24212427
ret = wc_Ed25519PrivateKeyDecode(input, ref idx, key, (uint)input.Length);

0 commit comments

Comments
 (0)