Skip to content

Add generic and AES SKEY support#163

Open
mamckee wants to merge 5 commits intomainfrom
mamckee-aes-skey
Open

Add generic and AES SKEY support#163
mamckee wants to merge 5 commits intomainfrom
mamckee-aes-skey

Conversation

@mamckee
Copy link
Copy Markdown
Collaborator

@mamckee mamckee commented Apr 1, 2026

OpenSSL 3.5 added SKEYs for opaque symmetric key management. This PR adds support for the new key types to the SymCrypt provider.

  • Add generic and AES SKEY keymgmt interfaces
  • Add support for AES SKEYs to AES cipher interfaces
  • Add support for AES SKEYs to CMAC interface

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

This PR adds OpenSSL 3.5 SKEY (opaque symmetric key) support to the SymCrypt provider by introducing SKEYMGMT implementations and wiring SKEY-based initialization into existing AES cipher and CMAC MAC implementations.

Changes:

  • Added generic and AES SKEYMGMT implementations (import/export/generate) backed by secure key storage.
  • Added AES cipher support for SKEY-based init across generic, AEAD (GCM/CCM), and XTS implementations.
  • Added CMAC support for SKEY-based init and registered SKEYMGMT algorithms in the provider query interface.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
SymCryptProvider/src/skeymgmt/p_scossl_generic_skeymgmt.h Declares generic SKEYMGMT entry points.
SymCryptProvider/src/skeymgmt/p_scossl_generic_skeymgmt.c Implements generic secret key import/export/generation for SKEYs.
SymCryptProvider/src/skeymgmt/p_scossl_aes_skeymgmt.c Wraps generic SKEYMGMT to enforce AES key sizing and type tagging.
SymCryptProvider/src/p_scossl_skey.h Introduces the internal SCOSSL_SKEY representation.
SymCryptProvider/src/p_scossl_base.c Registers SKEYMGMT algorithms under OSSL_OP_SKEYMGMT.
SymCryptProvider/src/mac/p_scossl_cmac.c Adds OSSL_FUNC_MAC_INIT_SKEY path for CMAC.
SymCryptProvider/src/ciphers/p_scossl_aes.c Adds OSSL_FUNC_CIPHER_*_SKEY_INIT support for AES non-AEAD modes.
SymCryptProvider/src/ciphers/p_scossl_aes_xts.c Adds OSSL_FUNC_CIPHER_*_SKEY_INIT support for AES-XTS.
SymCryptProvider/src/ciphers/p_scossl_aes_aead.c Adds OSSL_FUNC_CIPHER_*_SKEY_INIT support for AES-GCM/CCM.
SymCryptProvider/CMakeLists.txt Conditionally compiles SKEYMGMT sources for OpenSSL >= 3.5.

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

@mamckee mamckee requested a review from Copilot April 1, 2026 00:37
@mamckee mamckee marked this pull request as ready for review April 1, 2026 00:42
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 10 out of 10 changed files in this pull request and generated 5 comments.


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

Copy link
Copy Markdown
Contributor

@MS-megliu MS-megliu left a comment

Choose a reason for hiding this comment

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

(see inline comments)

}

status = SCOSSL_SUCCESS;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: If OSSL_SKEY_PARAM_KEY_LENGTH is not present in params, OSSL_PARAM_locate_const returns NULL, the function skips the entire key generation block, falls through to status = SCOSSL_SUCCESS here, and returns a NULL skey as success. The caller gets a NULL key with no error indication.

Same issue in p_scossl_generic_skeymgmt_import (line 89 of this file) — if OSSL_SKEY_PARAM_RAW_BYTES is absent, returns NULL without raising an error.

Suggestion: treat a missing required param as an error — ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_KEY) or equivalent before goto cleanup.

skey->type = SCOSSL_SKEY_TYPE_AES;

if (skey->cbKey != 16 && skey->cbKey != 24 && skey->cbKey != 32)
{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: AES key length is validated after p_scossl_generic_skeymgmt_import has already allocated secure memory and copied the key material. For invalid lengths, the key is allocated, copied, then immediately freed. Consider validating the length from the OSSL_PARAM before calling the generic import to avoid the wasted OPENSSL_secure_malloc + memcpy. Same applies to p_scossl_aes_skeygen_generate below — SymCryptRandom is called for invalid lengths.

_In_ const OSSL_PARAM params[])
{
return p_scossl_aes_xts_init_internal((SCOSSL_AES_XTS_CTX *)ctx, 1, skey->pbKey, skey->cbKey, iv, ivlen, params);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: Redundant cast — ctx is already declared as SCOSSL_AES_XTS_CTX *ctx in the function signature, so (SCOSSL_AES_XTS_CTX *)ctx is unnecessary.


find_package(OpenSSL REQUIRED)
find_package(OpenSSL 3.5 REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIR})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Question: This bumps the minimum OpenSSL requirement from any version to 3.5 globally, making the entire provider unbuildable with OpenSSL 3.0-3.4. The SKEYMGMT dispatch registration in p_scossl_base.c already uses #ifdef OSSL_OP_SKEYMGMT guards — was making 3.5 the hard minimum intentional? If not, the new source files could be conditionally compiled and the find_package left as-is.

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