Skip to content

Commit 79d1f67

Browse files
committed
Exit success after ml_dsa prints its parameter table
1 parent 666b6a4 commit 79d1f67

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

pq/ml_dsa/ml_dsa.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
/* wolfssl includes */
99
#include <wolfssl/options.h>
10-
#include <wolfssl/wolfcrypt/dilithium.h>
10+
#include <wolfssl/wolfcrypt/wc_mldsa.h>
1111
#include <wolfssl/wolfcrypt/random.h>
1212
#include <wolfssl/wolfcrypt/memory.h>
1313

@@ -220,11 +220,14 @@ main(int argc,
220220
goto ml_dsa_exit;
221221
}
222222

223-
rc = wc_MlDsaKey_Sign(&key, sig, &sig_len, (const byte *) msg, strlen(msg),
224-
&rng);
223+
/* ctx=NULL/ctxLen=0 is FIPS 204 signing with an empty context. The older
224+
* wc_MlDsaKey_Sign is pre-FIPS 204 and only exists under
225+
* WOLFSSL_MLDSA_NO_CTX. */
226+
rc = wc_MlDsaKey_SignCtx(&key, NULL, 0, sig, &sig_len,
227+
(const byte *) msg, strlen(msg), &rng);
225228

226229
if (rc != 0) {
227-
printf("error: wc_MlDsaKey_Sign returned %d\n", rc);
230+
printf("error: wc_MlDsaKey_SignCtx returned %d\n", rc);
228231
goto ml_dsa_exit;
229232
}
230233

@@ -235,15 +238,15 @@ main(int argc,
235238
ml_dsa_dump_file((const uint8_t *) msg, strlen(msg), "msg.bin");
236239
ml_dsa_dump_file(sig, sig_len, "signature.bin");
237240

238-
rc = wc_MlDsaKey_Verify(&key, sig, sig_len,
239-
(const byte *) msg, strlen(msg),
240-
&verify_res);
241+
rc = wc_MlDsaKey_VerifyCtx(&key, sig, sig_len, NULL, 0,
242+
(const byte *) msg, strlen(msg),
243+
&verify_res);
241244

242245
if (rc == 0 && verify_res == 1) {
243246
printf("info: verify message good\n");
244247
}
245248
else {
246-
printf("error: wc_MlDsaKey_Verify returned: ret=%d, "
249+
printf("error: wc_MlDsaKey_VerifyCtx returned: ret=%d, "
247250
"res=%d\n", rc, verify_res);
248251
rc = -1;
249252
goto ml_dsa_exit;
@@ -445,5 +448,5 @@ ml_dsa_print_parms_and_die(void)
445448
printf("* from Tables 1 & 2 of FIPS 204:\n");
446449
printf(" https://csrc.nist.gov/pubs/fips/204/final\n");
447450

448-
exit(EXIT_FAILURE);
451+
exit(EXIT_SUCCESS);
449452
}

0 commit comments

Comments
 (0)