Skip to content

Implement HW/SW crypto affinity#281

Draft
AlexLanzano wants to merge 7 commits intowolfSSL:mainfrom
AlexLanzano:crypto-hw-sw-affinity
Draft

Implement HW/SW crypto affinity#281
AlexLanzano wants to merge 7 commits intowolfSSL:mainfrom
AlexLanzano:crypto-hw-sw-affinity

Conversation

@AlexLanzano
Copy link
Member

Add SetCryptoAffinity API for runtime HW/SW crypto selection

Summary

This PR adds a new client API to dynamically switch between hardware and software cryptographic implementations at runtime. This allows clients to control whether the server uses crypto callbacks (hardware acceleration) or pure software wolfCrypt implementations.

Changes

  • New Client API (wh_client.c, wh_client.h)

    • wh_Client_SetCryptoAffinity() - blocking call
    • wh_Client_SetCryptoAffinityRequest() / wh_Client_SetCryptoAffinityResponse() - async API
  • New Message Types (wh_message_comm.c, wh_message_comm.h)

    • WH_MESSAGE_COMM_ACTION_SET_CRYPTO_AFFINITY action
    • WH_CRYPTO_AFFINITY_SW / WH_CRYPTO_AFFINITY_HW enum values
    • Request/response structures with translation functions
  • Server Handler (wh_server.c, wh_server.h)

    • Added configDevId field to preserve the original configured device ID
    • Handler switches devId between INVALID_DEVID (SW) and configDevId (HW)
  • New Error Code (wh_error.h)

    • WH_ERROR_BADCONFIG (-2010) - returned when HW affinity is requested but no HW crypto was configured
  • Tests (wh_test_clientserver.c)

    • Added _testCryptoAffinity() to verify SW/HW switching behavior
  • Documentation (docs/draft/crypto_affinity.md)

    • API usage guide with examples

Usage

int32_t server_rc;
uint32_t affinity;

// Switch to software crypto
wh_Client_SetCryptoAffinity(client, WH_CRYPTO_AFFINITY_SW, &server_rc, &affinity);

// Switch to hardware crypto (if configured)
wh_Client_SetCryptoAffinity(client, WH_CRYPTO_AFFINITY_HW, &server_rc, &affinity);

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements a new client API to dynamically switch between hardware and software cryptographic implementations at runtime. The feature allows clients to control whether the server uses hardware acceleration (via crypto callbacks) or pure software wolfCrypt implementations by modifying the server's devId field.

Changes:

  • New client API with both blocking and async variants for setting crypto affinity
  • Server handler to process affinity change requests with proper validation and error handling
  • New message types and translation functions for client-server communication
  • Comprehensive test coverage including edge cases and error conditions

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
wolfhsm/wh_server.h Added configDevId field to preserve original device ID configuration
wolfhsm/wh_message_comm.h Defined message action, enum values, and request/response structures
wolfhsm/wh_error.h Added WH_ERROR_BADCONFIG error code for configuration failures
wolfhsm/wh_client.h Declared new client API functions with comprehensive documentation
src/wh_server.c Implemented initialization of configDevId and request handler with validation
src/wh_message_comm.c Implemented message translation functions following existing patterns
src/wh_client.c Implemented client APIs with proper error handling and retry logic
test/wh_test_clientserver.c Added comprehensive test coverage for various scenarios
docs/draft/crypto_affinity.md Created API documentation with usage examples and return code reference

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

AlexLanzano and others added 2 commits February 4, 2026 16:30
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 12 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@AlexLanzano AlexLanzano force-pushed the crypto-hw-sw-affinity branch from 571a0c7 to 3655e5c Compare February 4, 2026 22:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 12 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@AlexLanzano AlexLanzano force-pushed the crypto-hw-sw-affinity branch from 9949065 to 506f420 Compare February 5, 2026 19:08
@AlexLanzano AlexLanzano requested a review from Copilot February 5, 2026 19:18
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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.

1 participant