Skip to content

Bugfixes for the SymCrypt provider#165

Draft
mamckee wants to merge 9 commits intoscossl-1.9from
mamckee-provider-bugfixes
Draft

Bugfixes for the SymCrypt provider#165
mamckee wants to merge 9 commits intoscossl-1.9from
mamckee-provider-bugfixes

Conversation

@mamckee
Copy link
Copy Markdown
Collaborator

@mamckee mamckee commented Apr 21, 2026

This PR fixes a number of minor bugs and behavior issues with the SymCrypt provider. These bugs are either normally not triggerable through the EVP layer or normal calling patterns, or impact uncommonly used functions.

  • Fixed an incorrect size comparison in AES when setting OSSL_CIPHER_PARAM_TLS_MAC_SIZE
  • Fixed an issue where p_scossl_dh_keymgmt_dup_key_ctx would allocate an incorrectly sized buffer when copying a context using a custom group and with no key set yet.
  • Added initialization state checks to HMAC to prevent usage of context with no key set, but still permit partially initialized contexts for Allow MAC context duplication for partially initialized contexts #156
  • Added check for size of x25519 keys passed by parameter to the provider
  • Added checks for outlen in RSA encrypt/decrypt. This was previously not checked in OpenSSL for RSA encrypt but was hardened in 3.3.7. These checks bring SymCrypt-OpenSSL in line with the default behavior.
  • Fixed check in RSA key match, where the private exponent was not compared correctly.

@mamckee mamckee requested a review from Copilot April 21, 2026 21:59
Copy link
Copy Markdown

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.

Copy link
Copy Markdown

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 11 changed files in this pull request and generated 4 comments.


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

Comment thread ScosslCommon/src/scossl_mac.c
Comment thread ScosslCommon/src/scossl_mac.c
Comment on lines +246 to +263
cbModulus = SymCryptRsakeySizeofModulus(ctx->keyCtx->key);
if (out == NULL)
{
if (cbModulus == 0)
{
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY);
return SCOSSL_FAILURE;
}

*outlen = cbModulus;
return SCOSSL_SUCCESS;
}

if (outsize < cbModulus)
{
ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL);
return SCOSSL_FAILURE;
}
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

In the non-TLS decrypt path, cbModulus is used for output sizing but is only validated for the out == NULL (size query) case. If SymCryptRsakeySizeofModulus returns 0 for an invalid key and out != NULL, the outsize check is bypassed and the code proceeds to scossl_rsa_decrypt without raising PROV_R_INVALID_KEY. Consider checking cbModulus == 0 immediately after retrieval (as encrypt does) and returning PROV_R_INVALID_KEY consistently.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

So this is technically the OpenSSL behavior. I think raising the error outside of the out == NULL check is better though. I suppose this will still fail later in the call so moving this check should be safe.

Comment thread SymCryptProvider/src/keymgmt/p_scossl_ecc_keymgmt.c
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.

2 participants