Skip to content

Commit

Permalink
correct free in test_kem/sig (#1399)
Browse files Browse the repository at this point in the history
* correct free in test_kem/sig

* code simplification
  • Loading branch information
baentsch committed Feb 23, 2023
1 parent 4916446 commit 1f62f66
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
14 changes: 11 additions & 3 deletions tests/test_kem.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,21 @@ static OQS_STATUS kem_test_correctness(const char *method_name) {
ret = OQS_ERROR;

cleanup:
if (kem != NULL) {
if (secret_key) {
OQS_MEM_secure_free(secret_key - sizeof(magic_t), kem->length_secret_key + 2 * sizeof(magic_t));
}
if (shared_secret_e) {
OQS_MEM_secure_free(shared_secret_e - sizeof(magic_t), kem->length_shared_secret + 2 * sizeof(magic_t));
}
if (shared_secret_d) {
OQS_MEM_secure_free(shared_secret_d - sizeof(magic_t), kem->length_shared_secret + 2 * sizeof(magic_t));
}
OQS_MEM_insecure_free(public_key - sizeof(magic_t));
OQS_MEM_insecure_free(ciphertext - sizeof(magic_t));
if (public_key) {
OQS_MEM_insecure_free(public_key - sizeof(magic_t));
}
if (ciphertext) {
OQS_MEM_insecure_free(ciphertext - sizeof(magic_t));
}
OQS_KEM_free(kem);

return ret;
Expand Down
14 changes: 10 additions & 4 deletions tests/test_sig.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,18 @@ static OQS_STATUS sig_test_correctness(const char *method_name) {
ret = OQS_ERROR;

cleanup:
if (sig != NULL) {
if (secret_key) {
OQS_MEM_secure_free(secret_key - sizeof(magic_t), sig->length_secret_key + 2 * sizeof(magic_t));
}
OQS_MEM_insecure_free(public_key - sizeof(magic_t));
OQS_MEM_insecure_free(message - sizeof(magic_t));
OQS_MEM_insecure_free(signature - sizeof(magic_t));
if (public_key) {
OQS_MEM_insecure_free(public_key - sizeof(magic_t));
}
if (message) {
OQS_MEM_insecure_free(message - sizeof(magic_t));
}
if (signature) {
OQS_MEM_insecure_free(signature - sizeof(magic_t));
}
OQS_SIG_free(sig);

return ret;
Expand Down

0 comments on commit 1f62f66

Please sign in to comment.