Skip to content

Commit

Permalink
Remove / from test file names
Browse files Browse the repository at this point in the history
  • Loading branch information
ashman-p committed Sep 14, 2023
1 parent d60a429 commit bdff447
Showing 1 changed file with 71 additions and 13 deletions.
84 changes: 71 additions & 13 deletions tests/test_sig_stfl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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 */
Expand Down

0 comments on commit bdff447

Please sign in to comment.