Skip to content

Commit

Permalink
Add return check for lock/unlock function
Browse files Browse the repository at this point in the history
  • Loading branch information
ducnguyen-sb committed Mar 11, 2024
1 parent baf54a2 commit 59491a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/sig_stfl/xmss/sig_stfl_xmss_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_sign(uint8_t *signature, size_t *signat
}

/* Lock secret to ensure OTS use */
OQS_SECRET_KEY_XMSS_acquire_lock(secret_key);
if (OQS_SECRET_KEY_XMSS_acquire_lock(secret_key) != OQS_SUCCESS) {
return OQS_ERROR;
}

if (xmss_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) {
status = OQS_ERROR;
Expand All @@ -59,8 +61,10 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmss_sign(uint8_t *signature, size_t *signat
OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len);

err:
/* Unlock secret to ensure OTS use */
OQS_SECRET_KEY_XMSS_release_lock(secret_key);
/* Unlock the key if possible */
if (OQS_SECRET_KEY_XMSS_release_lock(secret_key) != OQS_SUCCESS) {
return OQS_ERROR;
}

return status;
}
Expand Down
10 changes: 7 additions & 3 deletions src/sig_stfl/xmss/sig_stfl_xmssmt_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_sign(uint8_t *signature, size_t *sign
}

/* Lock secret to ensure OTS use */
OQS_SECRET_KEY_XMSS_acquire_lock(secret_key);
if (OQS_SECRET_KEY_XMSS_acquire_lock(secret_key) != OQS_SUCCESS) {
return OQS_ERROR;
}

if (xmssmt_sign(secret_key->secret_key_data, signature, &sig_length, message, message_len)) {
status = OQS_ERROR;
Expand All @@ -60,8 +62,10 @@ OQS_API OQS_STATUS OQS_SIG_STFL_alg_xmssmt_sign(uint8_t *signature, size_t *sign
OQS_MEM_secure_free(sk_key_buf_ptr, sk_key_buf_len);

err:
/* Unlock secret to ensure OTS use */
OQS_SECRET_KEY_XMSS_release_lock(secret_key);
/* Unlock the key if possible */
if (OQS_SECRET_KEY_XMSS_release_lock(secret_key) != OQS_SUCCESS) {
return OQS_ERROR;
}

return status;
}
Expand Down

0 comments on commit 59491a7

Please sign in to comment.