liboqs/tests/dump_alg_info.c
Marco Gianvecchio 8ee6039c74
Add bitflip test for trivial SUF-CMA forgeries (#2090)
* add bitflip test to test_sig.c
Signed-off-by: rtjk <47841774+rtjk@users.noreply.github.com>

Signed-off-by: rtjk <47841774+rtjk@users.noreply.github.com>

* format code
Signed-off-by: rtjk <47841774+rtjk@users.noreply.github.com>

Signed-off-by: rtjk <47841774+rtjk@users.noreply.github.com>

* - add sig->suf_cma
- add command-line argument to test_sig.c (the number of bitflips)
- update CROSS upstream to SUF-CMA
Signed-off-by: rtjk <47841774+rtjk@users.noreply.github.com>

Signed-off-by: rtjk <47841774+rtjk@users.noreply.github.com>

* %d to %ld for size_t bitflips

Signed-off-by: rtjk <47841774+rtjk@users.noreply.github.com>

* cast argument bitflips to size_t
Signed-off-by: rtjk <47841774+rtjk@users.noreply.github.com>

* replace atoi() with strtol()
Signed-off-by: rtjk <47841774+rtjk@users.noreply.github.com>

* cast bit_index to %llu

Signed-off-by: rtjk <47841774+rtjk@users.noreply.github.com>

* update bitflip tests:
- revert CROSS to EUF-CMA
- add test_bitflip_message
- exclude stateful signatures for now
Signed-off-by: rtjk <47841774+rtjk@users.noreply.github.com>

* remove bitflips_as_str in printf
Signed-off-by: rtjk <47841774+rtjk@users.noreply.github.com>

* test_bitflip as a single function, add support for stateful signatures
Signed-off-by: rtjk <47841774+rtjk@users.noreply.github.com>

* add OQS_TEST_CT_DECLASSIFY after test_bitflip_stfl
Signed-off-by: rtjk <47841774+rtjk@users.noreply.github.com>

* [extended tests]
Signed-off-by: rtjk <47841774+rtjk@users.noreply.github.com>

* more OQS_TEST_CT_DECLASSIFY [extended tests]
Signed-off-by: rtjk <47841774+rtjk@users.noreply.github.com>

* patch dilithium to add suf-cma
Signed-off-by: rtjk <47841774+rtjk@users.noreply.github.com>

* run copy_from_upstream.py
Signed-off-by: rtjk <47841774+rtjk@users.noreply.github.com>

* SUF-CMA in dilithium docs, run copy_from_upstream.py
Signed-off-by: rtjk <47841774+rtjk@users.noreply.github.com>

* correct sizeof in OQS_randombytes call (thank you @SWilson4!)
Signed-off-by: rtjk <47841774+rtjk@users.noreply.github.com>

* factor bitflip testing functions out into test_helpers.c
Signed-off-by: rtjk <47841774+rtjk@users.noreply.github.com>

* --allow-multiple-definition for Windows .dll in test_kem_mem
Signed-off-by: rtjk <47841774+rtjk@users.noreply.github.com>

* --allow-multiple-definition for Windows .dll in test_sig and test_sig_stfl
Signed-off-by: rtjk <47841774+rtjk@users.noreply.github.com>

---------

Signed-off-by: rtjk <47841774+rtjk@users.noreply.github.com>
2025-03-14 11:53:05 -04:00

79 lines
2.5 KiB
C

/*
* dump_alg_info.c
*
* Print algorithm information in YAML format; used in conjunction with test_alg_info.py.
*
* SPDX-License-Identifier: MIT
*/
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <oqs/oqs.h>
int main(void) {
OQS_init();
// iterate through KEMs and print info
printf("KEMs:\n");
for (size_t i = 0; i < OQS_KEM_algs_length; i++) {
const char *kem_name = OQS_KEM_alg_identifier(i);
printf(" %s:\n", kem_name);
OQS_KEM *kem = OQS_KEM_new(kem_name);
if (kem == NULL) {
printf(" isnull: true\n");
continue;
}
printf(" isnull: false\n");
printf(" claimed-nist-level: %d\n", kem->claimed_nist_level);
printf(" claimed-security: %s\n", kem->ind_cca ? "IND-CCA2" : "IND-CPA");
printf(" length-public-key: %zu\n", kem->length_public_key);
printf(" length-ciphertext: %zu\n", kem->length_ciphertext);
printf(" length-secret-key: %zu\n", kem->length_secret_key);
printf(" length-shared-secret: %zu\n", kem->length_shared_secret);
OQS_KEM_free(kem);
}
// iterate through signature schemes and print info
printf("SIGs:\n");
for (size_t i = 0; i < OQS_SIG_algs_length; i++) {
const char *sig_name = OQS_SIG_alg_identifier(i);
printf(" %s:\n", sig_name);
OQS_SIG *sig = OQS_SIG_new(sig_name);
if (sig == NULL) {
printf(" isnull: true\n");
continue;
}
printf(" isnull: false\n");
printf(" claimed-nist-level: %d\n", sig->claimed_nist_level);
printf(" claimed-security: %s\n", sig->suf_cma ? "SUF-CMA" : (sig->euf_cma ? "EUF-CMA" : "none"));
printf(" length-public-key: %zu\n", sig->length_public_key);
printf(" length-secret-key: %zu\n", sig->length_secret_key);
printf(" length-signature: %zu\n", sig->length_signature);
OQS_SIG_free(sig);
}
// iterate through stateful signature schemes and print info
printf("SIG_STFLs:\n");
for (size_t i = 0; i < OQS_SIG_STFL_algs_length; i++) {
const char *sig_name = OQS_SIG_STFL_alg_identifier(i);
printf(" %s:\n", sig_name);
OQS_SIG_STFL *sig = OQS_SIG_STFL_new(sig_name);
if (sig == NULL) {
printf(" isnull: true\n");
continue;
}
printf(" isnull: false\n");
printf(" claimed-security: %s\n", sig->suf_cma ? "SUF-CMA" : (sig->euf_cma ? "EUF-CMA" : "none"));
printf(" length-public-key: %zu\n", sig->length_public_key);
printf(" length-secret-key: %zu\n", sig->length_secret_key);
printf(" length-signature: %zu\n", sig->length_signature);
OQS_SIG_STFL_free(sig);
}
OQS_destroy();
}