diff --git a/tests/test_sig_stfl.c b/tests/test_sig_stfl.c index 6176bb21cb..d8f1baf5b7 100644 --- a/tests/test_sig_stfl.c +++ b/tests/test_sig_stfl.c @@ -38,9 +38,11 @@ */ static OQS_STATUS test_save_secret_key(uint8_t *key_buf, size_t buf_len, void *context) { uint8_t *kb = key_buf; + fprintf(stderr, "\n%s test saved STFL SK <%s>.\n",__FUNCTION__, (const char *)context); + if (key_buf && context && buf_len != 0) { if (oqs_fstore("sk", (const char *)context, kb, buf_len) == OQS_SUCCESS) { - fprintf(stderr, "\nUpdated saved LMS SK <%s>.\n", (const char *)context); + fprintf(stderr, "\nUpdated saved STFL SK <%s>.\n", (const char *)context); return OQS_SUCCESS; } else { return OQS_ERROR; @@ -287,6 +289,7 @@ static OQS_STATUS sig_stfl_test_correctness(const char *method_name, const char uint8_t *sk_buf = NULL; uint8_t *read_pk_buf = NULL; char *context = NULL; + const char *file_store = NULL; size_t sk_buf_len = 0; size_t read_pk_len = 0; @@ -345,19 +348,75 @@ static OQS_STATUS sig_stfl_test_correctness(const char *method_name, const char fprintf(stderr, "ERROR: OQS_SIG_STFL_keypair failed\n"); goto err; } +/* + #define OQS_SIG_STFL_alg_xmssmt_sha256_h20_2 "XMSSMT-SHA2_20/2_256" + #define OQS_SIG_STFL_alg_xmssmt_sha256_h20_4 "XMSSMT-SHA2_20/4_256" +#define OQS_SIG_STFL_alg_xmssmt_sha256_h40_2 "XMSSMT-SHA2_40/2_256" +#define OQS_SIG_STFL_alg_xmssmt_sha256_h40_4 "XMSSMT-SHA2_40/4_256" +#define OQS_SIG_STFL_alg_xmssmt_sha256_h40_8 "XMSSMT-SHA2_40/8_256" +#define OQS_SIG_STFL_alg_xmssmt_sha256_h60_3 "XMSSMT-SHA2_60/3_256" +#define OQS_SIG_STFL_alg_xmssmt_sha256_h60_6 "XMSSMT-SHA2_60/6_256" +#define OQS_SIG_STFL_alg_xmssmt_sha256_h60_12 "XMSSMT-SHA2_60/12_256" +#define OQS_SIG_STFL_alg_xmssmt_shake128_h20_2 "XMSSMT-SHAKE_20/2_256" +#define OQS_SIG_STFL_alg_xmssmt_shake128_h20_4 "XMSSMT-SHAKE_20/4_256" +#define OQS_SIG_STFL_alg_xmssmt_shake128_h40_2 "XMSSMT-SHAKE_40/2_256" +#define OQS_SIG_STFL_alg_xmssmt_shake128_h40_4 "XMSSMT-SHAKE_40/4_256" +#define OQS_SIG_STFL_alg_xmssmt_shake128_h40_8 "XMSSMT-SHAKE_40/8_256" +#define OQS_SIG_STFL_alg_xmssmt_shake128_h60_3 "XMSSMT-SHAKE_60/3_256" + +#define OQS_SIG_STFL_alg_xmssmt_shake128_h60_6 "XMSSMT-SHAKE_60/6_256" +#define OQS_SIG_STFL_alg_xmssmt_shake128_h60_12 "XMSSMT-SHAKE_60/12_256" + */ - /* write key pair to disk */ - rc = OQS_SECRET_KEY_STFL_serialize_key(sk, &sk_buf_len, &sk_buf); - if (oqs_fstore("sk", sig->method_name, sk_buf, sk_buf_len) != OQS_SUCCESS) { - goto err; - } - - if (oqs_fstore("pk", sig->method_name, public_key, sig->length_public_key) != OQS_SUCCESS) { - goto err; - } + rc = OQS_SECRET_KEY_STFL_serialize_key(sk, &sk_buf_len, &sk_buf); + + if (strcmp(sig->method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h20_2) == 0) { + file_store = "XMSSMT-SHA2_20-2_256"; + } else if (strcmp(sig->method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h20_4) == 0) { + file_store = "XMSSMT-SHA2_20-4_256"; + } else if (strcmp(sig->method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h40_2) == 0) { + file_store = "XMSSMT-SHA2_40-2_256"; + } else if (strcmp(sig->method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h40_4) == 0) { + file_store = "XMSSMT-SHA2_40-4_256"; + } else if (strcmp(sig->method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h40_8) == 0) { + file_store = "XMSSMT-SHA2_40-8_256"; + } else if (strcmp(sig->method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h60_3) == 0) { + file_store = "XMSSMT-SHA2_60-3_256"; + } else if (strcmp(sig->method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h60_6) == 0) { + file_store = "XMSSMT-SHA2_60-6_256"; + } else if (strcmp(sig->method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h60_12) == 0) { + file_store = "XMSSMT-SHA2_60-12_256"; + } else if (strcmp(sig->method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h20_2) == 0) { + file_store = "XMSSMT-SHAKE_20-2_256"; + } else if (strcmp(sig->method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h20_4) == 0) { + file_store = "XMSSMT-SHAKE_20-4_256"; + } else if (strcmp(sig->method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h40_2) == 0) { + file_store = "XMSSMT-SHAKE_40-2_256"; + } else if (strcmp(sig->method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h40_4) == 0) { + file_store = "XMSSMT-SHAKE_40-4_256"; + } else if (strcmp(sig->method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h40_8) == 0) { + file_store = "XMSSMT-SHAKE_40-8_256"; + } else if (strcmp(sig->method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h60_3) == 0) { + file_store = "XMSSMT-SHAKE_60-3_256"; + } else if (strcmp(sig->method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h60_6) == 0) { + file_store = "XMSSMT-SHAKE_60-6_256"; + } else if (strcmp(sig->method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h60_12) == 0) { + file_store = "XMSSMT-SHAKE_60-12_256"; + } else { + file_store = sig->method_name; + } + + /* write key pair to disk */ + if (oqs_fstore("sk", file_store, sk_buf, sk_buf_len) != OQS_SUCCESS) { + goto err; + } + + if (oqs_fstore("pk", file_store, public_key, sig->length_public_key) != OQS_SUCCESS) { + goto err; + } /* set context and secure store callback */ - context = strdup(((sig->method_name))); + context = strdup(((file_store))); OQS_SIG_STFL_SECRET_KEY_SET_store_cb(secret_key, test_save_secret_key, (void *)context); rc = OQS_SIG_STFL_sign(sig, signature, &signature_len, message, message_len, secret_key); @@ -378,14 +437,13 @@ static OQS_STATUS sig_stfl_test_correctness(const char *method_name, const char /* Read public key and re-test verify.*/ read_pk_buf = malloc(sig->length_public_key); - if (oqs_fload("pk", sig->method_name, read_pk_buf, sig->length_public_key, &read_pk_len) != OQS_SUCCESS) { + if (oqs_fload("pk", file_store, read_pk_buf, sig->length_public_key, &read_pk_len) != OQS_SUCCESS) { goto err; } rc = OQS_SIG_STFL_verify(sig, message, message_len, signature, signature_len, read_pk_buf); OQS_TEST_CT_DECLASSIFY(&rc, sizeof rc); if (rc != OQS_SUCCESS) { fprintf(stderr, "ERROR: 2nd Verify with restored public key OQS_SIG_STFL_verify failed\n"); - goto err; } /* modify the signature to invalidate it */