From d278b06a1b9b92bd2c2ba7799c2163f5c29d7350 Mon Sep 17 00:00:00 2001 From: Norman Ashley Date: Fri, 1 Dec 2023 06:35:28 +0000 Subject: [PATCH] 2-level LMS Support --- src/sig_stfl/lms/sig_stfl_lms.c | 869 ++++++++++++++++++++++ src/sig_stfl/lms/sig_stfl_lms.h | 70 ++ src/sig_stfl/lms/sig_stfl_lms_functions.c | 72 +- src/sig_stfl/sig_stfl.c | 81 ++ src/sig_stfl/sig_stfl.h | 17 +- 5 files changed, 1107 insertions(+), 2 deletions(-) diff --git a/src/sig_stfl/lms/sig_stfl_lms.c b/src/sig_stfl/lms/sig_stfl_lms.c index b6d57902ee..4013c7a473 100644 --- a/src/sig_stfl/lms/sig_stfl_lms.c +++ b/src/sig_stfl/lms/sig_stfl_lms.c @@ -1755,6 +1755,875 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_LMS_SHA256_H25_W8_new(void) { return sk; } +// +//2-Level LMS +// ======================== LMS-SHA256 H5/W8, H5/W8 ======================== // + +OQS_API OQS_STATUS OQS_SIG_STFL_alg_lms_sha256_h5_w8_h5_w8_keypair(uint8_t *public_key, OQS_SIG_STFL_SECRET_KEY *secret_key) { + if (secret_key == NULL || public_key == NULL) { + return OQS_ERROR; + } + + if (oqs_sig_stfl_lms_keypair(public_key, secret_key, (const uint32_t)OQS_LMS_ID_sha256_n32_h5_w8_h5_w8) != 0) { + return OQS_ERROR; + } + return OQS_SUCCESS; +} + +OQS_SIG_STFL *OQS_SIG_STFL_alg_lms_sha256_h5_w8_h5_w8_new(void) { + + OQS_SIG_STFL *sig = (OQS_SIG_STFL *)malloc(sizeof(OQS_SIG_STFL)); + if (sig == NULL) { + return NULL; + } + memset(sig, 0, sizeof(OQS_SIG_STFL)); + + sig->oid = OQS_LMS_ID_sha256_n32_h5_w8_h5_w8; + sig->method_name = OQS_SIG_STFL_alg_lms_sha256_n32_h5_w8_h5_w8; + sig->alg_version = "https://datatracker.ietf.org/doc/html/rfc8554"; + sig->euf_cma = true; + + sig->length_public_key = OQS_SIG_STFL_alg_lms_length_public_key; + sig->length_signature = OQS_SIG_STFL_alg_lms_sha256_h5_w8_h5_w8_length_signature; + sig->length_secret_key = OQS_SIG_STFL_alg_lms_length_private_key; + + sig->keypair = OQS_SIG_STFL_alg_lms_sha256_h5_w8_h5_w8_keypair; + sig->sign = OQS_SIG_STFL_alg_lms_sign; + sig->verify = OQS_SIG_STFL_alg_lms_verify; + + sig->sigs_remaining = OQS_SIG_STFL_lms_sigs_left; + sig->sigs_total = OQS_SIG_STFL_lms_sigs_total; + + return sig; +} + +OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_LMS_SHA256_H5_W8_H5_W8_new(void) { + + // Initialize the secret key in the heap with adequate memory + OQS_SIG_STFL_SECRET_KEY *sk = malloc(sizeof(OQS_SIG_STFL_SECRET_KEY)); + if (sk == NULL) { + return NULL; + } + memset(sk, 0, sizeof(OQS_SIG_STFL_SECRET_KEY)); + + // Initialize the key with length_secret_key amount of bytes. + sk->length_secret_key = OQS_SIG_STFL_alg_lms_length_private_key; + + /* + * Secret Key retrieval Function + */ + sk->serialize_key = OQS_SECRET_KEY_LMS_serialize_key; + + /* + * set Secret Key to internal structure Function + */ + sk->deserialize_key = OQS_SECRET_KEY_LMS_deserialize_key; + + /* + * Set Secret Key Locking Function + */ + sk->lock_key = NULL; + + /* + * Set Secret Key Saving Function + */ + sk->secure_store_scrt_key = NULL; + + /* + * Set Secret Key free function + */ + sk->free_key = OQS_SECRET_KEY_LMS_free; + + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_LMS_set_store_cb; + + return sk; +} + +// ======================== LMS-SHA256 H10/W8, H5/W8 ======================== // + +OQS_API OQS_STATUS OQS_SIG_STFL_alg_lms_sha256_h10_w8_h5_w8_keypair(uint8_t *public_key, OQS_SIG_STFL_SECRET_KEY *secret_key) { + if (secret_key == NULL || public_key == NULL) { + return OQS_ERROR; + } + + if (oqs_sig_stfl_lms_keypair(public_key, secret_key, (const uint32_t)OQS_LMS_ID_sha256_n32_h10_w8_h5_w8) != 0) { + return OQS_ERROR; + } + return OQS_SUCCESS; +} + +OQS_SIG_STFL *OQS_SIG_STFL_alg_lms_sha256_h10_w8_h5_w8_new(void) { + + OQS_SIG_STFL *sig = (OQS_SIG_STFL *)malloc(sizeof(OQS_SIG_STFL)); + if (sig == NULL) { + return NULL; + } + memset(sig, 0, sizeof(OQS_SIG_STFL)); + + sig->oid = OQS_LMS_ID_sha256_n32_h10_w8_h5_w8; + sig->method_name = OQS_SIG_STFL_alg_lms_sha256_n32_h10_w8_h5_w8; + sig->alg_version = "https://datatracker.ietf.org/doc/html/rfc8554"; + sig->euf_cma = true; + + sig->length_public_key = OQS_SIG_STFL_alg_lms_length_public_key; + sig->length_signature = OQS_SIG_STFL_alg_lms_sha256_h10_w8_h5_w8_length_signature; + sig->length_secret_key = OQS_SIG_STFL_alg_lms_length_private_key; + + sig->keypair = OQS_SIG_STFL_alg_lms_sha256_h10_w8_h5_w8_keypair; + sig->sign = OQS_SIG_STFL_alg_lms_sign; + sig->verify = OQS_SIG_STFL_alg_lms_verify; + + sig->sigs_remaining = OQS_SIG_STFL_lms_sigs_left; + sig->sigs_total = OQS_SIG_STFL_lms_sigs_total; + + return sig; +} + +OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_LMS_SHA256_H10_W8_H5_W8_new(void) { + + // Initialize the secret key in the heap with adequate memory + OQS_SIG_STFL_SECRET_KEY *sk = malloc(sizeof(OQS_SIG_STFL_SECRET_KEY)); + if (sk == NULL) { + return NULL; + } + memset(sk, 0, sizeof(OQS_SIG_STFL_SECRET_KEY)); + + // Initialize the key with length_secret_key amount of bytes. + sk->length_secret_key = OQS_SIG_STFL_alg_lms_length_private_key; + + /* + * Secret Key retrieval Function + */ + sk->serialize_key = OQS_SECRET_KEY_LMS_serialize_key; + + /* + * set Secret Key to internal structure Function + */ + sk->deserialize_key = OQS_SECRET_KEY_LMS_deserialize_key; + + /* + * Set Secret Key Locking Function + */ + sk->lock_key = NULL; + + /* + * Set Secret Key Unlocking / Releasing Function + */ + sk->unlock_key = NULL; + + /* + * Set Secret Key Saving Function + */ + sk->secure_store_scrt_key = NULL; + + /* + * Set Secret Key free function + */ + sk->free_key = OQS_SECRET_KEY_LMS_free; + + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_LMS_set_store_cb; + + return sk; +} + +// ======================== LMS-SHA256 H10/W8, H10/W8 ======================== // + +OQS_API OQS_STATUS OQS_SIG_STFL_alg_lms_sha256_h10_w8_h10_w8_keypair(uint8_t *public_key, OQS_SIG_STFL_SECRET_KEY *secret_key) { + if (secret_key == NULL || public_key == NULL) { + return OQS_ERROR; + } + + if (oqs_sig_stfl_lms_keypair(public_key, secret_key, (const uint32_t)OQS_LMS_ID_sha256_n32_h10_w8_h10_w8) != 0) { + return OQS_ERROR; + } + return OQS_SUCCESS; +} + +OQS_SIG_STFL *OQS_SIG_STFL_alg_lms_sha256_h10_w8_h10_w8_new(void) { + + OQS_SIG_STFL *sig = (OQS_SIG_STFL *)malloc(sizeof(OQS_SIG_STFL)); + if (sig == NULL) { + return NULL; + } + memset(sig, 0, sizeof(OQS_SIG_STFL)); + + sig->oid = OQS_LMS_ID_sha256_n32_h15_w4; + sig->method_name = OQS_SIG_STFL_alg_lms_sha256_n32_h10_w8_h10_w8; + sig->alg_version = "https://datatracker.ietf.org/doc/html/rfc8554"; + sig->euf_cma = true; + + sig->length_public_key = OQS_SIG_STFL_alg_lms_length_public_key; + sig->length_signature = OQS_SIG_STFL_alg_lms_sha256_h10_w8_h10_w8_length_signature; + sig->length_secret_key = OQS_SIG_STFL_alg_lms_length_private_key; + + sig->keypair = OQS_SIG_STFL_alg_lms_sha256_h10_w8_h10_w8_keypair; + sig->sign = OQS_SIG_STFL_alg_lms_sign; + sig->verify = OQS_SIG_STFL_alg_lms_verify; + + sig->sigs_remaining = OQS_SIG_STFL_lms_sigs_left; + sig->sigs_total = OQS_SIG_STFL_lms_sigs_total; + + return sig; +} + +OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_LMS_SHA256_H10_W8_H10_W8_new(void) { + + // Initialize the secret key in the heap with adequate memory + OQS_SIG_STFL_SECRET_KEY *sk = malloc(sizeof(OQS_SIG_STFL_SECRET_KEY)); + if (sk == NULL) { + return NULL; + } + memset(sk, 0, sizeof(OQS_SIG_STFL_SECRET_KEY)); + + // Initialize the key with length_secret_key amount of bytes. + sk->length_secret_key = OQS_SIG_STFL_alg_lms_length_private_key; + + /* + * Secret Key retrieval Function + */ + sk->serialize_key = OQS_SECRET_KEY_LMS_serialize_key; + + /* + * set Secret Key to internal structure Function + */ + sk->deserialize_key = OQS_SECRET_KEY_LMS_deserialize_key; + + /* + * Set Secret Key Locking Function + */ + sk->lock_key = NULL; + + /* + * Set Secret Key Unlocking / Releasing Function + */ + sk->unlock_key = NULL; + + /* + * Set Secret Key Saving Function + */ + sk->secure_store_scrt_key = NULL; + + /* + * Set Secret Key free function + */ + sk->free_key = OQS_SECRET_KEY_LMS_free; + + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_LMS_set_store_cb; + + return sk; +} + +// ======================== LMS-SHA256 H15/W8, H5/W8 ======================== // + +OQS_API OQS_STATUS OQS_SIG_STFL_alg_lms_sha256_h15_w8_h5_w8_keypair(uint8_t *public_key, OQS_SIG_STFL_SECRET_KEY *secret_key) { + if (secret_key == NULL || public_key == NULL) { + return OQS_ERROR; + } + + if (oqs_sig_stfl_lms_keypair(public_key, secret_key, (const uint32_t)OQS_LMS_ID_sha256_n32_h15_w8_h5_w8) != 0) { + return OQS_ERROR; + } + return OQS_SUCCESS; +} + +OQS_SIG_STFL *OQS_SIG_STFL_alg_lms_sha256_h15_w8_h5_w8_new(void) { + + OQS_SIG_STFL *sig = (OQS_SIG_STFL *)malloc(sizeof(OQS_SIG_STFL)); + if (sig == NULL) { + return NULL; + } + memset(sig, 0, sizeof(OQS_SIG_STFL)); + + sig->oid = OQS_LMS_ID_sha256_n32_h15_w8_h5_w8; + sig->method_name = OQS_SIG_STFL_alg_lms_sha256_n32_h15_w8_h5_w8; + sig->alg_version = "https://datatracker.ietf.org/doc/html/rfc8554"; + sig->euf_cma = true; + + sig->length_public_key = OQS_SIG_STFL_alg_lms_length_public_key; + sig->length_signature = OQS_SIG_STFL_alg_lms_sha256_h15_w8_h5_w8_length_signature; + sig->length_secret_key = OQS_SIG_STFL_alg_lms_length_private_key; + + sig->keypair = OQS_SIG_STFL_alg_lms_sha256_h15_w8_h5_w8_keypair; + sig->sign = OQS_SIG_STFL_alg_lms_sign; + sig->verify = OQS_SIG_STFL_alg_lms_verify; + + sig->sigs_remaining = OQS_SIG_STFL_lms_sigs_left; + sig->sigs_total = OQS_SIG_STFL_lms_sigs_total; + + return sig; +} + +OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_LMS_SHA256_H15_W8_H5_W8_new(void) { + + // Initialize the secret key in the heap with adequate memory + OQS_SIG_STFL_SECRET_KEY *sk = malloc(sizeof(OQS_SIG_STFL_SECRET_KEY)); + if (sk == NULL) { + return NULL; + } + memset(sk, 0, sizeof(OQS_SIG_STFL_SECRET_KEY)); + + // Initialize the key with length_secret_key amount of bytes. + sk->length_secret_key = OQS_SIG_STFL_alg_lms_length_private_key; + + /* + * Secret Key retrieval Function + */ + sk->serialize_key = OQS_SECRET_KEY_LMS_serialize_key; + + /* + * set Secret Key to internal structure Function + */ + sk->deserialize_key = OQS_SECRET_KEY_LMS_deserialize_key; + + /* + * Set Secret Key Locking Function + */ + sk->lock_key = NULL; + + /* + * Set Secret Key Unlocking / Releasing Function + */ + sk->unlock_key = NULL; + + /* + * Set Secret Key Saving Function + */ + sk->secure_store_scrt_key = NULL; + + /* + * Set Secret Key free function + */ + sk->free_key = OQS_SECRET_KEY_LMS_free; + + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_LMS_set_store_cb; + + return sk; +} + +// ======================== LMS-SHA256 H15/W8, H10/W8 ======================== // + +OQS_API OQS_STATUS OQS_SIG_STFL_alg_lms_sha256_h15_w8_h10_w8_keypair(uint8_t *public_key, OQS_SIG_STFL_SECRET_KEY *secret_key) { + if (secret_key == NULL || public_key == NULL) { + return OQS_ERROR; + } + + if (oqs_sig_stfl_lms_keypair(public_key, secret_key, (const uint32_t)OQS_LMS_ID_sha256_n32_h15_w8_h10_w8) != 0) { + return OQS_ERROR; + } + return OQS_SUCCESS; +} + +OQS_SIG_STFL *OQS_SIG_STFL_alg_lms_sha256_h15_w8_h10_w8_new(void) { + + OQS_SIG_STFL *sig = (OQS_SIG_STFL *)malloc(sizeof(OQS_SIG_STFL)); + if (sig == NULL) { + return NULL; + } + memset(sig, 0, sizeof(OQS_SIG_STFL)); + + sig->oid = OQS_LMS_ID_sha256_n32_h15_w8_h10_w8; + sig->method_name = OQS_SIG_STFL_alg_lms_sha256_n32_h15_w8_h10_w8; + sig->alg_version = "https://datatracker.ietf.org/doc/html/rfc8554"; + sig->euf_cma = true; + + sig->length_public_key = OQS_SIG_STFL_alg_lms_length_public_key; + sig->length_signature = OQS_SIG_STFL_alg_lms_sha256_h15_w8_h10_w8_length_signature; + sig->length_secret_key = OQS_SIG_STFL_alg_lms_length_private_key; + + sig->keypair = OQS_SIG_STFL_alg_lms_sha256_h15_w8_h10_w8_keypair; + sig->sign = OQS_SIG_STFL_alg_lms_sign; + sig->verify = OQS_SIG_STFL_alg_lms_verify; + + sig->sigs_remaining = OQS_SIG_STFL_lms_sigs_left; + sig->sigs_total = OQS_SIG_STFL_lms_sigs_total; + + return sig; +} + +OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_LMS_SHA256_H15_W8_H10_W8_new(void) { + + // Initialize the secret key in the heap with adequate memory + OQS_SIG_STFL_SECRET_KEY *sk = malloc(sizeof(OQS_SIG_STFL_SECRET_KEY)); + if (sk == NULL) { + return NULL; + } + memset(sk, 0, sizeof(OQS_SIG_STFL_SECRET_KEY)); + + // Initialize the key with length_secret_key amount of bytes. + sk->length_secret_key = OQS_SIG_STFL_alg_lms_length_private_key; + + /* + * Secret Key retrieval Function + */ + sk->serialize_key = OQS_SECRET_KEY_LMS_serialize_key; + + /* + * set Secret Key to internal structure Function + */ + sk->deserialize_key = OQS_SECRET_KEY_LMS_deserialize_key; + + /* + * Set Secret Key Locking Function + */ + sk->lock_key = NULL; + + /* + * Set Secret Key Unlocking / Releasing Function + */ + sk->unlock_key = NULL; + + /* + * Set Secret Key Saving Function + */ + sk->secure_store_scrt_key = NULL; + + /* + * Set Secret Key free function + */ + sk->free_key = OQS_SECRET_KEY_LMS_free; + + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_LMS_set_store_cb; + + return sk; +} + +// ======================== LMS-SHA256 H15/W8, H15/W8 ======================== // + +OQS_API OQS_STATUS OQS_SIG_STFL_alg_lms_sha256_h15_w8_h15_w8_keypair(uint8_t *public_key, OQS_SIG_STFL_SECRET_KEY *secret_key) { + if (secret_key == NULL || public_key == NULL) { + return OQS_ERROR; + } + + if (oqs_sig_stfl_lms_keypair(public_key, secret_key, (const uint32_t)OQS_LMS_ID_sha256_n32_h15_w8_h15_w8) != 0) { + return OQS_ERROR; + } + return OQS_SUCCESS; +} + +OQS_SIG_STFL *OQS_SIG_STFL_alg_lms_sha256_h15_w8_h15_w8_new(void) { + + OQS_SIG_STFL *sig = (OQS_SIG_STFL *)malloc(sizeof(OQS_SIG_STFL)); + if (sig == NULL) { + return NULL; + } + memset(sig, 0, sizeof(OQS_SIG_STFL)); + + sig->oid = OQS_LMS_ID_sha256_n32_h15_w8_h15_w8; + sig->method_name = OQS_SIG_STFL_alg_lms_sha256_n32_h15_w8_h15_w8; + sig->alg_version = "https://datatracker.ietf.org/doc/html/rfc8554"; + sig->euf_cma = true; + + sig->length_public_key = OQS_SIG_STFL_alg_lms_length_public_key; + sig->length_signature = OQS_SIG_STFL_alg_lms_sha256_h15_w8_h15_w8_length_signature; + sig->length_secret_key = OQS_SIG_STFL_alg_lms_length_private_key; + + sig->keypair = OQS_SIG_STFL_alg_lms_sha256_h15_w8_h15_w8_keypair; + sig->sign = OQS_SIG_STFL_alg_lms_sign; + sig->verify = OQS_SIG_STFL_alg_lms_verify; + + sig->sigs_remaining = OQS_SIG_STFL_lms_sigs_left; + sig->sigs_total = OQS_SIG_STFL_lms_sigs_total; + + return sig; +} + +OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_LMS_SHA256_H15_W8_H15_W8_new(void) { + + // Initialize the secret key in the heap with adequate memory + OQS_SIG_STFL_SECRET_KEY *sk = malloc(sizeof(OQS_SIG_STFL_SECRET_KEY)); + if (sk == NULL) { + return NULL; + } + memset(sk, 0, sizeof(OQS_SIG_STFL_SECRET_KEY)); + + // Initialize the key with length_secret_key amount of bytes. + sk->length_secret_key = OQS_SIG_STFL_alg_lms_length_private_key; + + /* + * Secret Key retrieval Function + */ + sk->serialize_key = OQS_SECRET_KEY_LMS_serialize_key; + + /* + * set Secret Key to internal structure Function + */ + sk->deserialize_key = OQS_SECRET_KEY_LMS_deserialize_key; + + /* + * Set Secret Key Locking Function + */ + sk->lock_key = NULL; + + /* + * Set Secret Key Unlocking / Releasing Function + */ + sk->unlock_key = NULL; + + /* + * Set Secret Key Saving Function + */ + sk->secure_store_scrt_key = NULL; + + /* + * Set Secret Key free function + */ + sk->free_key = OQS_SECRET_KEY_LMS_free; + + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_LMS_set_store_cb; + + return sk; +} + +// ======================== LMS-SHA256 H20/W8, H5/W8 ======================== // + +OQS_API OQS_STATUS OQS_SIG_STFL_alg_lms_sha256_h20_w8_h5_w8_keypair(uint8_t *public_key, OQS_SIG_STFL_SECRET_KEY *secret_key) { + if (secret_key == NULL || public_key == NULL) { + return OQS_ERROR; + } + + if (oqs_sig_stfl_lms_keypair(public_key, secret_key, (const uint32_t)OQS_LMS_ID_sha256_n32_h20_w8_h5_w8) != 0) { + return OQS_ERROR; + } + return OQS_SUCCESS; +} + +OQS_SIG_STFL *OQS_SIG_STFL_alg_lms_sha256_h20_w8_h5_w8_new(void) { + + OQS_SIG_STFL *sig = (OQS_SIG_STFL *)malloc(sizeof(OQS_SIG_STFL)); + if (sig == NULL) { + return NULL; + } + memset(sig, 0, sizeof(OQS_SIG_STFL)); + + sig->oid = OQS_LMS_ID_sha256_n32_h20_w8_h5_w8; + sig->method_name = OQS_SIG_STFL_alg_lms_sha256_n32_h20_w8_h5_w8; + sig->alg_version = "https://datatracker.ietf.org/doc/html/rfc8554"; + sig->euf_cma = true; + + sig->length_public_key = OQS_SIG_STFL_alg_lms_length_public_key; + sig->length_signature = OQS_SIG_STFL_alg_lms_sha256_h20_w8_h5_w8_length_signature; + sig->length_secret_key = OQS_SIG_STFL_alg_lms_length_private_key; + + sig->keypair = OQS_SIG_STFL_alg_lms_sha256_h20_w8_h5_w8_keypair; + sig->sign = OQS_SIG_STFL_alg_lms_sign; + sig->verify = OQS_SIG_STFL_alg_lms_verify; + + sig->sigs_remaining = OQS_SIG_STFL_lms_sigs_left; + sig->sigs_total = OQS_SIG_STFL_lms_sigs_total; + + return sig; +} + +OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_LMS_SHA256_H20_W8_H5_W8_new(void) { + + // Initialize the secret key in the heap with adequate memory + OQS_SIG_STFL_SECRET_KEY *sk = malloc(sizeof(OQS_SIG_STFL_SECRET_KEY)); + if (sk == NULL) { + return NULL; + } + memset(sk, 0, sizeof(OQS_SIG_STFL_SECRET_KEY)); + + // Initialize the key with length_secret_key amount of bytes. + sk->length_secret_key = OQS_SIG_STFL_alg_lms_length_private_key; + + /* + * Secret Key retrieval Function + */ + sk->serialize_key = OQS_SECRET_KEY_LMS_serialize_key; + + /* + * set Secret Key to internal structure Function + */ + sk->deserialize_key = OQS_SECRET_KEY_LMS_deserialize_key; + + /* + * Set Secret Key Locking Function + */ + sk->lock_key = NULL; + + /* + * Set Secret Key Unlocking / Releasing Function + */ + sk->unlock_key = NULL; + + /* + * Set Secret Key Saving Function + */ + sk->secure_store_scrt_key = NULL; + + /* + * Set Secret Key free function + */ + sk->free_key = OQS_SECRET_KEY_LMS_free; + + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_LMS_set_store_cb; + + return sk; +} + +// ======================== LMS-SHA256 H20/W8, H10/W8 ======================== // + +OQS_API OQS_STATUS OQS_SIG_STFL_alg_lms_sha256_h20_w8_h10_w8_keypair(uint8_t *public_key, OQS_SIG_STFL_SECRET_KEY *secret_key) { + if (secret_key == NULL || public_key == NULL) { + return OQS_ERROR; + } + + if (oqs_sig_stfl_lms_keypair(public_key, secret_key, (const uint32_t)OQS_LMS_ID_sha256_n32_h20_w8_h10_w8) != 0) { + return OQS_ERROR; + } + return OQS_SUCCESS; +} + +OQS_SIG_STFL *OQS_SIG_STFL_alg_lms_sha256_h20_w8_h10_w8_new(void) { + + OQS_SIG_STFL *sig = (OQS_SIG_STFL *)malloc(sizeof(OQS_SIG_STFL)); + if (sig == NULL) { + return NULL; + } + memset(sig, 0, sizeof(OQS_SIG_STFL)); + + sig->oid = OQS_LMS_ID_sha256_n32_h20_w8_h10_w8; + sig->method_name = OQS_SIG_STFL_alg_lms_sha256_n32_h20_w8_h10_w8; + sig->alg_version = "https://datatracker.ietf.org/doc/html/rfc8554"; + sig->euf_cma = true; + + sig->length_public_key = OQS_SIG_STFL_alg_lms_length_public_key; + sig->length_signature = OQS_SIG_STFL_alg_lms_sha256_h20_w8_h10_w8_length_signature; + sig->length_secret_key = OQS_SIG_STFL_alg_lms_length_private_key; + + sig->keypair = OQS_SIG_STFL_alg_lms_sha256_h20_w8_h10_w8_keypair; + sig->sign = OQS_SIG_STFL_alg_lms_sign; + sig->verify = OQS_SIG_STFL_alg_lms_verify; + + sig->sigs_remaining = OQS_SIG_STFL_lms_sigs_left; + sig->sigs_total = OQS_SIG_STFL_lms_sigs_total; + + return sig; +} + +OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_LMS_SHA256_H20_W8_H10_W8_new(void) { + + // Initialize the secret key in the heap with adequate memory + OQS_SIG_STFL_SECRET_KEY *sk = malloc(sizeof(OQS_SIG_STFL_SECRET_KEY)); + if (sk == NULL) { + return NULL; + } + memset(sk, 0, sizeof(OQS_SIG_STFL_SECRET_KEY)); + + // Initialize the key with length_secret_key amount of bytes. + sk->length_secret_key = OQS_SIG_STFL_alg_lms_length_private_key; + + /* + * Secret Key retrieval Function + */ + sk->serialize_key = OQS_SECRET_KEY_LMS_serialize_key; + + /* + * set Secret Key to internal structure Function + */ + sk->deserialize_key = OQS_SECRET_KEY_LMS_deserialize_key; + + /* + * Set Secret Key Locking Function + */ + sk->lock_key = NULL; + + /* + * Set Secret Key Unlocking / Releasing Function + */ + sk->unlock_key = NULL; + + /* + * Set Secret Key Saving Function + */ + sk->secure_store_scrt_key = NULL; + + /* + * Set Secret Key free function + */ + sk->free_key = OQS_SECRET_KEY_LMS_free; + + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_LMS_set_store_cb; + + return sk; +} + +// ======================== LMS-SHA256 H20/W8, H15/W8 ======================== // + +OQS_API OQS_STATUS OQS_SIG_STFL_alg_lms_sha256_h20_w8_h15_w8_keypair(uint8_t *public_key, OQS_SIG_STFL_SECRET_KEY *secret_key) { + if (secret_key == NULL || public_key == NULL) { + return OQS_ERROR; + } + + if (oqs_sig_stfl_lms_keypair(public_key, secret_key, (const uint32_t)OQS_LMS_ID_sha256_n32_h20_w8_h15_w8) != 0) { + return OQS_ERROR; + } + return OQS_SUCCESS; +} + +OQS_SIG_STFL *OQS_SIG_STFL_alg_lms_sha256_h20_w8_h15_w8_new(void) { + + OQS_SIG_STFL *sig = (OQS_SIG_STFL *)malloc(sizeof(OQS_SIG_STFL)); + if (sig == NULL) { + return NULL; + } + memset(sig, 0, sizeof(OQS_SIG_STFL)); + + sig->oid = OQS_LMS_ID_sha256_n32_h20_w8_h15_w8; + sig->method_name = OQS_SIG_STFL_alg_lms_sha256_n32_h20_w8_h15_w8; + sig->alg_version = "https://datatracker.ietf.org/doc/html/rfc8554"; + sig->euf_cma = true; + + sig->length_public_key = OQS_SIG_STFL_alg_lms_length_public_key; + sig->length_signature = OQS_SIG_STFL_alg_lms_sha256_h20_w8_h15_w8_length_signature; + sig->length_secret_key = OQS_SIG_STFL_alg_lms_length_private_key; + + sig->keypair = OQS_SIG_STFL_alg_lms_sha256_h20_w8_h15_w8_keypair; + sig->sign = OQS_SIG_STFL_alg_lms_sign; + sig->verify = OQS_SIG_STFL_alg_lms_verify; + + sig->sigs_remaining = OQS_SIG_STFL_lms_sigs_left; + sig->sigs_total = OQS_SIG_STFL_lms_sigs_total; + + return sig; +} + +OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_LMS_SHA256_H20_W8_H15_W8_new(void) { + + // Initialize the secret key in the heap with adequate memory + OQS_SIG_STFL_SECRET_KEY *sk = malloc(sizeof(OQS_SIG_STFL_SECRET_KEY)); + if (sk == NULL) { + return NULL; + } + memset(sk, 0, sizeof(OQS_SIG_STFL_SECRET_KEY)); + + // Initialize the key with length_secret_key amount of bytes. + sk->length_secret_key = OQS_SIG_STFL_alg_lms_length_private_key; + + /* + * Secret Key retrieval Function + */ + sk->serialize_key = OQS_SECRET_KEY_LMS_serialize_key; + + /* + * set Secret Key to internal structure Function + */ + sk->deserialize_key = OQS_SECRET_KEY_LMS_deserialize_key; + + /* + * Set Secret Key Locking Function + */ + sk->lock_key = NULL; + + /* + * Set Secret Key Unlocking / Releasing Function + */ + sk->unlock_key = NULL; + + /* + * Set Secret Key Saving Function + */ + sk->secure_store_scrt_key = NULL; + + /* + * Set Secret Key free function + */ + sk->free_key = OQS_SECRET_KEY_LMS_free; + + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_LMS_set_store_cb; + + return sk; +} + +// ======================== LMS-SHA256 H20/W8, H20/W8 ======================== // + +OQS_API OQS_STATUS OQS_SIG_STFL_alg_lms_sha256_h20_w8_h20_w8_keypair(uint8_t *public_key, OQS_SIG_STFL_SECRET_KEY *secret_key) { + if (secret_key == NULL || public_key == NULL) { + return OQS_ERROR; + } + + if (oqs_sig_stfl_lms_keypair(public_key, secret_key, (const uint32_t)OQS_LMS_ID_sha256_n32_h20_w8_h20_w8) != 0) { + return OQS_ERROR; + } + return OQS_SUCCESS; +} + +OQS_SIG_STFL *OQS_SIG_STFL_alg_lms_sha256_h20_w8_h20_w8_new(void) { + + OQS_SIG_STFL *sig = (OQS_SIG_STFL *)malloc(sizeof(OQS_SIG_STFL)); + if (sig == NULL) { + return NULL; + } + memset(sig, 0, sizeof(OQS_SIG_STFL)); + + sig->oid = OQS_LMS_ID_sha256_n32_h20_w8_h20_w8; + sig->method_name = OQS_SIG_STFL_alg_lms_sha256_n32_h20_w8_h20_w8; + sig->alg_version = "https://datatracker.ietf.org/doc/html/rfc8554"; + sig->euf_cma = true; + + sig->length_public_key = OQS_SIG_STFL_alg_lms_length_public_key; + sig->length_signature = OQS_SIG_STFL_alg_lms_sha256_h20_w8_h20_w8_length_signature; + sig->length_secret_key = OQS_SIG_STFL_alg_lms_length_private_key; + + sig->keypair = OQS_SIG_STFL_alg_lms_sha256_h20_w8_h20_w8_keypair; + sig->sign = OQS_SIG_STFL_alg_lms_sign; + sig->verify = OQS_SIG_STFL_alg_lms_verify; + + sig->sigs_remaining = OQS_SIG_STFL_lms_sigs_left; + sig->sigs_total = OQS_SIG_STFL_lms_sigs_total; + + return sig; +} + +OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_LMS_SHA256_H20_W8_H20_W8_new(void) { + + // Initialize the secret key in the heap with adequate memory + OQS_SIG_STFL_SECRET_KEY *sk = malloc(sizeof(OQS_SIG_STFL_SECRET_KEY)); + if (sk == NULL) { + return NULL; + } + memset(sk, 0, sizeof(OQS_SIG_STFL_SECRET_KEY)); + + // Initialize the key with length_secret_key amount of bytes. + sk->length_secret_key = OQS_SIG_STFL_alg_lms_length_private_key; + + /* + * Secret Key retrieval Function + */ + sk->serialize_key = OQS_SECRET_KEY_LMS_serialize_key; + + /* + * set Secret Key to internal structure Function + */ + sk->deserialize_key = OQS_SECRET_KEY_LMS_deserialize_key; + + /* + * Set Secret Key Locking Function + */ + sk->lock_key = NULL; + + /* + * Set Secret Key Unlocking / Releasing Function + */ + sk->unlock_key = NULL; + + /* + * Set Secret Key Saving Function + */ + sk->secure_store_scrt_key = NULL; + + /* + * Set Secret Key free function + */ + sk->free_key = OQS_SECRET_KEY_LMS_free; + + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_LMS_set_store_cb; + + return sk; +} +//2-Level LMS + + void OQS_SECRET_KEY_LMS_free(OQS_SIG_STFL_SECRET_KEY *sk) { oqs_secret_lms_key_free(sk); } diff --git a/src/sig_stfl/lms/sig_stfl_lms.h b/src/sig_stfl/lms/sig_stfl_lms.h index b75446d2e3..fcd146c9f2 100644 --- a/src/sig_stfl/lms/sig_stfl_lms.h +++ b/src/sig_stfl/lms/sig_stfl_lms.h @@ -32,6 +32,18 @@ #define OQS_LMS_ID_sha256_n32_h25_w4 0x14 //"25/4" #define OQS_LMS_ID_sha256_n32_h25_w8 0x15 //"25/8" +//2-Level LMS +#define OQS_LMS_ID_sha256_n32_h5_w8_h5_w8 0x50 //"5/8,5/8" +#define OQS_LMS_ID_sha256_n32_h10_w8_h5_w8 0xA0 //"10/8,5/8" +#define OQS_LMS_ID_sha256_n32_h10_w8_h10_w8 0xA1 //"10/8,10/8" +#define OQS_LMS_ID_sha256_n32_h15_w8_h5_w8 0xF0 //"15/8,5/8" +#define OQS_LMS_ID_sha256_n32_h15_w8_h10_w8 0xF1 //"15/8,10/8" +#define OQS_LMS_ID_sha256_n32_h15_w8_h15_w8 0xF2 //"15/8,15/8" +#define OQS_LMS_ID_sha256_n32_h20_w8_h5_w8 0x140 //"20/8,5/8" +#define OQS_LMS_ID_sha256_n32_h20_w8_h10_w8 0x141 //"20/8,10/8" +#define OQS_LMS_ID_sha256_n32_h20_w8_h15_w8 0x142 //"20/8,15/8" +#define OQS_LMS_ID_sha256_n32_h20_w8_h20_w8 0x143 //"20/8,20/8" + //H5 #define OQS_SIG_STFL_alg_lms_sha256_h5_w1_length_signature 8688 #define OQS_SIG_STFL_alg_lms_sha256_h5_w1_length_pk 60 @@ -198,6 +210,64 @@ OQS_API OQS_STATUS OQS_SIG_STFL_lms_sigs_total(unsigned long long *totaln, const void OQS_SECRET_KEY_LMS_free(OQS_SIG_STFL_SECRET_KEY *sk); + +//2-Level LMS +#define OQS_SIG_STFL_alg_lms_length_private_key 64 +#define OQS_SIG_STFL_alg_lms_length_public_key 60 +#define OQS_SIG_STFL_alg_lms_sha256_h5_w8_h5_w8_length_signature 2644 + +#define OQS_SIG_STFL_alg_lms_sha256_h10_w8_h5_w8_length_signature 2804 +#define OQS_SIG_STFL_alg_lms_sha256_h10_w8_h10_w8_length_signature 2964 + +#define OQS_SIG_STFL_alg_lms_sha256_h15_w8_h5_w8_length_signature 2964 +#define OQS_SIG_STFL_alg_lms_sha256_h15_w8_h10_w8_length_signature 3124 +#define OQS_SIG_STFL_alg_lms_sha256_h15_w8_h15_w8_length_signature 3284 + +#define OQS_SIG_STFL_alg_lms_sha256_h20_w8_h5_w8_length_signature 3124 +#define OQS_SIG_STFL_alg_lms_sha256_h20_w8_h10_w8_length_signature 3284 +#define OQS_SIG_STFL_alg_lms_sha256_h20_w8_h15_w8_length_signature 3444 +#define OQS_SIG_STFL_alg_lms_sha256_h20_w8_h20_w8_length_signature 3604 + +OQS_API OQS_STATUS OQS_SIG_STFL_alg_lms_sha256_h5_w8_h5_w8_keypair(uint8_t *public_key, OQS_SIG_STFL_SECRET_KEY *secret_key); +OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_LMS_SHA256_H5_W8_H5_W8_new(void); +OQS_SIG_STFL *OQS_SIG_STFL_alg_lms_sha256_h5_w8_h5_w8_new(void); + +OQS_API OQS_STATUS OQS_SIG_STFL_alg_lms_sha256_h10_w8_h5_w8_keypair(uint8_t *public_key, OQS_SIG_STFL_SECRET_KEY *secret_key); +OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_LMS_SHA256_H10_W8_H5_W8_new(void); +OQS_SIG_STFL *OQS_SIG_STFL_alg_lms_sha256_h10_w8_h5_w8_new(void); + +OQS_API OQS_STATUS OQS_SIG_STFL_alg_lms_sha256_h10_w8_h10_w8_keypair(uint8_t *public_key, OQS_SIG_STFL_SECRET_KEY *secret_key); +OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_LMS_SHA256_H10_W8_H10_W8_new(void); +OQS_SIG_STFL *OQS_SIG_STFL_alg_lms_sha256_h10_w8_h10_w8_new(void); + +OQS_API OQS_STATUS OQS_SIG_STFL_alg_lms_sha256_h15_w8_h5_w8_keypair(uint8_t *public_key, OQS_SIG_STFL_SECRET_KEY *secret_key); +OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_LMS_SHA256_H15_W8_H5_W8_new(void); +OQS_SIG_STFL *OQS_SIG_STFL_alg_lms_sha256_h15_w8_h5_w8_new(void); + +OQS_API OQS_STATUS OQS_SIG_STFL_alg_lms_sha256_h15_w8_h10_w8_keypair(uint8_t *public_key, OQS_SIG_STFL_SECRET_KEY *secret_key); +OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_LMS_SHA256_H15_W8_H10_W8_new(void); +OQS_SIG_STFL *OQS_SIG_STFL_alg_lms_sha256_h15_w8_h10_w8_new(void); + +OQS_API OQS_STATUS OQS_SIG_STFL_alg_lms_sha256_h15_w8_h15_w8_keypair(uint8_t *public_key, OQS_SIG_STFL_SECRET_KEY *secret_key); +OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_LMS_SHA256_H15_W8_H15_W8_new(void); +OQS_SIG_STFL *OQS_SIG_STFL_alg_lms_sha256_h15_w8_h15_w8_new(void); + +OQS_API OQS_STATUS OQS_SIG_STFL_alg_lms_sha256_h20_w8_h5_w8_keypair(uint8_t *public_key, OQS_SIG_STFL_SECRET_KEY *secret_key); +OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_LMS_SHA256_H20_W8_H5_W8_new(void); +OQS_SIG_STFL *OQS_SIG_STFL_alg_lms_sha256_h20_w8_h5_w8_new(void); + +OQS_API OQS_STATUS OQS_SIG_STFL_alg_lms_sha256_h20_w8_h10_w8_keypair(uint8_t *public_key, OQS_SIG_STFL_SECRET_KEY *secret_key); +OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_LMS_SHA256_H20_W8_H10_W8_new(void); +OQS_SIG_STFL *OQS_SIG_STFL_alg_lms_sha256_h20_w8_h10_w8_new(void); + +OQS_API OQS_STATUS OQS_SIG_STFL_alg_lms_sha256_h20_w8_h15_w8_keypair(uint8_t *public_key, OQS_SIG_STFL_SECRET_KEY *secret_key); +OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_LMS_SHA256_H20_W8_H15_W8_new(void); +OQS_SIG_STFL *OQS_SIG_STFL_alg_lms_sha256_h20_w8_h15_w8_new(void); + +OQS_API OQS_STATUS OQS_SIG_STFL_alg_lms_sha256_h20_w8_h20_w8_keypair(uint8_t *public_key, OQS_SIG_STFL_SECRET_KEY *secret_key); +OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_LMS_SHA256_H20_W8_H20_W8_new(void); +OQS_SIG_STFL *OQS_SIG_STFL_alg_lms_sha256_h20_w8_h20_w8_new(void); + // ----------------------------------- WRAPPER FUNCTIONS ------------------------------------------------ int oqs_sig_stfl_lms_keypair(uint8_t *pk, OQS_SIG_STFL_SECRET_KEY *sk, const uint32_t oid); diff --git a/src/sig_stfl/lms/sig_stfl_lms_functions.c b/src/sig_stfl/lms/sig_stfl_lms_functions.c index 1e3154b009..d9203ecf29 100644 --- a/src/sig_stfl/lms/sig_stfl_lms_functions.c +++ b/src/sig_stfl/lms/sig_stfl_lms_functions.c @@ -360,7 +360,77 @@ int oqs_sig_stfl_lms_keypair(uint8_t *pk, OQS_SIG_STFL_SECRET_KEY *sk, const uin oqs_key_data->lm_type[0] = LMS_SHA256_N32_H25; oqs_key_data->lm_ots_type[0] = LMOTS_SHA256_N32_W8; break; - + case OQS_LMS_ID_sha256_n32_h5_w8_h5_w8: + oqs_key_data->levels = 2; + oqs_key_data->lm_type[0] = LMS_SHA256_N32_H5; + oqs_key_data->lm_ots_type[0] = LMOTS_SHA256_N32_W8; + oqs_key_data->lm_type[1] = LMS_SHA256_N32_H5; + oqs_key_data->lm_ots_type[1] = LMOTS_SHA256_N32_W8; + break; + case OQS_LMS_ID_sha256_n32_h10_w8_h5_w8: + oqs_key_data->levels = 2; + oqs_key_data->lm_type[0] = LMS_SHA256_N32_H10; + oqs_key_data->lm_ots_type[0] = LMOTS_SHA256_N32_W8; + oqs_key_data->lm_type[1] = LMS_SHA256_N32_H5; + oqs_key_data->lm_ots_type[1] = LMOTS_SHA256_N32_W8; + break; + case OQS_LMS_ID_sha256_n32_h10_w8_h10_w8: + oqs_key_data->levels = 2; + oqs_key_data->lm_type[0] = LMS_SHA256_N32_H10; + oqs_key_data->lm_ots_type[0] = LMOTS_SHA256_N32_W8; + oqs_key_data->lm_type[1] = LMS_SHA256_N32_H10; + oqs_key_data->lm_ots_type[1] = LMOTS_SHA256_N32_W8; + break; + case OQS_LMS_ID_sha256_n32_h15_w8_h5_w8: + oqs_key_data->levels = 2; + oqs_key_data->lm_type[0] = LMS_SHA256_N32_H15; + oqs_key_data->lm_ots_type[0] = LMOTS_SHA256_N32_W8; + oqs_key_data->lm_type[1] = LMS_SHA256_N32_H5; + oqs_key_data->lm_ots_type[1] = LMOTS_SHA256_N32_W8; + break; + case OQS_LMS_ID_sha256_n32_h15_w8_h10_w8: + oqs_key_data->levels = 2; + oqs_key_data->lm_type[0] = LMS_SHA256_N32_H15; + oqs_key_data->lm_ots_type[0] = LMOTS_SHA256_N32_W8; + oqs_key_data->lm_type[1] = LMS_SHA256_N32_H10; + oqs_key_data->lm_ots_type[1] = LMOTS_SHA256_N32_W8; + break; + case OQS_LMS_ID_sha256_n32_h15_w8_h15_w8: + oqs_key_data->levels = 2; + oqs_key_data->lm_type[0] = LMS_SHA256_N32_H15; + oqs_key_data->lm_ots_type[0] = LMOTS_SHA256_N32_W8; + oqs_key_data->lm_type[1] = LMS_SHA256_N32_H15; + oqs_key_data->lm_ots_type[1] = LMOTS_SHA256_N32_W8; + break; + case OQS_LMS_ID_sha256_n32_h20_w8_h5_w8: + oqs_key_data->levels = 2; + oqs_key_data->lm_type[0] = LMS_SHA256_N32_H20; + oqs_key_data->lm_ots_type[0] = LMOTS_SHA256_N32_W8; + oqs_key_data->lm_type[1] = LMS_SHA256_N32_H5; + oqs_key_data->lm_ots_type[1] = LMOTS_SHA256_N32_W8; + break; + case OQS_LMS_ID_sha256_n32_h20_w8_h10_w8: + oqs_key_data->levels = 2; + oqs_key_data->lm_type[0] = LMS_SHA256_N32_H20; + oqs_key_data->lm_ots_type[0] = LMOTS_SHA256_N32_W8; + oqs_key_data->lm_type[1] = LMS_SHA256_N32_H10; + oqs_key_data->lm_ots_type[1] = LMOTS_SHA256_N32_W8; + break; + case OQS_LMS_ID_sha256_n32_h20_w8_h15_w8: + oqs_key_data->levels = 2; + oqs_key_data->lm_type[0] = LMS_SHA256_N32_H20; + oqs_key_data->lm_ots_type[0] = LMOTS_SHA256_N32_W8; + oqs_key_data->lm_type[1] = LMS_SHA256_N32_H15; + oqs_key_data->lm_ots_type[1] = LMOTS_SHA256_N32_W8; + break; + case OQS_LMS_ID_sha256_n32_h20_w8_h20_w8: + oqs_key_data->levels = 2; + oqs_key_data->lm_type[0] = LMS_SHA256_N32_H20; + oqs_key_data->lm_ots_type[0] = LMOTS_SHA256_N32_W8; + oqs_key_data->lm_type[1] = LMS_SHA256_N32_H20; + oqs_key_data->lm_ots_type[1] = LMOTS_SHA256_N32_W8; + break; + default: oqs_key_data->lm_type[0] = 0; oqs_key_data->lm_ots_type[0] = 0; parse_err = 1; diff --git a/src/sig_stfl/sig_stfl.c b/src/sig_stfl/sig_stfl.c index 9bdee77780..15448e33a2 100644 --- a/src/sig_stfl/sig_stfl.c +++ b/src/sig_stfl/sig_stfl.c @@ -68,6 +68,21 @@ OQS_API const char *OQS_SIG_STFL_alg_identifier(size_t i) { OQS_SIG_STFL_alg_lms_sha256_n32_h25_w2, OQS_SIG_STFL_alg_lms_sha256_n32_h25_w4, OQS_SIG_STFL_alg_lms_sha256_n32_h25_w8, + + //2-Level LMS + OQS_SIG_STFL_alg_lms_sha256_n32_h5_w8_h5_w8, + + OQS_SIG_STFL_alg_lms_sha256_n32_h10_w8_h5_w8, + OQS_SIG_STFL_alg_lms_sha256_n32_h10_w8_h10_w8, + + OQS_SIG_STFL_alg_lms_sha256_n32_h15_w8_h5_w8, + OQS_SIG_STFL_alg_lms_sha256_n32_h15_w8_h10_w8, + OQS_SIG_STFL_alg_lms_sha256_n32_h15_w8_h15_w8, + + OQS_SIG_STFL_alg_lms_sha256_n32_h20_w8_h5_w8, + OQS_SIG_STFL_alg_lms_sha256_n32_h20_w8_h10_w8, + OQS_SIG_STFL_alg_lms_sha256_n32_h20_w8_h15_w8, + OQS_SIG_STFL_alg_lms_sha256_n32_h20_w8_h20_w8, }; if (i >= OQS_SIG_STFL_algs_length) { @@ -303,6 +318,28 @@ OQS_API int OQS_SIG_STFL_alg_is_enabled(const char *method_name) { } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h25_w8)) { return 1; } + //2-Level LMS + else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h5_w8_h5_w8)) { + return 1; + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h10_w8_h5_w8)) { + return 1; + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h10_w8_h10_w8)) { + return 1; + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h15_w8_h5_w8)) { + return 1; + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h15_w8_h10_w8)) { + return 1; + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h15_w8_h15_w8)) { + return 1; + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h20_w8_h5_w8)) { + return 1; + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h20_w8_h10_w8)) { + return 1; + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h20_w8_h15_w8)) { + return 1; + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h20_w8_h20_w8)) { + return 1; + } #endif //OQS_ENABLE_SIG_STFL_LMS else { return 0; @@ -525,6 +562,28 @@ OQS_API OQS_SIG_STFL *OQS_SIG_STFL_new(const char *method_name) { } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h25_w8)) { return OQS_SIG_STFL_alg_lms_sha256_h25_w8_new(); } +//2-Level LMS + else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h5_w8_h5_w8)) { + return OQS_SIG_STFL_alg_lms_sha256_h5_w8_h5_w8_new(); + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h10_w8_h5_w8)) { + return OQS_SIG_STFL_alg_lms_sha256_h10_w8_h5_w8_new(); + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h10_w8_h10_w8)) { + return OQS_SIG_STFL_alg_lms_sha256_h10_w8_h10_w8_new(); + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h15_w8_h5_w8)) { + return OQS_SIG_STFL_alg_lms_sha256_h15_w8_h5_w8_new(); + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h15_w8_h10_w8)) { + return OQS_SIG_STFL_alg_lms_sha256_h15_w8_h10_w8_new(); + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h15_w8_h15_w8)) { + return OQS_SIG_STFL_alg_lms_sha256_h15_w8_h15_w8_new(); + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h20_w8_h5_w8)) { + return OQS_SIG_STFL_alg_lms_sha256_h20_w8_h5_w8_new(); + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h20_w8_h10_w8)) { + return OQS_SIG_STFL_alg_lms_sha256_h20_w8_h10_w8_new(); + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h20_w8_h15_w8)) { + return OQS_SIG_STFL_alg_lms_sha256_h20_w8_h15_w8_new(); + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h20_w8_h20_w8)) { + return OQS_SIG_STFL_alg_lms_sha256_h20_w8_h20_w8_new(); + } #endif //OQS_ENABLE_SIG_STFL_LMS else { return NULL; @@ -795,6 +854,28 @@ OQS_API OQS_SIG_STFL_SECRET_KEY *OQS_SIG_STFL_SECRET_KEY_new(const char *method_ } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h25_w8)) { return OQS_SECRET_KEY_LMS_SHA256_H25_W8_new(); } +//2-Level LMS + else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h5_w8_h5_w8)) { + return OQS_SECRET_KEY_LMS_SHA256_H5_W8_H5_W8_new(); + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h10_w8_h5_w8)) { + return OQS_SECRET_KEY_LMS_SHA256_H10_W8_H5_W8_new(); + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h10_w8_h10_w8)) { + return OQS_SECRET_KEY_LMS_SHA256_H10_W8_H10_W8_new(); + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h15_w8_h5_w8)) { + return OQS_SECRET_KEY_LMS_SHA256_H15_W8_H5_W8_new(); + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h15_w8_h10_w8)) { + return OQS_SECRET_KEY_LMS_SHA256_H15_W8_H10_W8_new(); + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h15_w8_h15_w8)) { + return OQS_SECRET_KEY_LMS_SHA256_H15_W8_H15_W8_new(); + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h20_w8_h5_w8)) { + return OQS_SECRET_KEY_LMS_SHA256_H20_W8_H5_W8_new(); + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h20_w8_h10_w8)) { + return OQS_SECRET_KEY_LMS_SHA256_H20_W8_H10_W8_new(); + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h20_w8_h15_w8)) { + return OQS_SECRET_KEY_LMS_SHA256_H20_W8_H15_W8_new(); + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h20_w8_h20_w8)) { + return OQS_SECRET_KEY_LMS_SHA256_H20_W8_H20_W8_new(); + } #endif //OQS_ENABLE_SIG_STFL_LMS else { return NULL; diff --git a/src/sig_stfl/sig_stfl.h b/src/sig_stfl/sig_stfl.h index ad55b11d1a..12de108eb9 100644 --- a/src/sig_stfl/sig_stfl.h +++ b/src/sig_stfl/sig_stfl.h @@ -98,7 +98,22 @@ extern "C" { #define OQS_SIG_STFL_alg_lms_sha256_n32_h25_w4 "LMS_SHA256_H25_W4" //"25/4" #define OQS_SIG_STFL_alg_lms_sha256_n32_h25_w8 "LMS_SHA256_H25_W8" //"25/8" -#define OQS_SIG_STFL_algs_length 48 +//2-Level LMS +#define OQS_SIG_STFL_alg_lms_sha256_n32_h5_w8_h5_w8 "LMS_SHA256_H5_W8_H5_W8" //"5/8, 5/8" + +#define OQS_SIG_STFL_alg_lms_sha256_n32_h10_w8_h5_w8 "LMS_SHA256_H10_W8_H5_W8" //"10/8, 5/8" +#define OQS_SIG_STFL_alg_lms_sha256_n32_h10_w8_h10_w8 "LMS_SHA256_H10_W8_H10_W8" //"10/8, 10/8" + +#define OQS_SIG_STFL_alg_lms_sha256_n32_h15_w8_h5_w8 "LMS_SHA256_H15_W8_H5_W8" //"15/8, 5/8" +#define OQS_SIG_STFL_alg_lms_sha256_n32_h15_w8_h10_w8 "LMS_SHA256_H15_W8_H10_W8" //"15/8, 10/8" +#define OQS_SIG_STFL_alg_lms_sha256_n32_h15_w8_h15_w8 "LMS_SHA256_H15_W8_H15_W8" //"15/8, 15/8" + +#define OQS_SIG_STFL_alg_lms_sha256_n32_h20_w8_h5_w8 "LMS_SHA256_H20_W8_H5_W8" //"20/8, 5/8" +#define OQS_SIG_STFL_alg_lms_sha256_n32_h20_w8_h10_w8 "LMS_SHA256_H20_W8_H10_W8" //"20/8, 10/8" +#define OQS_SIG_STFL_alg_lms_sha256_n32_h20_w8_h15_w8 "LMS_SHA256_H20_W8_H15_W8" //"20/8, 15/8" +#define OQS_SIG_STFL_alg_lms_sha256_n32_h20_w8_h20_w8 "LMS_SHA256_H20_W8_H20_W8" //"20/8, 20/8" + +#define OQS_SIG_STFL_algs_length 58 /* Defined LM parameter identifiers */ /* Algorithm identifier for LMS-SHA256_N32_H5 */