Skip to content

Commit

Permalink
Add return status for XMSS lock/unlock functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
ducnguyen-sb committed Feb 29, 2024
1 parent 3f6aeac commit 700b50f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/sig_stfl/xmss/sig_stfl_xmss.h
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,9 @@ void OQS_SECRET_KEY_XMSS_set_store_cb(OQS_SIG_STFL_SECRET_KEY *sk, secure_store_
void OQS_SECRET_KEY_XMSS_free(OQS_SIG_STFL_SECRET_KEY *sk);

/* Lock the key if possible */
void OQS_SECRET_KEY_XMSS_acquire_lock(const OQS_SIG_STFL_SECRET_KEY *sk);
OQS_STATUS OQS_SECRET_KEY_XMSS_acquire_lock(const OQS_SIG_STFL_SECRET_KEY *sk);

/* Unlock the key if possible */
void OQS_SECRET_KEY_XMSS_release_lock(const OQS_SIG_STFL_SECRET_KEY *sk);
OQS_STATUS OQS_SECRET_KEY_XMSS_release_lock(const OQS_SIG_STFL_SECRET_KEY *sk);

#endif /* OQS_SIG_STFL_XMSS_H */
39 changes: 25 additions & 14 deletions src/sig_stfl/xmss/sig_stfl_xmss_secret_key_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
#define XMSS_UNUSED_ATT
#endif

extern inline
OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSS_new(size_t length_secret_key) {
extern inline OQS_SIG_STFL_SECRET_KEY *OQS_SECRET_KEY_XMSS_new(size_t length_secret_key) {

// Initialize the secret key in the heap with adequate memory
OQS_SIG_STFL_SECRET_KEY *sk = malloc(sizeof(OQS_SIG_STFL_SECRET_KEY));
Expand Down Expand Up @@ -71,7 +70,9 @@ OQS_STATUS OQS_SECRET_KEY_XMSS_serialize_key(uint8_t **sk_buf_ptr, size_t *sk_le
}

/* Lock the key if possible */
OQS_SECRET_KEY_XMSS_acquire_lock(sk);
if (OQS_SECRET_KEY_XMSS_acquire_lock(sk) != OQS_SUCCESS) {
return OQS_ERROR;
}

uint8_t *sk_buf = malloc(sk->length_secret_key * sizeof(uint8_t));
if (sk_buf == NULL) {
Expand All @@ -85,7 +86,9 @@ OQS_STATUS OQS_SECRET_KEY_XMSS_serialize_key(uint8_t **sk_buf_ptr, size_t *sk_le
*sk_len = sk->length_secret_key;

/* Unlock the key if possible */
OQS_SECRET_KEY_XMSS_release_lock(sk);
if (OQS_SECRET_KEY_XMSS_release_lock(sk) != OQS_SUCCESS) {
return OQS_ERROR;
}

return OQS_SUCCESS;
}
Expand Down Expand Up @@ -143,24 +146,32 @@ void OQS_SECRET_KEY_XMSS_free(OQS_SIG_STFL_SECRET_KEY *sk) {
sk->secret_key_data = NULL;
}

void OQS_SECRET_KEY_XMSS_acquire_lock(const OQS_SIG_STFL_SECRET_KEY *sk) {
OQS_STATUS OQS_SECRET_KEY_XMSS_acquire_lock(const OQS_SIG_STFL_SECRET_KEY *sk) {
if (sk == NULL) {
return;
return OQS_ERROR;
}

/* Lock the key if possible */
if ((sk->lock_key != NULL) && (sk->mutex != NULL)) {
sk->lock_key(sk->mutex);
/* Lock the key if possible, otherwise return SUCCESS because the lock_key, unlock_key and mutex are not defined.*/
if ((sk->lock_key != NULL) && (sk->mutex != NULL) && (sk->unlock_key != NULL)) {
if (sk->lock_key(sk->mutex) != OQS_SUCCESS) {
return OQS_ERROR;
}
}

return OQS_SUCCESS;
}

void OQS_SECRET_KEY_XMSS_release_lock(const OQS_SIG_STFL_SECRET_KEY *sk) {
OQS_STATUS OQS_SECRET_KEY_XMSS_release_lock(const OQS_SIG_STFL_SECRET_KEY *sk) {
if (sk == NULL) {
return;
return OQS_ERROR;
}

/* Unlock the key if possible */
if ((sk->unlock_key != NULL) && (sk->mutex != NULL)) {
sk->unlock_key(sk->mutex);
/* Unlock the key if possible, otherwise return SUCCESS because the lock_key, unlock_key and mutex are not defined. */
if ((sk->unlock_key != NULL) && (sk->mutex != NULL) && (sk->lock_key != NULL)) {
if (sk->unlock_key(sk->mutex) != OQS_SUCCESS) {
return OQS_ERROR;
}
}

return OQS_SUCCESS;
}

0 comments on commit 700b50f

Please sign in to comment.