Skip to content

Add API visibility prefixes to wolfPKCS11 headers#102

Merged
dgarske merged 3 commits into
masterfrom
devin/1719140549-api-visibility-fix
Jun 23, 2025
Merged

Add API visibility prefixes to wolfPKCS11 headers#102
dgarske merged 3 commits into
masterfrom
devin/1719140549-api-visibility-fix

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

Add API visibility prefixes to wolfPKCS11 headers

Summary

This PR adds proper API visibility prefixes to function declarations in the wolfPKCS11 library headers to ensure correct symbol visibility control.

Changes Made

wolfpkcs11/internal.h

  • Added WP11_LOCAL prefix to all internal function declarations (~100+ functions)
  • Includes all WP11_* functions for library initialization, slot management, session handling, object manipulation, and cryptographic operations
  • Also includes debugging functions wolfPKCS11_Debugging_On/Off

wolfpkcs11/store.h

  • Added WP11_LOCAL prefix to all storage interface function declarations (5 functions)
  • Functions: wolfPKCS11_Store_Open, wolfPKCS11_Store_OpenSz, wolfPKCS11_Store_Close, wolfPKCS11_Store_Read, wolfPKCS11_Store_Write

wolfpkcs11/pkcs11.h

  • Added WP11_API prefix to all PKCS#11 API function declarations (~60+ functions)
  • Includes all C_* functions like C_Initialize, C_Finalize, C_GetSlotList, C_CreateObject, C_Encrypt, C_Sign, etc.
  • Note: C_GetFunctionList and debug functions already had WP11_API prefix

Technical Details

  • Files Modified: 3 files changed, 244 insertions(+), 244 deletions(-)
  • Visibility Control:
    • WP11_LOCAL marks functions as library-internal
    • WP11_API marks functions as publicly exported
  • Compatibility: Changes follow existing visibility macro patterns defined in the codebase

Testing

The changes are purely additive visibility annotations and do not modify function signatures or behavior. All existing functionality remains unchanged.


Link to Devin run: https://app.devin.ai/sessions/e21eeb0adc8c4a59ab47cc18a07e30f6
Requested by: andrew@wolfssl.com

- Add WP11_LOCAL prefix to all function declarations in wolfpkcs11/internal.h
- Add WP11_LOCAL prefix to all function declarations in wolfpkcs11/store.h
- Add WP11_API prefix to all API declarations in wolfpkcs11/pkcs11.h

This ensures proper symbol visibility control for the wolfPKCS11 library,
marking internal functions as library-internal and API functions as
publicly exported.

Co-Authored-By: andrew@wolfssl.com <andrew@wolfssl.com>
@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

devin-ai-integration Bot and others added 2 commits June 23, 2025 09:33
Remove duplicate wolfPKCS11_Debugging_On/Off declarations from internal.h
to resolve visibility conflict. These functions are already properly declared
with WP11_API visibility in pkcs11.h as public API functions.

Co-Authored-By: andrew@wolfssl.com <andrew@wolfssl.com>
Move wolfPKCS11_Debugging_On/Off declarations outside of DEBUG_WOLFPKCS11
conditional block so they are always declared in the public API.
The implementations in src/internal.c already provide empty definitions
when debugging is disabled, ensuring proper linking regardless of
debug configuration.

Co-Authored-By: andrew@wolfssl.com <andrew@wolfssl.com>
@SparkiDev
Copy link
Copy Markdown
Contributor

Why Is this necessary?
All functions are accessible through the table.

@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

@SparkiDev Thank you for the question!

You're absolutely right that PKCS#11 functions are typically accessed through the function table via C_GetFunctionList(). However, the API visibility prefixes serve several important purposes:

Why WP11_API is necessary:

  1. Symbol Visibility Control: The WP11_API macro controls which symbols are exported from the shared library. Without proper visibility annotations, all symbols might be exported by default (depending on compiler/linker settings), which can:

    • Increase library size
    • Create potential symbol conflicts
    • Expose internal implementation details
  2. Consistent API Design: Some applications may choose to link directly to specific PKCS#11 functions rather than using the function table, especially for commonly used functions like C_Initialize, C_Finalize, etc.

  3. Platform Compatibility: Different platforms (Windows DLL, Linux shared library, etc.) have different default symbol visibility behaviors. The WP11_API macro ensures consistent behavior across platforms.

  4. Future-proofing: Having explicit visibility control makes it easier to maintain a stable ABI and control what gets exported as the library evolves.

Why WP11_LOCAL is necessary:

The WP11_LOCAL prefixes on internal functions ensure they are NOT exported from the shared library, keeping the public API surface clean and preventing accidental usage of internal functions.

This was requested by @andrew@wolfssl.com as part of improving the library's symbol visibility architecture. The changes are purely additive and don't affect existing functionality - they just provide better control over what symbols are publicly accessible.

Does this help clarify the rationale? Happy to discuss further if you have other concerns!

@dgarske dgarske merged commit 0a9aaf0 into master Jun 23, 2025
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants