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 70c421c
Show file tree
Hide file tree
Showing 3 changed files with 47 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
33 changes: 33 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

set -e

cd build;
rm -rf * ;
# cmake -GNinja -DOQS_USE_OPENSSL=ON -DBUILD_SHARED_LIBS=ON -DOQS_USE_AES_OPENSSL=ON -DOQS_USE_SHA2_OPENSSL=ON -DOQS_USE_SHA3_OPENSSL=ON -DOQS_ENABLE_SIG_STFL_LMS=ON -DOQS_ENABLE_SIG_STFL_XMSS=ON -DOQS_ENABLE_SIG_STFL_KEY_SIG_GEN=ON ../
cmake -GNinja -DCMAKE_C_COMPILER=clang-15 -DOQS_ENABLE_SIG_STFL_LMS=ON -DOQS_ENABLE_SIG_STFL_XMSS=ON -DOQS_ENABLE_SIG_STFL_KEY_SIG_GEN=ON -DCMAKE_BUILD_TYPE=Debug -DUSE_SANITIZER=Address ../
scan-build --status-bugs ninja
cd ../

# echo "==========================="

echo "test code conventions"
# python3 -m pytest --verbose tests/test_code_conventions.py

# # echo "==========================="

# echo "test KAT"
# python3 tests/test_kat.py -v -k XMSS-SHA2_10_256 --show-capture=stderr
python3 tests/test_kat.py -v -k xmss --show-capture=stderr

# echo "==========================="


echo "test cmdline"
# python3 tests/test_cmdline.py -v -k XMSSMT-SHA2_40/8_256
python3 tests/test_cmdline.py -v -k xmss
# python3 tests/test_cmdline.py -v -k lms

# ./build/tests/test_sig_stfl XMSSMT-SHA2_40/8_256 tests/KATs/sig_stfl/xmss/XMSSMT-SHA2_40/8_256.rsp

echo "=========================== TEST.SH END ==========================="

0 comments on commit 70c421c

Please sign in to comment.