diff --git a/src/sig_stfl/lms/sig_stfl_lms_functions.c b/src/sig_stfl/lms/sig_stfl_lms_functions.c index f18d8c445b..63db4c49f1 100644 --- a/src/sig_stfl/lms/sig_stfl_lms_functions.c +++ b/src/sig_stfl/lms/sig_stfl_lms_functions.c @@ -69,6 +69,7 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_lms_sign(uint8_t *signature, size_t *signatu * Don't even attempt signing without a way to safe the updated private key */ if (secret_key->secure_store_scrt_key == NULL) { + fprintf(stderr, "No Secure-store set for secret key.\n."); goto err; } @@ -94,7 +95,7 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_lms_sign(uint8_t *signature, size_t *signatu goto err; } - context = lms_key_data->context; + context = secret_key->context; rc_keyupdate = secret_key->secure_store_scrt_key(sk_key_buf, sk_key_buf_len, context); if (rc_keyupdate != OQS_SUCCESS) { goto err; @@ -241,40 +242,41 @@ int oqs_sig_stfl_lms_keypair(uint8_t *pk, OQS_SIG_STFL_SECRET_KEY *sk, const uin } oqs_key_data = malloc(sizeof(oqs_lms_key_data)); - if (oqs_key_data) { - oqs_key_data->levels = 1; - if (sk->length_secret_key) { - oqs_key_data->len_sec_key = sk->length_secret_key; - oqs_key_data->sec_key = (uint8_t *)malloc(sk->length_secret_key * sizeof(uint8_t)); - if (oqs_key_data->sec_key) { - memset(oqs_key_data->sec_key, 0, sk->length_secret_key); - } else { - OQS_MEM_insecure_free(oqs_key_data); - oqs_key_data = NULL; - return -1; - } - } else { - OQS_MEM_insecure_free(oqs_key_data); - oqs_key_data = NULL; - return -1; - } + if (oqs_key_data == NULL) { + return -1; + } - //Aux Data - size_t len_aux_data = DEFAULT_AUX_DATA; - uint8_t *aux_data = malloc(sizeof(uint8_t) * len_aux_data); - if (aux_data) { - oqs_key_data->aux_data = aux_data; - oqs_key_data->len_aux_data = len_aux_data; - } else { - OQS_MEM_insecure_free( oqs_key_data->sec_key); - OQS_MEM_insecure_free(oqs_key_data); - return -1; - } - } else { - //TODO log error + memset(oqs_key_data, 0, sizeof(oqs_lms_key_data)); + if (sk->length_secret_key == 0) { + OQS_MEM_insecure_free(oqs_key_data); + oqs_key_data = NULL; + return -1; + } + + oqs_key_data->levels = 1; + oqs_key_data->len_sec_key = sk->length_secret_key; + oqs_key_data->sec_key = (uint8_t *)malloc(sk->length_secret_key * sizeof(uint8_t)); + if (oqs_key_data->sec_key == NULL) { + OQS_MEM_insecure_free(oqs_key_data); + oqs_key_data = NULL; return -1; } + memset(oqs_key_data->sec_key, 0, sk->length_secret_key); + + //Aux Data + size_t len_aux_data = DEFAULT_AUX_DATA; + uint8_t *aux_data = malloc(sizeof(uint8_t) * len_aux_data); + if (aux_data == NULL) { + OQS_MEM_insecure_free( oqs_key_data->sec_key); + OQS_MEM_insecure_free(oqs_key_data); + return -1; + } + + oqs_key_data->aux_data = aux_data; + oqs_key_data->len_aux_data = len_aux_data; + oqs_key_data->context = sk->context; + /* Set lms param set */ switch (oid) { case OQS_LMS_ID_sha256_n32_h5_w1: @@ -668,6 +670,7 @@ OQS_STATUS oqs_deserialize_lms_key(OQS_SIG_STFL_SECRET_KEY *sk, const size_t sk_ lms_key_data->len_aux_data = aux_buf_len; } + sk->context = context; sk->secret_key_data = lms_key_data; goto success; @@ -682,9 +685,10 @@ OQS_STATUS oqs_deserialize_lms_key(OQS_SIG_STFL_SECRET_KEY *sk, const size_t sk_ } void oqs_lms_key_set_store_cb(OQS_SIG_STFL_SECRET_KEY *sk, secure_store_sk store_cb, void *context) { - oqs_lms_key_data *lms_key_data = (oqs_lms_key_data *)sk->secret_key_data; - if (lms_key_data) { - lms_key_data->context = context; - sk->secure_store_scrt_key = store_cb; + + if (sk == NULL) { + return; } + sk->secure_store_scrt_key = store_cb; + sk->context = context; } diff --git a/src/sig_stfl/sig_stfl.h b/src/sig_stfl/sig_stfl.h index 33177e829e..e4b7d42c9c 100644 --- a/src/sig_stfl/sig_stfl.h +++ b/src/sig_stfl/sig_stfl.h @@ -268,6 +268,9 @@ typedef struct OQS_SIG_STFL_SECRET_KEY { /* mutual exclusion struct */ void *mutex; + /* file storage handle */ + void *context; + /** * Secret Key retrieval Function * diff --git a/src/sig_stfl/xmss/sig_stfl_xmss.h b/src/sig_stfl/xmss/sig_stfl_xmss.h index 54006043e1..8b9536daed 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmss.h +++ b/src/sig_stfl/xmss/sig_stfl_xmss.h @@ -503,4 +503,7 @@ OQS_STATUS OQS_SECRET_KEY_XMSS_serialize_key(const OQS_SIG_STFL_SECRET_KEY *sk, /* Deserialize XMSS byte string into an XMSS secret key data */ OQS_STATUS OQS_SECRET_KEY_XMSS_deserialize_key(OQS_SIG_STFL_SECRET_KEY *sk, const size_t sk_len, const uint8_t *sk_buf, void *context); +/* Set XMSS byte string into an XMSS secret key data */ +void OQS_SECRET_KEY_XMSS_set_store_cb(OQS_SIG_STFL_SECRET_KEY *sk, secure_store_sk store_cb, void *context); + #endif /* OQS_SIG_STFL_XMSS_H */ diff --git a/src/sig_stfl/xmss/sig_stfl_xmss_secret_key_functions.c b/src/sig_stfl/xmss/sig_stfl_xmss_secret_key_functions.c index 4a47c938c3..a9ea864cdb 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmss_secret_key_functions.c +++ b/src/sig_stfl/xmss/sig_stfl_xmss_secret_key_functions.c @@ -37,9 +37,8 @@ OQS_STATUS OQS_SECRET_KEY_XMSS_deserialize_key(OQS_SIG_STFL_SECRET_KEY *sk, cons } if (sk->secret_key_data != NULL) { - // Key data already present - // We dont want to trample over data - return OQS_ERROR; + OQS_MEM_secure_free(sk->secret_key_data, sk->length_secret_key); + sk->secret_key_data = NULL; } // Assume key data is not present @@ -48,7 +47,17 @@ OQS_STATUS OQS_SECRET_KEY_XMSS_deserialize_key(OQS_SIG_STFL_SECRET_KEY *sk, cons return OQS_ERROR; } + sk->context = context; memcpy(sk->secret_key_data, sk_buf, sk_len); return OQS_SUCCESS; } + +void OQS_SECRET_KEY_XMSS_set_store_cb(OQS_SIG_STFL_SECRET_KEY *sk, secure_store_sk store_cb, void *context) { + if (!sk || !store_cb || !context) { + return; + } + + sk->context = context; + sk->secure_store_scrt_key = store_cb; +} diff --git a/src/sig_stfl/xmss/sig_stfl_xmss_sha256_h10.c b/src/sig_stfl/xmss/sig_stfl_xmss_sha256_h10.c index 20a8f87af0..2affc67195 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmss_sha256_h10.c +++ b/src/sig_stfl/xmss/sig_stfl_xmss_sha256_h10.c @@ -68,6 +68,8 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSS_SHA256_H10_new(void) { sk->free_key = OQS_SECRET_KEY_XMSS_free; + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_XMSS_set_store_cb; + return sk; } @@ -87,17 +89,56 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_sha256_h10_keypair(XMSS_UNUSED_ATT uint OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_sha256_h10_sign(uint8_t *signature, size_t *signature_len, XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, XMSS_UNUSED_ATT OQS_SIG_STFL_SECRET_KEY *secret_key) { + OQS_STATUS rc_keyupdate, status = OQS_SUCCESS; + const OQS_SIG_STFL_SECRET_KEY *sk; + uint8_t *sk_key_buf_ptr = NULL; + unsigned long long sig_length = 0; + size_t sk_key_buf_len = 0; + if (signature == NULL || signature_len == NULL || message == NULL || secret_key == NULL || secret_key->secret_key_data == NULL) { return OQS_ERROR; } - unsigned long long sig_length = 0; - if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + /* check for secret key update function */ + if (secret_key->secure_store_scrt_key == NULL) { return OQS_ERROR; } + + /* Lock secret to ensure OTS use */ + if ((secret_key->lock_key) && (secret_key->mutex)) { + secret_key->lock_key(secret_key->mutex); + } + + if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + status = OQS_ERROR; + goto err; + } *signature_len = (size_t)sig_length; - return OQS_SUCCESS; + /* + * serialize and securely store the updated private key + * but, delete signature and the serialized key other wise + */ + + sk = secret_key; + rc_keyupdate = OQS_SECRET_KEY_XMSS_serialize_key(sk, &sk_key_buf_len, &sk_key_buf_ptr); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + goto err; + } + + rc_keyupdate = secret_key->secure_store_scrt_key(sk_key_buf_ptr, sk_key_buf_len, secret_key->context); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + } + + OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len); +err: + /* Unlock secret to ensure OTS use */ + if ((secret_key->unlock_key) && (secret_key->mutex)) { + secret_key->unlock_key(secret_key->mutex); + } + return status; } OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_sha256_h10_verify(XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, const uint8_t *signature, size_t signature_len, XMSS_UNUSED_ATT const uint8_t *public_key) { diff --git a/src/sig_stfl/xmss/sig_stfl_xmss_sha256_h16.c b/src/sig_stfl/xmss/sig_stfl_xmss_sha256_h16.c index d32ad7df05..cfaa958dd7 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmss_sha256_h16.c +++ b/src/sig_stfl/xmss/sig_stfl_xmss_sha256_h16.c @@ -67,6 +67,8 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSS_SHA256_H16_new(void) { sk->free_key = OQS_SECRET_KEY_XMSS_free; + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_XMSS_set_store_cb; + return sk; } @@ -86,17 +88,56 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_sha256_h16_keypair(XMSS_UNUSED_ATT uint OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_sha256_h16_sign(uint8_t *signature, size_t *signature_len, XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, XMSS_UNUSED_ATT OQS_SIG_STFL_SECRET_KEY *secret_key) { + OQS_STATUS rc_keyupdate, status = OQS_SUCCESS; + const OQS_SIG_STFL_SECRET_KEY *sk; + uint8_t *sk_key_buf_ptr = NULL; + unsigned long long sig_length = 0; + size_t sk_key_buf_len = 0; + if (signature == NULL || signature_len == NULL || message == NULL || secret_key == NULL || secret_key->secret_key_data == NULL) { return OQS_ERROR; } - unsigned long long sig_length = 0; - if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + /* check for secret key update function */ + if (secret_key->secure_store_scrt_key == NULL) { return OQS_ERROR; } - *signature_len = (size_t) sig_length; - return OQS_SUCCESS; + /* Lock secret to ensure OTS use */ + if ((secret_key->lock_key) && (secret_key->mutex)) { + secret_key->lock_key(secret_key->mutex); + } + + if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + status = OQS_ERROR; + goto err; + } + *signature_len = (size_t)sig_length; + + /* + * serialize and securely store the updated private key + * but, delete signature and the serialized key other wise + */ + + sk = secret_key; + rc_keyupdate = OQS_SECRET_KEY_XMSS_serialize_key(sk, &sk_key_buf_len, &sk_key_buf_ptr); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + goto err; + } + + rc_keyupdate = secret_key->secure_store_scrt_key(sk_key_buf_ptr, sk_key_buf_len, secret_key->context); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + } + + OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len); +err: + /* Unlock secret to ensure OTS use */ + if ((secret_key->unlock_key) && (secret_key->mutex)) { + secret_key->unlock_key(secret_key->mutex); + } + return status; } OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_sha256_h16_verify(XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, const uint8_t *signature, size_t signature_len, XMSS_UNUSED_ATT const uint8_t *public_key) { diff --git a/src/sig_stfl/xmss/sig_stfl_xmss_sha256_h20.c b/src/sig_stfl/xmss/sig_stfl_xmss_sha256_h20.c index 9675fb1151..1145d17e2b 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmss_sha256_h20.c +++ b/src/sig_stfl/xmss/sig_stfl_xmss_sha256_h20.c @@ -67,6 +67,8 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSS_SHA256_H20_new(void) { sk->free_key = OQS_SECRET_KEY_XMSS_free; + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_XMSS_set_store_cb; + return sk; } @@ -86,17 +88,56 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_sha256_h20_keypair(XMSS_UNUSED_ATT uint OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_sha256_h20_sign(uint8_t *signature, size_t *signature_len, XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, XMSS_UNUSED_ATT OQS_SIG_STFL_SECRET_KEY *secret_key) { + OQS_STATUS rc_keyupdate, status = OQS_SUCCESS; + const OQS_SIG_STFL_SECRET_KEY *sk; + uint8_t *sk_key_buf_ptr = NULL; + unsigned long long sig_length = 0; + size_t sk_key_buf_len = 0; + if (signature == NULL || signature_len == NULL || message == NULL || secret_key == NULL || secret_key->secret_key_data == NULL) { return OQS_ERROR; } - unsigned long long sig_length = 0; - if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + /* check for secret key update function */ + if (secret_key->secure_store_scrt_key == NULL) { return OQS_ERROR; } - *signature_len = (size_t) sig_length; - return OQS_SUCCESS; + /* Lock secret to ensure OTS use */ + if ((secret_key->lock_key) && (secret_key->mutex)) { + secret_key->lock_key(secret_key->mutex); + } + + if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + status = OQS_ERROR; + goto err; + } + *signature_len = (size_t)sig_length; + + /* + * serialize and securely store the updated private key + * but, delete signature and the serialized key other wise + */ + + sk = secret_key; + rc_keyupdate = OQS_SECRET_KEY_XMSS_serialize_key(sk, &sk_key_buf_len, &sk_key_buf_ptr); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + goto err; + } + + rc_keyupdate = secret_key->secure_store_scrt_key(sk_key_buf_ptr, sk_key_buf_len, secret_key->context); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + } + + OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len); +err: + /* Unlock secret to ensure OTS use */ + if ((secret_key->unlock_key) && (secret_key->mutex)) { + secret_key->unlock_key(secret_key->mutex); + } + return status; } OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_sha256_h20_verify(XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, const uint8_t *signature, size_t signature_len, XMSS_UNUSED_ATT const uint8_t *public_key) { diff --git a/src/sig_stfl/xmss/sig_stfl_xmss_sha512_h10.c b/src/sig_stfl/xmss/sig_stfl_xmss_sha512_h10.c index c4589175c6..c7ca88eee7 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmss_sha512_h10.c +++ b/src/sig_stfl/xmss/sig_stfl_xmss_sha512_h10.c @@ -67,6 +67,8 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSS_SHA512_H10_new(void) { sk->free_key = OQS_SECRET_KEY_XMSS_free; + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_XMSS_set_store_cb; + return sk; } @@ -86,17 +88,56 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_sha512_h10_keypair(XMSS_UNUSED_ATT uint OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_sha512_h10_sign(uint8_t *signature, size_t *signature_len, XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, XMSS_UNUSED_ATT OQS_SIG_STFL_SECRET_KEY *secret_key) { + OQS_STATUS rc_keyupdate, status = OQS_SUCCESS; + const OQS_SIG_STFL_SECRET_KEY *sk; + uint8_t *sk_key_buf_ptr = NULL; + unsigned long long sig_length = 0; + size_t sk_key_buf_len = 0; + if (signature == NULL || signature_len == NULL || message == NULL || secret_key == NULL || secret_key->secret_key_data == NULL) { return OQS_ERROR; } - unsigned long long sig_length = 0; - if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + /* check for secret key update function */ + if (secret_key->secure_store_scrt_key == NULL) { return OQS_ERROR; } - *signature_len = (size_t) sig_length; - return OQS_SUCCESS; + /* Lock secret to ensure OTS use */ + if ((secret_key->lock_key) && (secret_key->mutex)) { + secret_key->lock_key(secret_key->mutex); + } + + if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + status = OQS_ERROR; + goto err; + } + *signature_len = (size_t)sig_length; + + /* + * serialize and securely store the updated private key + * but, delete signature and the serialized key other wise + */ + + sk = secret_key; + rc_keyupdate = OQS_SECRET_KEY_XMSS_serialize_key(sk, &sk_key_buf_len, &sk_key_buf_ptr); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + goto err; + } + + rc_keyupdate = secret_key->secure_store_scrt_key(sk_key_buf_ptr, sk_key_buf_len, secret_key->context); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + } + + OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len); +err: + /* Unlock secret to ensure OTS use */ + if ((secret_key->unlock_key) && (secret_key->mutex)) { + secret_key->unlock_key(secret_key->mutex); + } + return status; } OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_sha512_h10_verify(XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, const uint8_t *signature, size_t signature_len, XMSS_UNUSED_ATT const uint8_t *public_key) { diff --git a/src/sig_stfl/xmss/sig_stfl_xmss_sha512_h16.c b/src/sig_stfl/xmss/sig_stfl_xmss_sha512_h16.c index bab2bda1f2..70123ccb16 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmss_sha512_h16.c +++ b/src/sig_stfl/xmss/sig_stfl_xmss_sha512_h16.c @@ -67,6 +67,8 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSS_SHA512_H16_new(void) { sk->free_key = OQS_SECRET_KEY_XMSS_free; + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_XMSS_set_store_cb; + return sk; } @@ -86,17 +88,56 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_sha512_h16_keypair(XMSS_UNUSED_ATT uint OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_sha512_h16_sign(uint8_t *signature, size_t *signature_len, XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, XMSS_UNUSED_ATT OQS_SIG_STFL_SECRET_KEY *secret_key) { + OQS_STATUS rc_keyupdate, status = OQS_SUCCESS; + const OQS_SIG_STFL_SECRET_KEY *sk; + uint8_t *sk_key_buf_ptr = NULL; + unsigned long long sig_length = 0; + size_t sk_key_buf_len = 0; + if (signature == NULL || signature_len == NULL || message == NULL || secret_key == NULL || secret_key->secret_key_data == NULL) { return OQS_ERROR; } - unsigned long long sig_length = 0; - if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + /* check for secret key update function */ + if (secret_key->secure_store_scrt_key == NULL) { return OQS_ERROR; } - *signature_len = (size_t) sig_length; - return OQS_SUCCESS; + /* Lock secret to ensure OTS use */ + if ((secret_key->lock_key) && (secret_key->mutex)) { + secret_key->lock_key(secret_key->mutex); + } + + if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + status = OQS_ERROR; + goto err; + } + *signature_len = (size_t)sig_length; + + /* + * serialize and securely store the updated private key + * but, delete signature and the serialized key other wise + */ + + sk = secret_key; + rc_keyupdate = OQS_SECRET_KEY_XMSS_serialize_key(sk, &sk_key_buf_len, &sk_key_buf_ptr); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + goto err; + } + + rc_keyupdate = secret_key->secure_store_scrt_key(sk_key_buf_ptr, sk_key_buf_len, secret_key->context); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + } + + OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len); +err: + /* Unlock secret to ensure OTS use */ + if ((secret_key->unlock_key) && (secret_key->mutex)) { + secret_key->unlock_key(secret_key->mutex); + } + return status; } OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_sha512_h16_verify(XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, const uint8_t *signature, size_t signature_len, XMSS_UNUSED_ATT const uint8_t *public_key) { diff --git a/src/sig_stfl/xmss/sig_stfl_xmss_sha512_h20.c b/src/sig_stfl/xmss/sig_stfl_xmss_sha512_h20.c index 5c931a35c4..ebb03643a6 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmss_sha512_h20.c +++ b/src/sig_stfl/xmss/sig_stfl_xmss_sha512_h20.c @@ -67,6 +67,8 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSS_SHA512_H20_new(void) { sk->free_key = OQS_SECRET_KEY_XMSS_free; + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_XMSS_set_store_cb; + return sk; } @@ -86,17 +88,56 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_sha512_h20_keypair(XMSS_UNUSED_ATT uint OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_sha512_h20_sign(uint8_t *signature, size_t *signature_len, XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, XMSS_UNUSED_ATT OQS_SIG_STFL_SECRET_KEY *secret_key) { + OQS_STATUS rc_keyupdate, status = OQS_SUCCESS; + const OQS_SIG_STFL_SECRET_KEY *sk; + uint8_t *sk_key_buf_ptr = NULL; + unsigned long long sig_length = 0; + size_t sk_key_buf_len = 0; + if (signature == NULL || signature_len == NULL || message == NULL || secret_key == NULL || secret_key->secret_key_data == NULL) { return OQS_ERROR; } - unsigned long long sig_length = 0; - if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + /* check for secret key update function */ + if (secret_key->secure_store_scrt_key == NULL) { return OQS_ERROR; } - *signature_len = (size_t) sig_length; - return OQS_SUCCESS; + /* Lock secret to ensure OTS use */ + if ((secret_key->lock_key) && (secret_key->mutex)) { + secret_key->lock_key(secret_key->mutex); + } + + if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + status = OQS_ERROR; + goto err; + } + *signature_len = (size_t)sig_length; + + /* + * serialize and securely store the updated private key + * but, delete signature and the serialized key other wise + */ + + sk = secret_key; + rc_keyupdate = OQS_SECRET_KEY_XMSS_serialize_key(sk, &sk_key_buf_len, &sk_key_buf_ptr); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + goto err; + } + + rc_keyupdate = secret_key->secure_store_scrt_key(sk_key_buf_ptr, sk_key_buf_len, secret_key->context); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + } + + OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len); +err: + /* Unlock secret to ensure OTS use */ + if ((secret_key->unlock_key) && (secret_key->mutex)) { + secret_key->unlock_key(secret_key->mutex); + } + return status; } OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_sha512_h20_verify(XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, const uint8_t *signature, size_t signature_len, XMSS_UNUSED_ATT const uint8_t *public_key) { diff --git a/src/sig_stfl/xmss/sig_stfl_xmss_shake128_h10.c b/src/sig_stfl/xmss/sig_stfl_xmss_shake128_h10.c index fde4331e66..4d15d86461 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmss_shake128_h10.c +++ b/src/sig_stfl/xmss/sig_stfl_xmss_shake128_h10.c @@ -67,6 +67,8 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSS_SHAKE128_H10_new(void) { sk->free_key = OQS_SECRET_KEY_XMSS_free; + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_XMSS_set_store_cb; + return sk; } @@ -86,17 +88,56 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_shake128_h10_keypair(XMSS_UNUSED_ATT ui OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_shake128_h10_sign(uint8_t *signature, size_t *signature_len, XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, XMSS_UNUSED_ATT OQS_SIG_STFL_SECRET_KEY *secret_key) { + OQS_STATUS rc_keyupdate, status = OQS_SUCCESS; + const OQS_SIG_STFL_SECRET_KEY *sk; + uint8_t *sk_key_buf_ptr = NULL; + unsigned long long sig_length = 0; + size_t sk_key_buf_len = 0; + if (signature == NULL || signature_len == NULL || message == NULL || secret_key == NULL || secret_key->secret_key_data == NULL) { return OQS_ERROR; } - unsigned long long sig_length = 0; - if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + /* check for secret key update function */ + if (secret_key->secure_store_scrt_key == NULL) { return OQS_ERROR; } - *signature_len = (size_t) sig_length; - return OQS_SUCCESS; + /* Lock secret to ensure OTS use */ + if ((secret_key->lock_key) && (secret_key->mutex)) { + secret_key->lock_key(secret_key->mutex); + } + + if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + status = OQS_ERROR; + goto err; + } + *signature_len = (size_t)sig_length; + + /* + * serialize and securely store the updated private key + * but, delete signature and the serialized key other wise + */ + + sk = secret_key; + rc_keyupdate = OQS_SECRET_KEY_XMSS_serialize_key(sk, &sk_key_buf_len, &sk_key_buf_ptr); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + goto err; + } + + rc_keyupdate = secret_key->secure_store_scrt_key(sk_key_buf_ptr, sk_key_buf_len, secret_key->context); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + } + + OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len); +err: + /* Unlock secret to ensure OTS use */ + if ((secret_key->unlock_key) && (secret_key->mutex)) { + secret_key->unlock_key(secret_key->mutex); + } + return status; } OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_shake128_h10_verify(XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, const uint8_t *signature, size_t signature_len, XMSS_UNUSED_ATT const uint8_t *public_key) { diff --git a/src/sig_stfl/xmss/sig_stfl_xmss_shake128_h16.c b/src/sig_stfl/xmss/sig_stfl_xmss_shake128_h16.c index d1587260f3..499ba294ad 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmss_shake128_h16.c +++ b/src/sig_stfl/xmss/sig_stfl_xmss_shake128_h16.c @@ -67,6 +67,8 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSS_SHAKE128_H16_new(void) { sk->free_key = OQS_SECRET_KEY_XMSS_free; + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_XMSS_set_store_cb; + return sk; } @@ -86,17 +88,56 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_shake128_h16_keypair(XMSS_UNUSED_ATT ui OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_shake128_h16_sign(uint8_t *signature, size_t *signature_len, XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, XMSS_UNUSED_ATT OQS_SIG_STFL_SECRET_KEY *secret_key) { + OQS_STATUS rc_keyupdate, status = OQS_SUCCESS; + const OQS_SIG_STFL_SECRET_KEY *sk; + uint8_t *sk_key_buf_ptr = NULL; + unsigned long long sig_length = 0; + size_t sk_key_buf_len = 0; + if (signature == NULL || signature_len == NULL || message == NULL || secret_key == NULL || secret_key->secret_key_data == NULL) { return OQS_ERROR; } - unsigned long long sig_length = 0; - if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + /* check for secret key update function */ + if (secret_key->secure_store_scrt_key == NULL) { return OQS_ERROR; } - *signature_len = (size_t) sig_length; - return OQS_SUCCESS; + /* Lock secret to ensure OTS use */ + if ((secret_key->lock_key) && (secret_key->mutex)) { + secret_key->lock_key(secret_key->mutex); + } + + if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + status = OQS_ERROR; + goto err; + } + *signature_len = (size_t)sig_length; + + /* + * serialize and securely store the updated private key + * but, delete signature and the serialized key other wise + */ + + sk = secret_key; + rc_keyupdate = OQS_SECRET_KEY_XMSS_serialize_key(sk, &sk_key_buf_len, &sk_key_buf_ptr); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + goto err; + } + + rc_keyupdate = secret_key->secure_store_scrt_key(sk_key_buf_ptr, sk_key_buf_len, secret_key->context); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + } + + OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len); +err: + /* Unlock secret to ensure OTS use */ + if ((secret_key->unlock_key) && (secret_key->mutex)) { + secret_key->unlock_key(secret_key->mutex); + } + return status; } OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_shake128_h16_verify(XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, const uint8_t *signature, size_t signature_len, XMSS_UNUSED_ATT const uint8_t *public_key) { diff --git a/src/sig_stfl/xmss/sig_stfl_xmss_shake128_h20.c b/src/sig_stfl/xmss/sig_stfl_xmss_shake128_h20.c index c618ce8260..8f47a4f825 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmss_shake128_h20.c +++ b/src/sig_stfl/xmss/sig_stfl_xmss_shake128_h20.c @@ -67,6 +67,8 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSS_SHAKE128_H20_new(void) { sk->free_key = OQS_SECRET_KEY_XMSS_free; + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_XMSS_set_store_cb; + return sk; } @@ -86,17 +88,56 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_shake128_h20_keypair(XMSS_UNUSED_ATT ui OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_shake128_h20_sign(uint8_t *signature, size_t *signature_len, XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, XMSS_UNUSED_ATT OQS_SIG_STFL_SECRET_KEY *secret_key) { + OQS_STATUS rc_keyupdate, status = OQS_SUCCESS; + const OQS_SIG_STFL_SECRET_KEY *sk; + uint8_t *sk_key_buf_ptr = NULL; + unsigned long long sig_length = 0; + size_t sk_key_buf_len = 0; + if (signature == NULL || signature_len == NULL || message == NULL || secret_key == NULL || secret_key->secret_key_data == NULL) { return OQS_ERROR; } - unsigned long long sig_length = 0; - if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + /* check for secret key update function */ + if (secret_key->secure_store_scrt_key == NULL) { return OQS_ERROR; } - *signature_len = (size_t) sig_length; - return OQS_SUCCESS; + /* Lock secret to ensure OTS use */ + if ((secret_key->lock_key) && (secret_key->mutex)) { + secret_key->lock_key(secret_key->mutex); + } + + if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + status = OQS_ERROR; + goto err; + } + *signature_len = (size_t)sig_length; + + /* + * serialize and securely store the updated private key + * but, delete signature and the serialized key other wise + */ + + sk = secret_key; + rc_keyupdate = oqs_serialize_lms_key(sk, &sk_key_buf_len, &sk_key_buf_ptr); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + goto err; + } + + rc_keyupdate = secret_key->secure_store_scrt_key(sk_key_buf_ptr, sk_key_buf_len, secret_key->context); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + } + + OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len); +err: + /* Unlock secret to ensure OTS use */ + if ((secret_key->unlock_key) && (secret_key->mutex)) { + secret_key->unlock_key(secret_key->mutex); + } + return status; } OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_shake128_h20_verify(XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, const uint8_t *signature, size_t signature_len, XMSS_UNUSED_ATT const uint8_t *public_key) { diff --git a/src/sig_stfl/xmss/sig_stfl_xmss_shake256_h10.c b/src/sig_stfl/xmss/sig_stfl_xmss_shake256_h10.c index 84e5772280..944a34d9de 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmss_shake256_h10.c +++ b/src/sig_stfl/xmss/sig_stfl_xmss_shake256_h10.c @@ -67,6 +67,8 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSS_SHAKE256_H10_new(void) { sk->free_key = OQS_SECRET_KEY_XMSS_free; + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_XMSS_set_store_cb; + return sk; } @@ -86,17 +88,56 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_shake256_h10_keypair(XMSS_UNUSED_ATT ui OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_shake256_h10_sign(uint8_t *signature, size_t *signature_len, XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, XMSS_UNUSED_ATT OQS_SIG_STFL_SECRET_KEY *secret_key) { + OQS_STATUS rc_keyupdate, status = OQS_SUCCESS; + const OQS_SIG_STFL_SECRET_KEY *sk; + uint8_t *sk_key_buf_ptr = NULL; + unsigned long long sig_length = 0; + size_t sk_key_buf_len = 0; + if (signature == NULL || signature_len == NULL || message == NULL || secret_key == NULL || secret_key->secret_key_data == NULL) { return OQS_ERROR; } - unsigned long long sig_length = 0; - if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + /* check for secret key update function */ + if (secret_key->secure_store_scrt_key == NULL) { return OQS_ERROR; } - *signature_len = (size_t) sig_length; - return OQS_SUCCESS; + /* Lock secret to ensure OTS use */ + if ((secret_key->lock_key) && (secret_key->mutex)) { + secret_key->lock_key(secret_key->mutex); + } + + if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + status = OQS_ERROR; + goto err; + } + *signature_len = (size_t)sig_length; + + /* + * serialize and securely store the updated private key + * but, delete signature and the serialized key other wise + */ + + sk = secret_key; + rc_keyupdate = OQS_SECRET_KEY_XMSS_serialize_key(sk, &sk_key_buf_len, &sk_key_buf_ptr); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + goto err; + } + + rc_keyupdate = secret_key->secure_store_scrt_key(sk_key_buf_ptr, sk_key_buf_len, secret_key->context); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + } + + OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len); +err: + /* Unlock secret to ensure OTS use */ + if ((secret_key->unlock_key) && (secret_key->mutex)) { + secret_key->unlock_key(secret_key->mutex); + } + return status; } OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_shake256_h10_verify(XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, const uint8_t *signature, size_t signature_len, XMSS_UNUSED_ATT const uint8_t *public_key) { diff --git a/src/sig_stfl/xmss/sig_stfl_xmss_shake256_h16.c b/src/sig_stfl/xmss/sig_stfl_xmss_shake256_h16.c index 788eb8f1e7..93e8791bf8 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmss_shake256_h16.c +++ b/src/sig_stfl/xmss/sig_stfl_xmss_shake256_h16.c @@ -67,6 +67,8 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSS_SHAKE256_H16_new(void) { sk->free_key = OQS_SECRET_KEY_XMSS_free; + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_XMSS_set_store_cb; + return sk; } @@ -86,17 +88,56 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_shake256_h16_keypair(XMSS_UNUSED_ATT ui OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_shake256_h16_sign(uint8_t *signature, size_t *signature_len, XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, XMSS_UNUSED_ATT OQS_SIG_STFL_SECRET_KEY *secret_key) { + OQS_STATUS rc_keyupdate, status = OQS_SUCCESS; + const OQS_SIG_STFL_SECRET_KEY *sk; + uint8_t *sk_key_buf_ptr = NULL; + unsigned long long sig_length = 0; + size_t sk_key_buf_len = 0; + if (signature == NULL || signature_len == NULL || message == NULL || secret_key == NULL || secret_key->secret_key_data == NULL) { return OQS_ERROR; } - unsigned long long sig_length = 0; - if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + /* check for secret key update function */ + if (secret_key->secure_store_scrt_key == NULL) { return OQS_ERROR; } - *signature_len = (size_t) sig_length; - return OQS_SUCCESS; + /* Lock secret to ensure OTS use */ + if ((secret_key->lock_key) && (secret_key->mutex)) { + secret_key->lock_key(secret_key->mutex); + } + + if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + status = OQS_ERROR; + goto err; + } + *signature_len = (size_t)sig_length; + + /* + * serialize and securely store the updated private key + * but, delete signature and the serialized key other wise + */ + + sk = secret_key; + rc_keyupdate = OQS_SECRET_KEY_XMSS_serialize_key(sk, &sk_key_buf_len, &sk_key_buf_ptr); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + goto err; + } + + rc_keyupdate = secret_key->secure_store_scrt_key(sk_key_buf_ptr, sk_key_buf_len, secret_key->context); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + } + + OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len); +err: + /* Unlock secret to ensure OTS use */ + if ((secret_key->unlock_key) && (secret_key->mutex)) { + secret_key->unlock_key(secret_key->mutex); + } + return status; } OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_shake256_h16_verify(XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, const uint8_t *signature, size_t signature_len, XMSS_UNUSED_ATT const uint8_t *public_key) { diff --git a/src/sig_stfl/xmss/sig_stfl_xmss_shake256_h20.c b/src/sig_stfl/xmss/sig_stfl_xmss_shake256_h20.c index 7029f669f8..e701614e79 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmss_shake256_h20.c +++ b/src/sig_stfl/xmss/sig_stfl_xmss_shake256_h20.c @@ -67,6 +67,8 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSS_SHAKE256_H20_new(void) { sk->free_key = OQS_SECRET_KEY_XMSS_free; + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_XMSS_set_store_cb; + return sk; } @@ -86,17 +88,56 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_shake256_h20_keypair(XMSS_UNUSED_ATT ui OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_shake256_h20_sign(uint8_t *signature, size_t *signature_len, XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, XMSS_UNUSED_ATT OQS_SIG_STFL_SECRET_KEY *secret_key) { + OQS_STATUS rc_keyupdate, status = OQS_SUCCESS; + const OQS_SIG_STFL_SECRET_KEY *sk; + uint8_t *sk_key_buf_ptr = NULL; + unsigned long long sig_length = 0; + size_t sk_key_buf_len = 0; + if (signature == NULL || signature_len == NULL || message == NULL || secret_key == NULL || secret_key->secret_key_data == NULL) { return OQS_ERROR; } - unsigned long long sig_length = 0; - if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + /* check for secret key update function */ + if (secret_key->secure_store_scrt_key == NULL) { return OQS_ERROR; } - *signature_len = (size_t) sig_length; - return OQS_SUCCESS; + /* Lock secret to ensure OTS use */ + if ((secret_key->lock_key) && (secret_key->mutex)) { + secret_key->lock_key(secret_key->mutex); + } + + if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + status = OQS_ERROR; + goto err; + } + *signature_len = (size_t)sig_length; + + /* + * serialize and securely store the updated private key + * but, delete signature and the serialized key other wise + */ + + sk = secret_key; + rc_keyupdate = OQS_SECRET_KEY_XMSS_serialize_key(sk, &sk_key_buf_len, &sk_key_buf_ptr); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + goto err; + } + + rc_keyupdate = secret_key->secure_store_scrt_key(sk_key_buf_ptr, sk_key_buf_len, secret_key->context); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + } + + OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len); +err: + /* Unlock secret to ensure OTS use */ + if ((secret_key->unlock_key) && (secret_key->mutex)) { + secret_key->unlock_key(secret_key->mutex); + } + return status; } OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_shake256_h20_verify(XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, const uint8_t *signature, size_t signature_len, XMSS_UNUSED_ATT const uint8_t *public_key) { diff --git a/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h20_2.c b/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h20_2.c index c4862f728e..f333b08a0e 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h20_2.c +++ b/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h20_2.c @@ -67,6 +67,8 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSSMT_SHA256_H20_2_new(void) { sk->free_key = OQS_SECRET_KEY_XMSS_free; + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_XMSS_set_store_cb; + return sk; } @@ -86,17 +88,56 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_sha256_h20_2_keypair(XMSS_UNUSED_ATT OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_sha256_h20_2_sign(uint8_t *signature, size_t *signature_len, XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, XMSS_UNUSED_ATT OQS_SIG_STFL_SECRET_KEY *secret_key) { + OQS_STATUS rc_keyupdate, status = OQS_SUCCESS; + const OQS_SIG_STFL_SECRET_KEY *sk; + uint8_t *sk_key_buf_ptr = NULL; + unsigned long long sig_length = 0; + size_t sk_key_buf_len = 0; + if (signature == NULL || signature_len == NULL || message == NULL || secret_key == NULL || secret_key->secret_key_data == NULL) { return OQS_ERROR; } - unsigned long long sig_length = 0; - if (xmssmt_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + /* check for secret key update function */ + if (secret_key->secure_store_scrt_key == NULL) { return OQS_ERROR; } - *signature_len = (size_t) sig_length; - return OQS_SUCCESS; + /* Lock secret to ensure OTS use */ + if ((secret_key->lock_key) && (secret_key->mutex)) { + secret_key->lock_key(secret_key->mutex); + } + + if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + status = OQS_ERROR; + goto err; + } + *signature_len = (size_t)sig_length; + + /* + * serialize and securely store the updated private key + * but, delete signature and the serialized key other wise + */ + + sk = secret_key; + rc_keyupdate = OQS_SECRET_KEY_XMSS_serialize_key(sk, &sk_key_buf_len, &sk_key_buf_ptr); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + goto err; + } + + rc_keyupdate = secret_key->secure_store_scrt_key(sk_key_buf_ptr, sk_key_buf_len, secret_key->context); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + } + + OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len); +err: + /* Unlock secret to ensure OTS use */ + if ((secret_key->unlock_key) && (secret_key->mutex)) { + secret_key->unlock_key(secret_key->mutex); + } + return status; } OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_sha256_h20_2_verify(XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, const uint8_t *signature, size_t signature_len, XMSS_UNUSED_ATT const uint8_t *public_key) { diff --git a/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h20_4.c b/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h20_4.c index efa097b262..76febd3103 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h20_4.c +++ b/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h20_4.c @@ -67,6 +67,8 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSSMT_SHA256_H20_4_new(void) { sk->free_key = OQS_SECRET_KEY_XMSS_free; + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_XMSS_set_store_cb; + return sk; } @@ -86,17 +88,56 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_sha256_h20_4_keypair(XMSS_UNUSED_ATT OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_sha256_h20_4_sign(uint8_t *signature, size_t *signature_len, XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, XMSS_UNUSED_ATT OQS_SIG_STFL_SECRET_KEY *secret_key) { + OQS_STATUS rc_keyupdate, status = OQS_SUCCESS; + const OQS_SIG_STFL_SECRET_KEY *sk; + uint8_t *sk_key_buf_ptr = NULL; + unsigned long long sig_length = 0; + size_t sk_key_buf_len = 0; + if (signature == NULL || signature_len == NULL || message == NULL || secret_key == NULL || secret_key->secret_key_data == NULL) { return OQS_ERROR; } - unsigned long long sig_length = 0; - if (xmssmt_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + /* check for secret key update function */ + if (secret_key->secure_store_scrt_key == NULL) { return OQS_ERROR; } - *signature_len = (size_t) sig_length; - return OQS_SUCCESS; + /* Lock secret to ensure OTS use */ + if ((secret_key->lock_key) && (secret_key->mutex)) { + secret_key->lock_key(secret_key->mutex); + } + + if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + status = OQS_ERROR; + goto err; + } + *signature_len = (size_t)sig_length; + + /* + * serialize and securely store the updated private key + * but, delete signature and the serialized key other wise + */ + + sk = secret_key; + rc_keyupdate = OQS_SECRET_KEY_XMSS_serialize_key(sk, &sk_key_buf_len, &sk_key_buf_ptr); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + goto err; + } + + rc_keyupdate = secret_key->secure_store_scrt_key(sk_key_buf_ptr, sk_key_buf_len, secret_key->context); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + } + + OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len); +err: + /* Unlock secret to ensure OTS use */ + if ((secret_key->unlock_key) && (secret_key->mutex)) { + secret_key->unlock_key(secret_key->mutex); + } + return status; } OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_sha256_h20_4_verify(XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, const uint8_t *signature, size_t signature_len, XMSS_UNUSED_ATT const uint8_t *public_key) { diff --git a/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h40_2.c b/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h40_2.c index 04c8fd52fb..b2b39b51ec 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h40_2.c +++ b/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h40_2.c @@ -67,6 +67,8 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSSMT_SHA256_H40_2_new(void) { sk->free_key = OQS_SECRET_KEY_XMSS_free; + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_XMSS_set_store_cb; + return sk; } @@ -86,17 +88,57 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_sha256_h40_2_keypair(XMSS_UNUSED_ATT OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_sha256_h40_2_sign(uint8_t *signature, size_t *signature_len, XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, XMSS_UNUSED_ATT OQS_SIG_STFL_SECRET_KEY *secret_key) { + OQS_STATUS rc_keyupdate, status = OQS_SUCCESS; + const OQS_SIG_STFL_SECRET_KEY *sk; + uint8_t *sk_key_buf_ptr = NULL; + unsigned long long sig_length = 0; + size_t sk_key_buf_len = 0; + if (signature == NULL || signature_len == NULL || message == NULL || secret_key == NULL || secret_key->secret_key_data == NULL) { return OQS_ERROR; } - unsigned long long sig_length = 0; - if (xmssmt_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + /* check for secret key update function */ + if (secret_key->secure_store_scrt_key == NULL) { + fprintf(stderr, "No secret key secure-store set.\n"); return OQS_ERROR; } - *signature_len = (size_t) sig_length; - return OQS_SUCCESS; + /* Lock secret to ensure OTS use */ + if ((secret_key->lock_key) && (secret_key->mutex)) { + secret_key->lock_key(secret_key->mutex); + } + + if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + status = OQS_ERROR; + goto err; + } + *signature_len = (size_t)sig_length; + + /* + * serialize and securely store the updated private key + * but, delete signature and the serialized key other wise + */ + + sk = secret_key; + rc_keyupdate = OQS_SECRET_KEY_XMSS_serialize_key(sk, &sk_key_buf_len, &sk_key_buf_ptr); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + goto err; + } + + rc_keyupdate = secret_key->secure_store_scrt_key(sk_key_buf_ptr, sk_key_buf_len, secret_key->context); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + } + + OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len); +err: + /* Unlock secret to ensure OTS use */ + if ((secret_key->unlock_key) && (secret_key->mutex)) { + secret_key->unlock_key(secret_key->mutex); + } + return status; } OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_sha256_h40_2_verify(XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, const uint8_t *signature, size_t signature_len, XMSS_UNUSED_ATT const uint8_t *public_key) { diff --git a/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h40_4.c b/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h40_4.c index dfa69325e8..4781f49cfe 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h40_4.c +++ b/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h40_4.c @@ -67,6 +67,8 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSSMT_SHA256_H40_4_new(void) { sk->free_key = OQS_SECRET_KEY_XMSS_free; + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_XMSS_set_store_cb; + return sk; } @@ -86,17 +88,56 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_sha256_h40_4_keypair(XMSS_UNUSED_ATT OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_sha256_h40_4_sign(uint8_t *signature, size_t *signature_len, XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, XMSS_UNUSED_ATT OQS_SIG_STFL_SECRET_KEY *secret_key) { + OQS_STATUS rc_keyupdate, status = OQS_SUCCESS; + const OQS_SIG_STFL_SECRET_KEY *sk; + uint8_t *sk_key_buf_ptr = NULL; + unsigned long long sig_length = 0; + size_t sk_key_buf_len = 0; + if (signature == NULL || signature_len == NULL || message == NULL || secret_key == NULL || secret_key->secret_key_data == NULL) { return OQS_ERROR; } - unsigned long long sig_length = 0; - if (xmssmt_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + /* check for secret key update function */ + if (secret_key->secure_store_scrt_key == NULL) { return OQS_ERROR; } - *signature_len = (size_t) sig_length; - return OQS_SUCCESS; + /* Lock secret to ensure OTS use */ + if ((secret_key->lock_key) && (secret_key->mutex)) { + secret_key->lock_key(secret_key->mutex); + } + + if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + status = OQS_ERROR; + goto err; + } + *signature_len = (size_t)sig_length; + + /* + * serialize and securely store the updated private key + * but, delete signature and the serialized key other wise + */ + + sk = secret_key; + rc_keyupdate = OQS_SECRET_KEY_XMSS_serialize_key(sk, &sk_key_buf_len, &sk_key_buf_ptr); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + goto err; + } + + rc_keyupdate = secret_key->secure_store_scrt_key(sk_key_buf_ptr, sk_key_buf_len, secret_key->context); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + } + + OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len); +err: + /* Unlock secret to ensure OTS use */ + if ((secret_key->unlock_key) && (secret_key->mutex)) { + secret_key->unlock_key(secret_key->mutex); + } + return status; } OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_sha256_h40_4_verify(XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, const uint8_t *signature, size_t signature_len, XMSS_UNUSED_ATT const uint8_t *public_key) { diff --git a/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h40_8.c b/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h40_8.c index 7b4640ed40..2acbc1046e 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h40_8.c +++ b/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h40_8.c @@ -67,6 +67,8 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSSMT_SHA256_H40_8_new(void) { sk->free_key = OQS_SECRET_KEY_XMSS_free; + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_XMSS_set_store_cb; + return sk; } @@ -86,17 +88,56 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_sha256_h40_8_keypair(XMSS_UNUSED_ATT OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_sha256_h40_8_sign(uint8_t *signature, size_t *signature_len, XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, XMSS_UNUSED_ATT OQS_SIG_STFL_SECRET_KEY *secret_key) { + OQS_STATUS rc_keyupdate, status = OQS_SUCCESS; + const OQS_SIG_STFL_SECRET_KEY *sk; + uint8_t *sk_key_buf_ptr = NULL; + unsigned long long sig_length = 0; + size_t sk_key_buf_len = 0; + if (signature == NULL || signature_len == NULL || message == NULL || secret_key == NULL || secret_key->secret_key_data == NULL) { return OQS_ERROR; } - unsigned long long sig_length = 0; - if (xmssmt_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + /* check for secret key update function */ + if (secret_key->secure_store_scrt_key == NULL) { return OQS_ERROR; } - *signature_len = (size_t) sig_length; - return OQS_SUCCESS; + /* Lock secret to ensure OTS use */ + if ((secret_key->lock_key) && (secret_key->mutex)) { + secret_key->lock_key(secret_key->mutex); + } + + if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + status = OQS_ERROR; + goto err; + } + *signature_len = (size_t)sig_length; + + /* + * serialize and securely store the updated private key + * but, delete signature and the serialized key other wise + */ + + sk = secret_key; + rc_keyupdate = OQS_SECRET_KEY_XMSS_serialize_key(sk, &sk_key_buf_len, &sk_key_buf_ptr); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + goto err; + } + + rc_keyupdate = secret_key->secure_store_scrt_key(sk_key_buf_ptr, sk_key_buf_len, secret_key->context); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + } + + OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len); +err: + /* Unlock secret to ensure OTS use */ + if ((secret_key->unlock_key) && (secret_key->mutex)) { + secret_key->unlock_key(secret_key->mutex); + } + return status; } OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_sha256_h40_8_verify(XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, const uint8_t *signature, size_t signature_len, XMSS_UNUSED_ATT const uint8_t *public_key) { diff --git a/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h60_12.c b/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h60_12.c index 84f0f589d3..d9b98a749f 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h60_12.c +++ b/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h60_12.c @@ -67,6 +67,8 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSSMT_SHA256_H60_12_new(void) { sk->free_key = OQS_SECRET_KEY_XMSS_free; + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_XMSS_set_store_cb; + return sk; } @@ -86,17 +88,57 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_sha256_h60_12_keypair(XMSS_UNUSED_ATT OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_sha256_h60_12_sign(uint8_t *signature, size_t *signature_len, XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, XMSS_UNUSED_ATT OQS_SIG_STFL_SECRET_KEY *secret_key) { + + OQS_STATUS rc_keyupdate, status = OQS_SUCCESS; + const OQS_SIG_STFL_SECRET_KEY *sk; + uint8_t *sk_key_buf_ptr = NULL; + unsigned long long sig_length = 0; + size_t sk_key_buf_len = 0; + if (signature == NULL || signature_len == NULL || message == NULL || secret_key == NULL || secret_key->secret_key_data == NULL) { return OQS_ERROR; } - unsigned long long sig_length = 0; - if (xmssmt_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + /* check for secret key update function */ + if (secret_key->secure_store_scrt_key == NULL) { return OQS_ERROR; } - *signature_len = (size_t) sig_length; - return OQS_SUCCESS; + /* Lock secret to ensure OTS use */ + if ((secret_key->lock_key) && (secret_key->mutex)) { + secret_key->lock_key(secret_key->mutex); + } + + if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + status = OQS_ERROR; + goto err; + } + *signature_len = (size_t)sig_length; + + /* + * serialize and securely store the updated private key + * but, delete signature and the serialized key other wise + */ + + sk = secret_key; + rc_keyupdate = OQS_SECRET_KEY_XMSS_serialize_key(sk, &sk_key_buf_len, &sk_key_buf_ptr); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + goto err; + } + + rc_keyupdate = secret_key->secure_store_scrt_key(sk_key_buf_ptr, sk_key_buf_len, secret_key->context); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + } + + OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len); +err: + /* Unlock secret to ensure OTS use */ + if ((secret_key->unlock_key) && (secret_key->mutex)) { + secret_key->unlock_key(secret_key->mutex); + } + return status; } OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_sha256_h60_12_verify(XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, const uint8_t *signature, size_t signature_len, XMSS_UNUSED_ATT const uint8_t *public_key) { diff --git a/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h60_3.c b/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h60_3.c index c9616932eb..c45fef5959 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h60_3.c +++ b/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h60_3.c @@ -67,6 +67,8 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSSMT_SHA256_H60_3_new(void) { sk->free_key = OQS_SECRET_KEY_XMSS_free; + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_XMSS_set_store_cb; + return sk; } @@ -86,17 +88,56 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_sha256_h60_3_keypair(XMSS_UNUSED_ATT OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_sha256_h60_3_sign(uint8_t *signature, size_t *signature_len, XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, XMSS_UNUSED_ATT OQS_SIG_STFL_SECRET_KEY *secret_key) { + OQS_STATUS rc_keyupdate, status = OQS_SUCCESS; + const OQS_SIG_STFL_SECRET_KEY *sk; + uint8_t *sk_key_buf_ptr = NULL; + unsigned long long sig_length = 0; + size_t sk_key_buf_len = 0; + if (signature == NULL || signature_len == NULL || message == NULL || secret_key == NULL || secret_key->secret_key_data == NULL) { return OQS_ERROR; } - unsigned long long sig_length = 0; - if (xmssmt_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + /* check for secret key update function */ + if (secret_key->secure_store_scrt_key == NULL) { return OQS_ERROR; } - *signature_len = (size_t) sig_length; - return OQS_SUCCESS; + /* Lock secret to ensure OTS use */ + if ((secret_key->lock_key) && (secret_key->mutex)) { + secret_key->lock_key(secret_key->mutex); + } + + if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + status = OQS_ERROR; + goto err; + } + *signature_len = (size_t)sig_length; + + /* + * serialize and securely store the updated private key + * but, delete signature and the serialized key other wise + */ + + sk = secret_key; + rc_keyupdate = OQS_SECRET_KEY_XMSS_serialize_key(sk, &sk_key_buf_len, &sk_key_buf_ptr); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + goto err; + } + + rc_keyupdate = secret_key->secure_store_scrt_key(sk_key_buf_ptr, sk_key_buf_len, secret_key->context); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + } + + OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len); +err: + /* Unlock secret to ensure OTS use */ + if ((secret_key->unlock_key) && (secret_key->mutex)) { + secret_key->unlock_key(secret_key->mutex); + } + return status; } OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_sha256_h60_3_verify(XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, const uint8_t *signature, size_t signature_len, XMSS_UNUSED_ATT const uint8_t *public_key) { diff --git a/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h60_6.c b/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h60_6.c index 7ab46f56ad..f43f87c6b4 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h60_6.c +++ b/src/sig_stfl/xmss/sig_stfl_xmssmt_sha256_h60_6.c @@ -67,6 +67,8 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSSMT_SHA256_H60_6_new(void) { sk->free_key = OQS_SECRET_KEY_XMSS_free; + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_XMSS_set_store_cb; + return sk; } @@ -86,17 +88,56 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_sha256_h60_6_keypair(XMSS_UNUSED_ATT OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_sha256_h60_6_sign(uint8_t *signature, size_t *signature_len, XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, XMSS_UNUSED_ATT OQS_SIG_STFL_SECRET_KEY *secret_key) { + OQS_STATUS rc_keyupdate, status = OQS_SUCCESS; + const OQS_SIG_STFL_SECRET_KEY *sk; + uint8_t *sk_key_buf_ptr = NULL; + unsigned long long sig_length = 0; + size_t sk_key_buf_len = 0; + if (signature == NULL || signature_len == NULL || message == NULL || secret_key == NULL || secret_key->secret_key_data == NULL) { return OQS_ERROR; } - unsigned long long sig_length = 0; - if (xmssmt_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + /* check for secret key update function */ + if (secret_key->secure_store_scrt_key == NULL) { return OQS_ERROR; } - *signature_len = (size_t) sig_length; - return OQS_SUCCESS; + /* Lock secret to ensure OTS use */ + if ((secret_key->lock_key) && (secret_key->mutex)) { + secret_key->lock_key(secret_key->mutex); + } + + if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + status = OQS_ERROR; + goto err; + } + *signature_len = (size_t)sig_length; + + /* + * serialize and securely store the updated private key + * but, delete signature and the serialized key other wise + */ + + sk = secret_key; + rc_keyupdate = OQS_SECRET_KEY_XMSS_serialize_key(sk, &sk_key_buf_len, &sk_key_buf_ptr); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + goto err; + } + + rc_keyupdate = secret_key->secure_store_scrt_key(sk_key_buf_ptr, sk_key_buf_len, secret_key->context); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + } + + OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len); +err: + /* Unlock secret to ensure OTS use */ + if ((secret_key->unlock_key) && (secret_key->mutex)) { + secret_key->unlock_key(secret_key->mutex); + } + return status; } OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_sha256_h60_6_verify(XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, const uint8_t *signature, size_t signature_len, XMSS_UNUSED_ATT const uint8_t *public_key) { diff --git a/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h20_2.c b/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h20_2.c index 19421bb2ae..16d7270593 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h20_2.c +++ b/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h20_2.c @@ -67,6 +67,8 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSSMT_SHAKE128_H20_2_new(void) { sk->free_key = OQS_SECRET_KEY_XMSS_free; + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_XMSS_set_store_cb; + return sk; } @@ -86,17 +88,56 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_shake128_h20_2_keypair(XMSS_UNUSED_AT OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_shake128_h20_2_sign(uint8_t *signature, size_t *signature_len, XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, XMSS_UNUSED_ATT OQS_SIG_STFL_SECRET_KEY *secret_key) { + OQS_STATUS rc_keyupdate, status = OQS_SUCCESS; + const OQS_SIG_STFL_SECRET_KEY *sk; + uint8_t *sk_key_buf_ptr = NULL; + unsigned long long sig_length = 0; + size_t sk_key_buf_len = 0; + if (signature == NULL || signature_len == NULL || message == NULL || secret_key == NULL || secret_key->secret_key_data == NULL) { return OQS_ERROR; } - unsigned long long sig_length = 0; - if (xmssmt_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + /* check for secret key update function */ + if (secret_key->secure_store_scrt_key == NULL) { return OQS_ERROR; } - *signature_len = (size_t) sig_length; - return OQS_SUCCESS; + /* Lock secret to ensure OTS use */ + if ((secret_key->lock_key) && (secret_key->mutex)) { + secret_key->lock_key(secret_key->mutex); + } + + if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + status = OQS_ERROR; + goto err; + } + *signature_len = (size_t)sig_length; + + /* + * serialize and securely store the updated private key + * but, delete signature and the serialized key other wise + */ + + sk = secret_key; + rc_keyupdate = OQS_SECRET_KEY_XMSS_serialize_key(sk, &sk_key_buf_len, &sk_key_buf_ptr); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + goto err; + } + + rc_keyupdate = secret_key->secure_store_scrt_key(sk_key_buf_ptr, sk_key_buf_len, secret_key->context); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + } + + OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len); +err: + /* Unlock secret to ensure OTS use */ + if ((secret_key->unlock_key) && (secret_key->mutex)) { + secret_key->unlock_key(secret_key->mutex); + } + return status; } OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_shake128_h20_2_verify(XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, const uint8_t *signature, size_t signature_len, XMSS_UNUSED_ATT const uint8_t *public_key) { diff --git a/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h20_4.c b/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h20_4.c index 1b51a87c76..941a2ecb3c 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h20_4.c +++ b/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h20_4.c @@ -67,6 +67,8 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSSMT_SHAKE128_H20_4_new(void) { sk->free_key = OQS_SECRET_KEY_XMSS_free; + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_XMSS_set_store_cb; + return sk; } @@ -86,17 +88,56 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_shake128_h20_4_keypair(XMSS_UNUSED_AT OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_shake128_h20_4_sign(uint8_t *signature, size_t *signature_len, XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, XMSS_UNUSED_ATT OQS_SIG_STFL_SECRET_KEY *secret_key) { + OQS_STATUS rc_keyupdate, status = OQS_SUCCESS; + const OQS_SIG_STFL_SECRET_KEY *sk; + uint8_t *sk_key_buf_ptr = NULL; + unsigned long long sig_length = 0; + size_t sk_key_buf_len = 0; + if (signature == NULL || signature_len == NULL || message == NULL || secret_key == NULL || secret_key->secret_key_data == NULL) { return OQS_ERROR; } - unsigned long long sig_length = 0; - if (xmssmt_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + /* check for secret key update function */ + if (secret_key->secure_store_scrt_key == NULL) { return OQS_ERROR; } - *signature_len = (size_t) sig_length; - return OQS_SUCCESS; + /* Lock secret to ensure OTS use */ + if ((secret_key->lock_key) && (secret_key->mutex)) { + secret_key->lock_key(secret_key->mutex); + } + + if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + status = OQS_ERROR; + goto err; + } + *signature_len = (size_t)sig_length; + + /* + * serialize and securely store the updated private key + * but, delete signature and the serialized key other wise + */ + + sk = secret_key; + rc_keyupdate = OQS_SECRET_KEY_XMSS_serialize_key(sk, &sk_key_buf_len, &sk_key_buf_ptr); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + goto err; + } + + rc_keyupdate = secret_key->secure_store_scrt_key(sk_key_buf_ptr, sk_key_buf_len, secret_key->context); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + } + + OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len); +err: + /* Unlock secret to ensure OTS use */ + if ((secret_key->unlock_key) && (secret_key->mutex)) { + secret_key->unlock_key(secret_key->mutex); + } + return status; } OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_shake128_h20_4_verify(XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, const uint8_t *signature, size_t signature_len, XMSS_UNUSED_ATT const uint8_t *public_key) { diff --git a/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h40_2.c b/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h40_2.c index 8e3617fbd0..adc47b4d11 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h40_2.c +++ b/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h40_2.c @@ -67,6 +67,8 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSSMT_SHAKE128_H40_2_new(void) { sk->free_key = OQS_SECRET_KEY_XMSS_free; + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_XMSS_set_store_cb; + return sk; } @@ -86,17 +88,56 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_shake128_h40_2_keypair(XMSS_UNUSED_AT OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_shake128_h40_2_sign(uint8_t *signature, size_t *signature_len, XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, XMSS_UNUSED_ATT OQS_SIG_STFL_SECRET_KEY *secret_key) { + OQS_STATUS rc_keyupdate, status = OQS_SUCCESS; + const OQS_SIG_STFL_SECRET_KEY *sk; + uint8_t *sk_key_buf_ptr = NULL; + unsigned long long sig_length = 0; + size_t sk_key_buf_len = 0; + if (signature == NULL || signature_len == NULL || message == NULL || secret_key == NULL || secret_key->secret_key_data == NULL) { return OQS_ERROR; } - unsigned long long sig_length = 0; - if (xmssmt_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + /* check for secret key update function */ + if (secret_key->secure_store_scrt_key == NULL) { return OQS_ERROR; } - *signature_len = (size_t) sig_length; - return OQS_SUCCESS; + /* Lock secret to ensure OTS use */ + if ((secret_key->lock_key) && (secret_key->mutex)) { + secret_key->lock_key(secret_key->mutex); + } + + if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + status = OQS_ERROR; + goto err; + } + *signature_len = (size_t)sig_length; + + /* + * serialize and securely store the updated private key + * but, delete signature and the serialized key other wise + */ + + sk = secret_key; + rc_keyupdate = OQS_SECRET_KEY_XMSS_serialize_key(sk, &sk_key_buf_len, &sk_key_buf_ptr); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + goto err; + } + + rc_keyupdate = secret_key->secure_store_scrt_key(sk_key_buf_ptr, sk_key_buf_len, secret_key->context); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + } + + OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len); +err: + /* Unlock secret to ensure OTS use */ + if ((secret_key->unlock_key) && (secret_key->mutex)) { + secret_key->unlock_key(secret_key->mutex); + } + return status; } OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_shake128_h40_2_verify(XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, const uint8_t *signature, size_t signature_len, XMSS_UNUSED_ATT const uint8_t *public_key) { diff --git a/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h40_4.c b/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h40_4.c index 9a5f66ccef..3312f25477 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h40_4.c +++ b/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h40_4.c @@ -67,6 +67,8 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSSMT_SHAKE128_H40_4_new(void) { sk->free_key = OQS_SECRET_KEY_XMSS_free; + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_XMSS_set_store_cb; + return sk; } @@ -86,17 +88,56 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_shake128_h40_4_keypair(XMSS_UNUSED_AT OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_shake128_h40_4_sign(uint8_t *signature, size_t *signature_len, XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, XMSS_UNUSED_ATT OQS_SIG_STFL_SECRET_KEY *secret_key) { + OQS_STATUS rc_keyupdate, status = OQS_SUCCESS; + const OQS_SIG_STFL_SECRET_KEY *sk; + uint8_t *sk_key_buf_ptr = NULL; + unsigned long long sig_length = 0; + size_t sk_key_buf_len = 0; + if (signature == NULL || signature_len == NULL || message == NULL || secret_key == NULL || secret_key->secret_key_data == NULL) { return OQS_ERROR; } - unsigned long long sig_length = 0; - if (xmssmt_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + /* check for secret key update function */ + if (secret_key->secure_store_scrt_key == NULL) { return OQS_ERROR; } - *signature_len = (size_t) sig_length; - return OQS_SUCCESS; + /* Lock secret to ensure OTS use */ + if ((secret_key->lock_key) && (secret_key->mutex)) { + secret_key->lock_key(secret_key->mutex); + } + + if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + status = OQS_ERROR; + goto err; + } + *signature_len = (size_t)sig_length; + + /* + * serialize and securely store the updated private key + * but, delete signature and the serialized key other wise + */ + + sk = secret_key; + rc_keyupdate = OQS_SECRET_KEY_XMSS_serialize_key(sk, &sk_key_buf_len, &sk_key_buf_ptr); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + goto err; + } + + rc_keyupdate = secret_key->secure_store_scrt_key(sk_key_buf_ptr, sk_key_buf_len, secret_key->context); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + } + + OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len); +err: + /* Unlock secret to ensure OTS use */ + if ((secret_key->unlock_key) && (secret_key->mutex)) { + secret_key->unlock_key(secret_key->mutex); + } + return status; } OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_shake128_h40_4_verify(XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, const uint8_t *signature, size_t signature_len, XMSS_UNUSED_ATT const uint8_t *public_key) { diff --git a/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h40_8.c b/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h40_8.c index 9b6fc160ed..43afdfeeff 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h40_8.c +++ b/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h40_8.c @@ -67,6 +67,8 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSSMT_SHAKE128_H40_8_new(void) { sk->free_key = OQS_SECRET_KEY_XMSS_free; + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_XMSS_set_store_cb; + return sk; } @@ -86,17 +88,56 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_shake128_h40_8_keypair(XMSS_UNUSED_AT OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_shake128_h40_8_sign(uint8_t *signature, size_t *signature_len, XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, XMSS_UNUSED_ATT OQS_SIG_STFL_SECRET_KEY *secret_key) { + OQS_STATUS rc_keyupdate, status = OQS_SUCCESS; + const OQS_SIG_STFL_SECRET_KEY *sk; + uint8_t *sk_key_buf_ptr = NULL; + unsigned long long sig_length = 0; + size_t sk_key_buf_len = 0; + if (signature == NULL || signature_len == NULL || message == NULL || secret_key == NULL || secret_key->secret_key_data == NULL) { return OQS_ERROR; } - unsigned long long sig_length = 0; - if (xmssmt_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + /* check for secret key update function */ + if (secret_key->secure_store_scrt_key == NULL) { return OQS_ERROR; } - *signature_len = (size_t) sig_length; - return OQS_SUCCESS; + /* Lock secret to ensure OTS use */ + if ((secret_key->lock_key) && (secret_key->mutex)) { + secret_key->lock_key(secret_key->mutex); + } + + if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + status = OQS_ERROR; + goto err; + } + *signature_len = (size_t)sig_length; + + /* + * serialize and securely store the updated private key + * but, delete signature and the serialized key other wise + */ + + sk = secret_key; + rc_keyupdate = OQS_SECRET_KEY_XMSS_serialize_key(sk, &sk_key_buf_len, &sk_key_buf_ptr); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + goto err; + } + + rc_keyupdate = secret_key->secure_store_scrt_key(sk_key_buf_ptr, sk_key_buf_len, secret_key->context); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + } + + OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len); +err: + /* Unlock secret to ensure OTS use */ + if ((secret_key->unlock_key) && (secret_key->mutex)) { + secret_key->unlock_key(secret_key->mutex); + } + return status; } OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_shake128_h40_8_verify(XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, const uint8_t *signature, size_t signature_len, XMSS_UNUSED_ATT const uint8_t *public_key) { diff --git a/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h60_12.c b/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h60_12.c index dfad288f23..bf7c0c56d2 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h60_12.c +++ b/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h60_12.c @@ -67,6 +67,8 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSSMT_SHAKE128_H60_12_new(void) { sk->free_key = OQS_SECRET_KEY_XMSS_free; + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_XMSS_set_store_cb; + return sk; } @@ -86,17 +88,56 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_shake128_h60_12_keypair(XMSS_UNUSED_A OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_shake128_h60_12_sign(uint8_t *signature, size_t *signature_len, XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, XMSS_UNUSED_ATT OQS_SIG_STFL_SECRET_KEY *secret_key) { + OQS_STATUS rc_keyupdate, status = OQS_SUCCESS; + const OQS_SIG_STFL_SECRET_KEY *sk; + uint8_t *sk_key_buf_ptr = NULL; + unsigned long long sig_length = 0; + size_t sk_key_buf_len = 0; + if (signature == NULL || signature_len == NULL || message == NULL || secret_key == NULL || secret_key->secret_key_data == NULL) { return OQS_ERROR; } - unsigned long long sig_length = 0; - if (xmssmt_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + /* check for secret key update function */ + if (secret_key->secure_store_scrt_key == NULL) { return OQS_ERROR; } - *signature_len = (size_t) sig_length; - return OQS_SUCCESS; + /* Lock secret to ensure OTS use */ + if ((secret_key->lock_key) && (secret_key->mutex)) { + secret_key->lock_key(secret_key->mutex); + } + + if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + status = OQS_ERROR; + goto err; + } + *signature_len = (size_t)sig_length; + + /* + * serialize and securely store the updated private key + * but, delete signature and the serialized key other wise + */ + + sk = secret_key; + rc_keyupdate = OQS_SECRET_KEY_XMSS_serialize_key(sk, &sk_key_buf_len, &sk_key_buf_ptr); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + goto err; + } + + rc_keyupdate = secret_key->secure_store_scrt_key(sk_key_buf_ptr, sk_key_buf_len, secret_key->context); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + } + + OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len); +err: + /* Unlock secret to ensure OTS use */ + if ((secret_key->unlock_key) && (secret_key->mutex)) { + secret_key->unlock_key(secret_key->mutex); + } + return status; } OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_shake128_h60_12_verify(XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, const uint8_t *signature, size_t signature_len, XMSS_UNUSED_ATT const uint8_t *public_key) { diff --git a/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h60_3.c b/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h60_3.c index acd7b70165..f8b6ab6ec5 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h60_3.c +++ b/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h60_3.c @@ -67,6 +67,8 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSSMT_SHAKE128_H60_3_new(void) { sk->free_key = OQS_SECRET_KEY_XMSS_free; + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_XMSS_set_store_cb; + return sk; } @@ -86,17 +88,56 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_shake128_h60_3_keypair(XMSS_UNUSED_AT OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_shake128_h60_3_sign(uint8_t *signature, size_t *signature_len, XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, XMSS_UNUSED_ATT OQS_SIG_STFL_SECRET_KEY *secret_key) { + OQS_STATUS rc_keyupdate, status = OQS_SUCCESS; + const OQS_SIG_STFL_SECRET_KEY *sk; + uint8_t *sk_key_buf_ptr = NULL; + unsigned long long sig_length = 0; + size_t sk_key_buf_len = 0; + if (signature == NULL || signature_len == NULL || message == NULL || secret_key == NULL || secret_key->secret_key_data == NULL) { return OQS_ERROR; } - unsigned long long sig_length = 0; - if (xmssmt_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + /* check for secret key update function */ + if (secret_key->secure_store_scrt_key == NULL) { return OQS_ERROR; } - *signature_len = (size_t) sig_length; - return OQS_SUCCESS; + /* Lock secret to ensure OTS use */ + if ((secret_key->lock_key) && (secret_key->mutex)) { + secret_key->lock_key(secret_key->mutex); + } + + if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) { + status = OQS_ERROR; + goto err; + } + *signature_len = (size_t)sig_length; + + /* + * serialize and securely store the updated private key + * but, delete signature and the serialized key other wise + */ + + sk = secret_key; + rc_keyupdate = OQS_SECRET_KEY_XMSS_serialize_key(sk, &sk_key_buf_len, &sk_key_buf_ptr); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + goto err; + } + + rc_keyupdate = secret_key->secure_store_scrt_key(sk_key_buf_ptr, sk_key_buf_len, secret_key->context); + if (rc_keyupdate != OQS_SUCCESS) { + status = OQS_ERROR; + } + + OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len); +err: + /* Unlock secret to ensure OTS use */ + if ((secret_key->unlock_key) && (secret_key->mutex)) { + secret_key->unlock_key(secret_key->mutex); + } + return status; } OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_shake128_h60_3_verify(XMSS_UNUSED_ATT const uint8_t *message, XMSS_UNUSED_ATT size_t message_len, const uint8_t *signature, size_t signature_len, XMSS_UNUSED_ATT const uint8_t *public_key) { diff --git a/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h60_6.c b/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h60_6.c index 889e831775..1821340645 100644 --- a/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h60_6.c +++ b/src/sig_stfl/xmss/sig_stfl_xmssmt_shake128_h60_6.c @@ -67,6 +67,8 @@ OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSSMT_SHAKE128_H60_6_new(void) { sk->free_key = OQS_SECRET_KEY_XMSS_free; + sk->set_scrt_key_store_cb = OQS_SECRET_KEY_XMSS_set_store_cb; + return sk; } diff --git a/tests/kat_sig_stfl.c b/tests/kat_sig_stfl.c index a65bc66a53..9fdbeefe11 100644 --- a/tests/kat_sig_stfl.c +++ b/tests/kat_sig_stfl.c @@ -18,6 +18,12 @@ #define MAX_MARKER_LEN 50 +static OQS_STATUS do_nothing_save(uint8_t *key_buf, size_t buf_len, void *context) { + (void)(context); + (void)(buf_len); + return key_buf != NULL ? OQS_SUCCESS : OQS_ERROR; +} + // // ALLOW TO READ HEXADECIMAL ENTRY (KEYS, DATA, TEXT, etc.) // @@ -159,6 +165,8 @@ OQS_STATUS sig_stfl_kat(const char *method_name, const char *katfile) { // Grab the pk and sk from KAT file public_key = malloc(sig->length_public_key); secret_key = OQS_SIG_STFL_SECRET_KEY_new(sig->method_name); + OQS_SIG_STFL_SECRET_KEY_SET_store_cb(secret_key, do_nothing_save, NULL); + signature = calloc(sig->length_signature, sizeof(uint8_t)); signature_kat = calloc(sig->length_signature, sizeof(uint8_t)); diff --git a/tests/test_sig_stfl.c b/tests/test_sig_stfl.c index 9abd8dbe73..305001a462 100644 --- a/tests/test_sig_stfl.c +++ b/tests/test_sig_stfl.c @@ -322,6 +322,52 @@ typedef struct magic_s { uint8_t val[31]; } magic_t; +static char *convert_method_name_to_file_name(const char *method_name) { + + const char *file_store = NULL; + char *name = NULL; + if (strcmp(method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h20_2) == 0) { + file_store = "XMSSMT-SHA2_20-2_256"; + } else if (strcmp(method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h20_4) == 0) { + file_store = "XMSSMT-SHA2_20-4_256"; + } else if (strcmp(method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h40_2) == 0) { + file_store = "XMSSMT-SHA2_40-2_256"; + } else if (strcmp(method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h40_4) == 0) { + file_store = "XMSSMT-SHA2_40-4_256"; + } else if (strcmp(method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h40_8) == 0) { + file_store = "XMSSMT-SHA2_40-8_256"; + } else if (strcmp(method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h60_3) == 0) { + file_store = "XMSSMT-SHA2_60-3_256"; + } else if (strcmp(method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h60_6) == 0) { + file_store = "XMSSMT-SHA2_60-6_256"; + } else if (strcmp(method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h60_12) == 0) { + file_store = "XMSSMT-SHA2_60-12_256"; + } else if (strcmp(method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h20_2) == 0) { + file_store = "XMSSMT-SHAKE_20-2_256"; + } else if (strcmp(method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h20_4) == 0) { + file_store = "XMSSMT-SHAKE_20-4_256"; + } else if (strcmp(method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h40_2) == 0) { + file_store = "XMSSMT-SHAKE_40-2_256"; + } else if (strcmp(method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h40_4) == 0) { + file_store = "XMSSMT-SHAKE_40-4_256"; + } else if (strcmp(method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h40_8) == 0) { + file_store = "XMSSMT-SHAKE_40-8_256"; + } else if (strcmp(method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h60_3) == 0) { + file_store = "XMSSMT-SHAKE_60-3_256"; + } else if (strcmp(method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h60_6) == 0) { + file_store = "XMSSMT-SHAKE_60-6_256"; + } else if (strcmp(method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h60_12) == 0) { + file_store = "XMSSMT-SHAKE_60-12_256"; + } else { + file_store = method_name; + } + + if (file_store) { + name = strdup(file_store); + } + return name; +} + static OQS_STATUS sig_stfl_test_correctness(const char *method_name, const char *katfile) { OQS_SIG_STFL *sig = NULL; @@ -337,19 +383,86 @@ 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; + char *file_store = NULL; size_t sk_buf_len = 0; size_t read_pk_len = 0; + magic_t magic; + #if OQS_USE_PTHREADS_IN_TESTS pthread_mutex_t *sk_lock = NULL; #endif OQS_STATUS rc, ret = OQS_ERROR; + if (0) { + +#ifdef OQS_ENABLE_SIG_STFL_xmss_sha256_h16 + } else if (strcmp(method_name, OQS_SIG_STFL_alg_xmss_sha256_h16) == 0) { + goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmss_sha256_h20 + } else if (strcmp(method_name, OQS_SIG_STFL_alg_xmss_sha256_h20) == 0) { + goto skip_test; +#endif + +#ifdef OQS_ENABLE_SIG_STFL_xmss_shake128_h16 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_shake128_h16)) { + goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmss_shake128_h20 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_shake128_h20)) { + goto skip_test; +#endif + +#ifdef OQS_ENABLE_SIG_STFL_xmss_sha512_h16 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_sha512_h16)) { + goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmss_sha512_h20 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_sha512_h20)) { + goto skip_test; +#endif + +#ifdef OQS_ENABLE_SIG_STFL_xmss_shake256_h16 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_shake256_h16)) { + goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmss_shake256_h20 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_shake256_h20)) { + goto skip_test; +#endif + +#ifdef OQS_ENABLE_SIG_STFL_xmssmt_sha256_h40_2 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h40_2)) { + goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmssmt_sha256_h60_3 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h60_3)) { + goto skip_test; +#endif + +#ifdef OQS_ENABLE_SIG_STFL_xmssmt_shake128_h40_2 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h40_2)) { + goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmssmt_shake128_h60_3 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h60_3)) { + goto skip_test; +#endif + } else { + goto test_on; + } +skip_test: + printf("skipping slow test %s\n", method_name); + return OQS_SUCCESS; + +test_on: + //The magic numbers are random values. //The length of the magic number was chosen to be 31 to break alignment - magic_t magic; + + OQS_randombytes(magic.val, sizeof(magic_t)); sig = OQS_SIG_STFL_new(method_name); @@ -368,6 +481,16 @@ static OQS_STATUS sig_stfl_test_correctness(const char *method_name, const char OQS_SIG_STFL_SECRET_KEY_SET_lock(secret_key, lock_sk_key); OQS_SIG_STFL_SECRET_KEY_SET_unlock(secret_key, unlock_sk_key); + file_store = convert_method_name_to_file_name(sig->method_name); + if (file_store == NULL) { + fprintf(stderr, "%s: file_store is null\n", __FUNCTION__); + goto err; + } + + /* set context and secure store callback */ + context = strdup(((file_store))); + OQS_SIG_STFL_SECRET_KEY_SET_store_cb(secret_key, test_save_secret_key, (void *)context); + #if OQS_USE_PTHREADS_IN_TESTS sk_lock = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t)); if (sk_lock == NULL) { @@ -421,42 +544,6 @@ static OQS_STATUS sig_stfl_test_correctness(const char *method_name, const char goto err; } - 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; @@ -466,10 +553,6 @@ static OQS_STATUS sig_stfl_test_correctness(const char *method_name, const char goto err; } - /* set context and secure store callback */ - 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); OQS_TEST_CT_DECLASSIFY(&rc, sizeof rc); if (rc != OQS_SUCCESS) { @@ -545,6 +628,7 @@ static OQS_STATUS sig_stfl_test_correctness(const char *method_name, const char OQS_MEM_insecure_free(read_pk_buf); OQS_MEM_insecure_free(context); + OQS_MEM_insecure_free(file_store); #if OQS_USE_PTHREADS_IN_TESTS if (sk_lock) { @@ -568,81 +652,70 @@ static OQS_STATUS sig_stfl_test_secret_key(const char *method_name) { size_t to_file_sk_len = 0; char *context = NULL; char *context_2 = NULL; + char *file_store_name = NULL; /* * Temporarily skip algs with long key generation times. */ - if (strcmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h5_w1) == 0 - || strcmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h5_w2) == 0 - || strcmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h5_w4) == 0 - || strcmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h5_w8) == 0 + if (0) { - || strcmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h10_w1) == 0 - || strcmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h15_w1) == 0) { - goto keep_going; - } else { +#ifdef OQS_ENABLE_SIG_STFL_xmss_sha256_h16 + } else if (strcmp(method_name, OQS_SIG_STFL_alg_xmss_sha256_h16) == 0) { goto skip_test; - } +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmss_sha256_h20 + } else if (strcmp(method_name, OQS_SIG_STFL_alg_xmss_sha256_h20) == 0) { + goto skip_test; +#endif -// if (0) { -// -//#ifdef OQS_ENABLE_SIG_STFL_xmss_sha256_h16 -// } else if (strcmp(method_name, OQS_SIG_STFL_alg_xmss_sha256_h16) == 0) { -// goto skip_test; -//#endif -//#ifdef OQS_ENABLE_SIG_STFL_xmss_sha256_h20 -// } else if (strcmp(method_name, OQS_SIG_STFL_alg_xmss_sha256_h20) == 0) { -// goto skip_test; -//#endif -// -//#ifdef OQS_ENABLE_SIG_STFL_xmss_shake128_h16 -// } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_shake128_h16)) { -// goto skip_test; -//#endif -//#ifdef OQS_ENABLE_SIG_STFL_xmss_shake128_h20 -// } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_shake128_h20)) { -// goto skip_test; -//#endif -// -//#ifdef OQS_ENABLE_SIG_STFL_xmss_sha512_h16 -// } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_sha512_h16)) { -// goto skip_test; -//#endif -//#ifdef OQS_ENABLE_SIG_STFL_xmss_sha512_h20 -// } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_sha512_h20)) { -// goto skip_test; -//#endif -// -//#ifdef OQS_ENABLE_SIG_STFL_xmss_shake256_h16 -// } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_shake256_h16)) { -// goto skip_test; -//#endif -//#ifdef OQS_ENABLE_SIG_STFL_xmss_shake256_h20 -// } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_shake256_h20)) { -// goto skip_test; -//#endif -// -//#ifdef OQS_ENABLE_SIG_STFL_xmssmt_sha256_h40_2 -// } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h40_2)) { -// goto skip_test; -//#endif -//#ifdef OQS_ENABLE_SIG_STFL_xmssmt_sha256_h60_3 -// } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h60_3)) { -// goto skip_test; -//#endif -// -//#ifdef OQS_ENABLE_SIG_STFL_xmssmt_shake128_h40_2 -// } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h40_2)) { -// goto skip_test; -//#endif -//#ifdef OQS_ENABLE_SIG_STFL_xmssmt_shake128_h60_3 -// } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h60_3)) { -// goto skip_test; -//#endif -// } else { -// goto keep_going; -// } +#ifdef OQS_ENABLE_SIG_STFL_xmss_shake128_h16 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_shake128_h16)) { + goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmss_shake128_h20 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_shake128_h20)) { + goto skip_test; +#endif + +#ifdef OQS_ENABLE_SIG_STFL_xmss_sha512_h16 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_sha512_h16)) { + goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmss_sha512_h20 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_sha512_h20)) { + goto skip_test; +#endif + +#ifdef OQS_ENABLE_SIG_STFL_xmss_shake256_h16 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_shake256_h16)) { + goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmss_shake256_h20 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_shake256_h20)) { + goto skip_test; +#endif + +#ifdef OQS_ENABLE_SIG_STFL_xmssmt_sha256_h40_2 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h40_2)) { + goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmssmt_sha256_h60_3 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h60_3)) { + goto skip_test; +#endif + +#ifdef OQS_ENABLE_SIG_STFL_xmssmt_shake128_h40_2 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h40_2)) { + goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmssmt_shake128_h60_3 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h60_3)) { + goto skip_test; +#endif + } else { + goto keep_going; + } skip_test: printf("Skip slow test %s.\n", method_name); @@ -706,7 +779,8 @@ static OQS_STATUS sig_stfl_test_secret_key(const char *method_name) { goto err; } - if (oqs_fstore("sk", sig_obj->method_name, to_file_sk_buf, to_file_sk_len) != OQS_SUCCESS) { + file_store_name = convert_method_name_to_file_name(sig_obj->method_name); + if (oqs_fstore("sk", file_store_name, to_file_sk_buf, to_file_sk_len) != OQS_SUCCESS) { goto err; } @@ -717,13 +791,13 @@ static OQS_STATUS sig_stfl_test_secret_key(const char *method_name) { /* set context and secure store callback */ if (sk->set_scrt_key_store_cb) { - context = strdup(((method_name))); + context = strdup(file_store_name); sk->set_scrt_key_store_cb(sk, test_save_secret_key, (void *)context); } /* read secret key from disk */ frm_file_sk_buf = malloc(to_file_sk_len); - if (oqs_fload("sk", method_name, frm_file_sk_buf, to_file_sk_len, &frm_file_sk_len) != OQS_SUCCESS) { + if (oqs_fload("sk", file_store_name, frm_file_sk_buf, to_file_sk_len, &frm_file_sk_len) != OQS_SUCCESS) { goto err; } if (to_file_sk_len != frm_file_sk_len) { @@ -737,7 +811,7 @@ static OQS_STATUS sig_stfl_test_secret_key(const char *method_name) { goto err; } - context_2 = strdup(((method_name))); + context_2 = strdup(file_store_name); rc = OQS_SECRET_KEY_STFL_deserialize_key(sk_frm_file, frm_file_sk_len, frm_file_sk_buf, (void *)context_2); if (rc != OQS_SUCCESS) { @@ -761,12 +835,12 @@ static OQS_STATUS sig_stfl_test_secret_key(const char *method_name) { OQS_SIG_STFL_free(sig_obj); OQS_MEM_insecure_free(context); OQS_MEM_insecure_free(context_2); + OQS_MEM_insecure_free(file_store_name); return rc; } static OQS_STATUS sig_stfl_test_query_key(const char *method_name) { OQS_STATUS rc = OQS_SUCCESS; - size_t message_len_1 = sizeof(message_1); size_t message_len_2 = sizeof(message_2); @@ -774,20 +848,67 @@ static OQS_STATUS sig_stfl_test_query_key(const char *method_name) { * Temporarily skip algs with long key generation times. */ - if (strcmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h5_w1) == 0 - || strcmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h5_w2) == 0 - || strcmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h5_w4) == 0 - || strcmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h5_w8) == 0 + if (0) { - || strcmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h10_w1) == 0 - || strcmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h15_w1) == 0) { - goto keep_going; - } else { +#ifdef OQS_ENABLE_SIG_STFL_xmss_sha256_h16 + } else if (strcmp(method_name, OQS_SIG_STFL_alg_xmss_sha256_h16) == 0) { + goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmss_sha256_h20 + } else if (strcmp(method_name, OQS_SIG_STFL_alg_xmss_sha256_h20) == 0) { + goto skip_test; +#endif + +#ifdef OQS_ENABLE_SIG_STFL_xmss_shake128_h16 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_shake128_h16)) { + goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmss_shake128_h20 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_shake128_h20)) { + goto skip_test; +#endif + +#ifdef OQS_ENABLE_SIG_STFL_xmss_sha512_h16 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_sha512_h16)) { + goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmss_sha512_h20 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_sha512_h20)) { + goto skip_test; +#endif + +#ifdef OQS_ENABLE_SIG_STFL_xmss_shake256_h16 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_shake256_h16)) { + goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmss_shake256_h20 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_shake256_h20)) { + goto skip_test; +#endif + +#ifdef OQS_ENABLE_SIG_STFL_xmssmt_sha256_h40_2 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h40_2)) { + goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmssmt_sha256_h60_3 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h60_3)) { + goto skip_test; +#endif + +#ifdef OQS_ENABLE_SIG_STFL_xmssmt_shake128_h40_2 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h40_2)) { goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmssmt_shake128_h60_3 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h60_3)) { + goto skip_test; +#endif + } else { + goto keep_going; } skip_test: - printf("Skip slow alg %s.\n", method_name); + printf("Skip slow test %s.\n", method_name); return rc; keep_going: @@ -839,24 +960,74 @@ static OQS_STATUS sig_stfl_test_sig_gen(const char *method_name) { size_t message_len_1 = sizeof(message_1); size_t message_len_2 = sizeof(message_2); + char *context = NULL; + char *key_store_name = NULL; + /* * Temporarily skip algs with long key generation times. */ - if (strcmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h5_w1) == 0 - || strcmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h5_w2) == 0 - || strcmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h5_w4) == 0 - || strcmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h5_w8) == 0 + if (0) { - || strcmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h10_w1) == 0 - || strcmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h15_w1) == 0) { - goto keep_going; - } else { +#ifdef OQS_ENABLE_SIG_STFL_xmss_sha256_h16 + } else if (strcmp(method_name, OQS_SIG_STFL_alg_xmss_sha256_h16) == 0) { + goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmss_sha256_h20 + } else if (strcmp(method_name, OQS_SIG_STFL_alg_xmss_sha256_h20) == 0) { + goto skip_test; +#endif + +#ifdef OQS_ENABLE_SIG_STFL_xmss_shake128_h16 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_shake128_h16)) { + goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmss_shake128_h20 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_shake128_h20)) { + goto skip_test; +#endif + +#ifdef OQS_ENABLE_SIG_STFL_xmss_sha512_h16 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_sha512_h16)) { + goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmss_sha512_h20 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_sha512_h20)) { + goto skip_test; +#endif + +#ifdef OQS_ENABLE_SIG_STFL_xmss_shake256_h16 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_shake256_h16)) { goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmss_shake256_h20 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_shake256_h20)) { + goto skip_test; +#endif + +#ifdef OQS_ENABLE_SIG_STFL_xmssmt_sha256_h40_2 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h40_2)) { + goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmssmt_sha256_h60_3 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h60_3)) { + goto skip_test; +#endif + +#ifdef OQS_ENABLE_SIG_STFL_xmssmt_shake128_h40_2 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h40_2)) { + goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmssmt_shake128_h60_3 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h60_3)) { + goto skip_test; +#endif + } else { + goto keep_going; } skip_test: - printf("Skip slow alg %s.\n", method_name); + printf("Skip slow test %s.\n", method_name); return rc; keep_going: @@ -869,6 +1040,11 @@ static OQS_STATUS sig_stfl_test_sig_gen(const char *method_name) { return OQS_ERROR; } + key_store_name = convert_method_name_to_file_name(method_name); + /* set context and secure store callback */ + context = strdup(((key_store_name))); + OQS_SIG_STFL_SECRET_KEY_SET_store_cb(lock_test_sk, test_save_secret_key, (void *)context); + /* * Get max num signature and the amount remaining */ @@ -957,6 +1133,8 @@ static OQS_STATUS sig_stfl_test_sig_gen(const char *method_name) { err: rc = OQS_ERROR; end_it: + OQS_MEM_insecure_free(context); + OQS_MEM_insecure_free(key_store_name); return rc; } @@ -964,20 +1142,71 @@ static OQS_STATUS sig_stfl_test_sig_gen(const char *method_name) { static OQS_STATUS sig_stfl_test_secret_key_lock(const char *method_name) { OQS_STATUS rc = OQS_SUCCESS; + printf("================================================================================\n"); + printf("Testing stateful Signature locks %s\n", method_name); + printf("================================================================================\n"); + /* * Temporarily skip algs with long key generation times. */ - if (strcmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h5_w1) == 0 - || strcmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h5_w2) == 0 - || strcmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h5_w4) == 0 - || strcmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h5_w8) == 0 + if (0) { - || strcmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h10_w1) == 0 - || strcmp(method_name, OQS_SIG_STFL_alg_lms_sha256_n32_h15_w1) == 0) { - goto keep_going; - } else { +#ifdef OQS_ENABLE_SIG_STFL_xmss_sha256_h16 + } else if (strcmp(method_name, OQS_SIG_STFL_alg_xmss_sha256_h16) == 0) { + goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmss_sha256_h20 + } else if (strcmp(method_name, OQS_SIG_STFL_alg_xmss_sha256_h20) == 0) { + goto skip_test; +#endif + +#ifdef OQS_ENABLE_SIG_STFL_xmss_shake128_h16 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_shake128_h16)) { goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmss_shake128_h20 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_shake128_h20)) { + goto skip_test; +#endif + +#ifdef OQS_ENABLE_SIG_STFL_xmss_sha512_h16 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_sha512_h16)) { + goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmss_sha512_h20 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_sha512_h20)) { + goto skip_test; +#endif + +#ifdef OQS_ENABLE_SIG_STFL_xmss_shake256_h16 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_shake256_h16)) { + goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmss_shake256_h20 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmss_shake256_h20)) { + goto skip_test; +#endif + +#ifdef OQS_ENABLE_SIG_STFL_xmssmt_sha256_h40_2 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h40_2)) { + goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmssmt_sha256_h60_3 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h60_3)) { + goto skip_test; +#endif + +#ifdef OQS_ENABLE_SIG_STFL_xmssmt_shake128_h40_2 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h40_2)) { + goto skip_test; +#endif +#ifdef OQS_ENABLE_SIG_STFL_xmssmt_shake128_h60_3 + } else if (0 == strcasecmp(method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h60_3)) { + goto skip_test; +#endif + } else { + goto keep_going; } skip_test: @@ -986,10 +1215,6 @@ static OQS_STATUS sig_stfl_test_secret_key_lock(const char *method_name) { keep_going: - printf("================================================================================\n"); - printf("Testing stateful Signature locks %s\n", method_name); - printf("================================================================================\n"); - printf("================================================================================\n"); printf("Create stateful Signature %s\n", method_name); printf("================================================================================\n"); @@ -1046,7 +1271,7 @@ static OQS_STATUS sig_stfl_test_secret_key_lock(const char *method_name) { /* set context and secure store callback */ if (lock_test_sk->set_scrt_key_store_cb) { - lock_test_context = strdup(((method_name))); + lock_test_context = convert_method_name_to_file_name(method_name); lock_test_sk->set_scrt_key_store_cb(lock_test_sk, test_save_secret_key, (void *)lock_test_context); }