From 792bf04d135de350a7deae5cca92522a3c20cc9c Mon Sep 17 00:00:00 2001 From: Douglas Stebila Date: Tue, 30 Jul 2019 21:27:21 -0400 Subject: [PATCH] Add function to check if KEMs enabled --- .../src/kem/kem.c/enabled_case.fragment | 8 + src/kem/kem.c | 224 ++++++++++++++++++ src/kem/kem.h | 8 + 3 files changed, 240 insertions(+) create mode 100644 scripts/copy_from_pqclean/src/kem/kem.c/enabled_case.fragment diff --git a/scripts/copy_from_pqclean/src/kem/kem.c/enabled_case.fragment b/scripts/copy_from_pqclean/src/kem/kem.c/enabled_case.fragment new file mode 100644 index 000000000..da1ff1d88 --- /dev/null +++ b/scripts/copy_from_pqclean/src/kem/kem.c/enabled_case.fragment @@ -0,0 +1,8 @@ +{% for family in instructions['kems'] %}{% for scheme in family['schemes'] %} + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_{{ family['name'] }}_{{ scheme['scheme'] }})) { +#ifdef OQS_ENABLE_KEM_{{ family['name'] }}_{{ scheme['scheme'] }} + return 1; +#else + return 0; +#endif{% endfor %}{% endfor %} + diff --git a/src/kem/kem.c b/src/kem/kem.c index 0fbb381bf..3023a88f8 100644 --- a/src/kem/kem.c +++ b/src/kem/kem.c @@ -33,6 +33,230 @@ OQS_API int OQS_KEM_alg_count() { return OQS_KEM_algs_length; } +OQS_API int OQS_KEM_alg_is_enabled(const char *method_name) { + if (method_name == NULL) { + return 0; + } + if (0 == strcasecmp(method_name, OQS_KEM_alg_default)) { + return OQS_KEM_alg_is_enabled(OQS_KEM_DEFAULT); + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_bike1_l1)) { +#ifdef OQS_ENABLE_KEM_bike1_l1 + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_bike1_l3)) { +#ifdef OQS_ENABLE_KEM_bike1_l3 + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_bike1_l5)) { +#ifdef OQS_ENABLE_KEM_bike1_l5 + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_bike2_l1)) { +#ifdef OQS_ENABLE_KEM_bike2_l1 + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_bike2_l3)) { +#ifdef OQS_ENABLE_KEM_bike2_l3 + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_bike2_l5)) { +#ifdef OQS_ENABLE_KEM_bike2_l5 + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_bike3_l1)) { +#ifdef OQS_ENABLE_KEM_bike3_l1 + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_bike3_l3)) { +#ifdef OQS_ENABLE_KEM_bike3_l3 + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_bike3_l5)) { +#ifdef OQS_ENABLE_KEM_bike3_l5 + return 1; +#else + return 0; +#endif + ///// OQS_COPY_FROM_PQCLEAN_FRAGMENT_ENABLED_CASE_START + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_kyber_512)) { +#ifdef OQS_ENABLE_KEM_kyber_512 + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_kyber_768)) { +#ifdef OQS_ENABLE_KEM_kyber_768 + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_kyber_1024)) { +#ifdef OQS_ENABLE_KEM_kyber_1024 + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_newhope_512cca)) { +#ifdef OQS_ENABLE_KEM_newhope_512cca + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_newhope_1024cca)) { +#ifdef OQS_ENABLE_KEM_newhope_1024cca + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_ntru_hps2048509)) { +#ifdef OQS_ENABLE_KEM_ntru_hps2048509 + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_ntru_hps2048677)) { +#ifdef OQS_ENABLE_KEM_ntru_hps2048677 + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_ntru_hps4096821)) { +#ifdef OQS_ENABLE_KEM_ntru_hps4096821 + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_ntru_hrss701)) { +#ifdef OQS_ENABLE_KEM_ntru_hrss701 + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_saber_lightsaber)) { +#ifdef OQS_ENABLE_KEM_saber_lightsaber + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_saber_saber)) { +#ifdef OQS_ENABLE_KEM_saber_saber + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_saber_firesaber)) { +#ifdef OQS_ENABLE_KEM_saber_firesaber + return 1; +#else + return 0; +#endif + ///// OQS_COPY_FROM_PQCLEAN_FRAGMENT_ENABLED_CASE_END + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_frodokem_640_aes)) { +#ifdef OQS_ENABLE_KEM_frodokem_640_aes + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_frodokem_640_shake)) { +#ifdef OQS_ENABLE_KEM_frodokem_640_shake + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_frodokem_976_aes)) { +#ifdef OQS_ENABLE_KEM_frodokem_976_aes + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_frodokem_976_shake)) { +#ifdef OQS_ENABLE_KEM_frodokem_976_shake + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_frodokem_1344_aes)) { +#ifdef OQS_ENABLE_KEM_frodokem_1344_aes + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_frodokem_1344_shake)) { +#ifdef OQS_ENABLE_KEM_frodokem_1344_shake + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_sidh_p434)) { +#ifdef OQS_ENABLE_KEM_sidh_p434 + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_sidh_p503)) { +#ifdef OQS_ENABLE_KEM_sidh_p503 + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_sidh_p610)) { +#ifdef OQS_ENABLE_KEM_sidh_p610 + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_sidh_p751)) { +#ifdef OQS_ENABLE_KEM_sidh_p751 + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_sike_p434)) { +#ifdef OQS_ENABLE_KEM_sike_p434 + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_sike_p503)) { +#ifdef OQS_ENABLE_KEM_sike_p503 + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_sike_p610)) { +#ifdef OQS_ENABLE_KEM_sike_p610 + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_KEM_alg_sike_p751)) { +#ifdef OQS_ENABLE_KEM_sike_p751 + return 1; +#else + return 0; +#endif + // EDIT-WHEN-ADDING-KEM + } else { + return 0; + } +} + OQS_API OQS_KEM *OQS_KEM_new(const char *method_name) { if (method_name == NULL) { return NULL; diff --git a/src/kem/kem.h b/src/kem/kem.h index 6bd8ba913..79e8037ae 100644 --- a/src/kem/kem.h +++ b/src/kem/kem.h @@ -130,6 +130,14 @@ OQS_API const char *OQS_KEM_alg_identifier(size_t i); */ OQS_API int OQS_KEM_alg_count(); +/** + * Indicates whether the specified algorithm was enabled at compile-time or not. + * + * @param[in] method_name Name of the desired algorithm; one of the names in `OQS_KEM_algs`. + * @return 1 if enabled, 0 if disabled or not found + */ +OQS_API int OQS_KEM_alg_is_enabled(const char *method_name); + /** * Key encapsulation mechanism object */