Skip to content

Commit d692f99

Browse files
committed
More peer review fixes (Use ML-DSA naming)
1 parent 5f124a9 commit d692f99

2 files changed

Lines changed: 100 additions & 75 deletions

File tree

wrapper/CSharp/wolfCrypt-Test/wolfCrypt-Test.cs

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,7 @@ private static void mldsa_test(wolfcrypt.MlDsaLevels level)
843843
{
844844
int ret = 0;
845845
IntPtr key = IntPtr.Zero;
846+
IntPtr importKey = IntPtr.Zero;
846847
IntPtr heap = IntPtr.Zero;
847848
int devId = wolfcrypt.INVALID_DEVID;
848849
byte[] privateKey = null;
@@ -856,7 +857,7 @@ private static void mldsa_test(wolfcrypt.MlDsaLevels level)
856857

857858
/* Generate Key */
858859
Console.WriteLine("Testing ML-DSA Key Generation...");
859-
key = wolfcrypt.DilithiumMakeKey(heap, devId, level);
860+
key = wolfcrypt.MlDsaMakeKey(heap, devId, level);
860861
if (key == IntPtr.Zero)
861862
{
862863
ret = -1;
@@ -871,15 +872,15 @@ private static void mldsa_test(wolfcrypt.MlDsaLevels level)
871872
if (ret == 0)
872873
{
873874
Console.WriteLine("Testing ML-DSA Key Export...");
874-
ret = wolfcrypt.DilithiumExportPrivateKey(key, out privateKey);
875+
ret = wolfcrypt.MlDsaExportPrivateKey(key, out privateKey);
875876
if (ret != 0)
876877
{
877878
Console.Error.WriteLine($"Failed to export private key. Error code: {ret}");
878879
}
879880
}
880881
if (ret == 0)
881882
{
882-
ret = wolfcrypt.DilithiumExportPublicKey(key, out publicKey);
883+
ret = wolfcrypt.MlDsaExportPublicKey(key, out publicKey);
883884
if (ret != 0)
884885
{
885886
Console.Error.WriteLine($"Failed to export public key. Error code: {ret}");
@@ -890,19 +891,30 @@ private static void mldsa_test(wolfcrypt.MlDsaLevels level)
890891
Console.WriteLine("ML-DSA Key Export test passed.");
891892
}
892893

893-
/* Import */
894+
/* Import into a fresh key to test the full import workflow */
894895
if (ret == 0)
895896
{
896897
Console.WriteLine("Testing ML-DSA Key Import...");
897-
ret = wolfcrypt.DilithiumImportPrivateKey(privateKey, key);
898+
/* Free the keygen key and create a fresh one for import */
899+
wolfcrypt.MlDsaFreeKey(ref key);
900+
importKey = wolfcrypt.MlDsaNew(heap, devId, level);
901+
if (importKey == IntPtr.Zero)
902+
{
903+
ret = -1;
904+
Console.Error.WriteLine("Failed to allocate key for import.");
905+
}
906+
}
907+
if (ret == 0)
908+
{
909+
ret = wolfcrypt.MlDsaImportPrivateKey(privateKey, importKey);
898910
if (ret != 0)
899911
{
900912
Console.Error.WriteLine($"Failed to import private key. Error code: {ret}");
901913
}
902914
}
903915
if (ret == 0)
904916
{
905-
ret = wolfcrypt.DilithiumImportPublicKey(publicKey, key);
917+
ret = wolfcrypt.MlDsaImportPublicKey(publicKey, importKey);
906918
if (ret != 0)
907919
{
908920
Console.Error.WriteLine($"Failed to import public key. Error code: {ret}");
@@ -913,11 +925,11 @@ private static void mldsa_test(wolfcrypt.MlDsaLevels level)
913925
Console.WriteLine("ML-DSA Key Import test passed.");
914926
}
915927

916-
/* Sign */
928+
/* Sign with imported key */
917929
if (ret == 0)
918930
{
919931
Console.WriteLine("Testing ML-DSA Signature Creation...");
920-
ret = wolfcrypt.DilithiumSignMsg(key, message, out signature);
932+
ret = wolfcrypt.MlDsaSignMsg(importKey, message, out signature);
921933
if (ret != 0)
922934
{
923935
Console.Error.WriteLine($"Failed to sign. Error code: {ret}");
@@ -928,11 +940,11 @@ private static void mldsa_test(wolfcrypt.MlDsaLevels level)
928940
Console.WriteLine($"ML-DSA Signature Creation test passed. Signature Length: {signature.Length}");
929941
}
930942

931-
/* Verify */
943+
/* Verify with imported key */
932944
if (ret == 0)
933945
{
934946
Console.WriteLine("Testing ML-DSA Signature Verification...");
935-
ret = wolfcrypt.DilithiumVerifyMsg(key, message, signature);
947+
ret = wolfcrypt.MlDsaVerifyMsg(importKey, message, signature);
936948
if (ret != 0)
937949
{
938950
Console.Error.WriteLine($"Failed to verify message. Error code: {ret}");
@@ -957,11 +969,11 @@ private static void mldsa_test(wolfcrypt.MlDsaLevels level)
957969
{
958970
if (key != IntPtr.Zero)
959971
{
960-
ret = wolfcrypt.DilithiumFreeKey(ref key);
961-
if (ret != 0)
962-
{
963-
Console.Error.WriteLine($"Failed to free ML-DSA key. Error code: {ret}");
964-
}
972+
wolfcrypt.MlDsaFreeKey(ref key);
973+
}
974+
if (importKey != IntPtr.Zero)
975+
{
976+
wolfcrypt.MlDsaFreeKey(ref importKey);
965977
}
966978
}
967979

0 commit comments

Comments
 (0)