Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

20241017-wc-delete-methods #8089

Merged
merged 3 commits into from
Oct 19, 2024
Merged

Conversation

douzzer
Copy link
Contributor

@douzzer douzzer commented Oct 17, 2024

refactor wolfcrypt constructors:

add delete APIs, matching recently added wc_AesNew, wc_curve25519_new, wc_ed25519_new, wc_HashNew, and wc_NewRsaKey:

  • wc_AesDelete()

  • wc_HashDelete()

  • wc_DeleteRsaKey()

  • wc_curve25519_delete()

  • wc_ed25519_delete()

  • remove handling in corresponding preexisting free APIs for recently added .isAllocated member -- this restores preexisting semantics;

  • add WC_NO_CONSTRUCTORS gate, and auto-activate it when NO_WOLFSSL_MEMORY && WOLFSSL_NO_MALLOC (unless preempted by XMALLOC_USER or XMALLOC_OVERRIDE);

  • exclude recently added .isAllocated members from wolfcrypt structs when defined(WC_NO_CONSTRUCTORS).

tested with wolfssl-multi-test.sh ... check-source-text quantum-safe-wolfssl-all-g++-latest-debug quantum-safe-wolfssl-all-cppcheck fortify-source-all-asm fortify-source-all-noasm clang-tidy-all-sp-all sanitizer-all-intelasm-c-fallback-fuzzer all-gcc-c99-asn-original cryptonly-opensslextra-gcc-c99 allcryptonly-no-malloc allcryptonly-no-malloc-no-wolf-memory allcryptonly-gcc-c89 quantum-safe-wolfssl-all-valgrind quantum-safe-wolfssl-all-smallstack-valgrind cppcheck-all-smallstack

add delete APIs, matching recently added wc_AesNew, wc_curve25519_new, wc_ed25519_new, wc_HashNew, and wc_NewRsaKey:
* wc_AesDelete()
* wc_HashDelete()
* wc_DeleteRsaKey()
* wc_curve25519_delete()
* wc_ed25519_delete()

* remove handling in corresponding preexisting free APIs for recently added .isAllocated member -- this restores preexisting semantics;

* add WC_NO_CONSTRUCTORS gate, and auto-activate it when NO_WOLFSSL_MEMORY && WOLFSSL_NO_MALLOC (unless preempted by XMALLOC_USER or XMALLOC_OVERRIDE);

* exclude recently added .isAllocated members from wolfcrypt structs when defined(WC_NO_CONSTRUCTORS);

* adjust wolfcrypt/test/test.c for consistency with the above, and fix cleanup codes/dynamics in several tests.
@douzzer douzzer force-pushed the 20241017-wc-delete-methods branch from 2ad389e to 984d16b Compare October 17, 2024 23:48
@philljj
Copy link
Contributor

philljj commented Oct 18, 2024

This modifies the new/free logic from #3166.

… unneeded .isAllocated member from struct definitions, and add int *result_code argument to constructor prototypes;

wolfssl/wolfcrypt/aes.h: add Aes.streamData_sz;

src/tls13.c: fix devId passed to wc_HmacInit() in CreateCookieExt() and TlsCheckCookie();

src/keys.c: in SetKeys(), call wc_HmacInit() on hmacs only if newly allocated;

wolfcrypt/src/aes.c:
* in wc_Gmac(), wc_GmacVerify(), and AesSivCipher(), use wc_AesNew() and wc_AesDelete();
* in wc_AesInit(), zero the object on entry, and remove superseded piecemeal initializations to zero;
* in wc_AesFree(), zero aes->streamData, and zero the entire object as final cleanup;

wolfcrypt/src/curve25519.c: in wc_curve25519_free(), zero the entire object rather than zeroing piecemeal;

wolfcrypt/test/test.c:
* add fallback implementations (for old FIPS) of wc_HashNew(), wc_HashDelete(), wc_curve25519_new(), wc_curve25519_delete(), wc_ed25519_new(), and wc_ed25519_delete();
* update constructor calls throughout for new semantics;
* refactor ed25519_test() for proper cleanup and error encoding.
@douzzer douzzer force-pushed the 20241017-wc-delete-methods branch 8 times, most recently from 2c71a22 to 859f3a6 Compare October 19, 2024 01:23
…shDelete, and wc_DeleteRsaKey to take two arguments, the first a required pointer to the object, the second an optional pointer to the pointer to be zeroed upon successful deletion, for the benefit of calling from C# without unsafe code.

wrapper/CSharp/wolfSSL_CSharp/wolfCrypt.cs: update for new calling conventions around wc_AesNew, wc_curve25519_new, wc_ed25519_new, wc_HashNew, and wc_NewRsaKey, and the corresponding delete functions.
@douzzer douzzer force-pushed the 20241017-wc-delete-methods branch from 859f3a6 to 996986d Compare October 19, 2024 02:14
@philljj philljj merged commit ea3a79e into wolfSSL:master Oct 19, 2024
140 checks passed
@dgarske
Copy link
Contributor

dgarske commented Oct 21, 2024

@aidangarske please add documentation for these new API's. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants