Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions ScosslCommon/src/scossl_aes_aead.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ SCOSSL_STATUS scossl_aes_gcm_init_key(SCOSSL_CIPHER_GCM_CTX *ctx,
return SCOSSL_FAILURE;
}
}

if (key != NULL)
{
scError = SymCryptGcmExpandKey(&ctx->key, SymCryptAesBlockCipher, key, keylen);
Expand All @@ -64,6 +65,7 @@ SCOSSL_STATUS scossl_aes_gcm_init_key(SCOSSL_CIPHER_GCM_CTX *ctx,
return SCOSSL_FAILURE;
}
}

return SCOSSL_SUCCESS;
}

Expand Down Expand Up @@ -299,7 +301,7 @@ SCOSSL_STATUS scossl_aes_gcm_set_iv_len(SCOSSL_CIPHER_GCM_CTX *ctx, size_t ivlen
if (ivlen != ctx->ivlen)
{
ctx->ivlen = ivlen;

if (ctx->iv != NULL)
{
OPENSSL_free(ctx->iv);
Expand Down Expand Up @@ -455,7 +457,7 @@ SCOSSL_STATUS scossl_aes_ccm_init_key(SCOSSL_CIPHER_CCM_CTX *ctx,

ctx->ccmStage = SCOSSL_CCM_STAGE_INIT;
ctx->cbData = 0;
if (iv)
if (iv != NULL)
{
if (!scossl_aes_ccm_set_iv_len(ctx, ivlen))
{
Expand All @@ -466,14 +468,16 @@ SCOSSL_STATUS scossl_aes_ccm_init_key(SCOSSL_CIPHER_CCM_CTX *ctx,
memcpy(ctx->iv, iv, ctx->ivlen);
ctx->ivSet = 1;
}
if (key)

if (key != NULL)
{
scError = SymCryptAesExpandKey(&ctx->key, key, keylen);
if (scError != SYMCRYPT_NO_ERROR)
{
return SCOSSL_FAILURE;
}
}

return SCOSSL_SUCCESS;
}

Expand Down
3 changes: 3 additions & 0 deletions ScosslCommon/src/scossl_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ SCOSSL_MAC_CTX *scossl_mac_dupctx(SCOSSL_MAC_CTX *ctx)
SCOSSL_STATUS success = SCOSSL_FAILURE;
SCOSSL_MAC_CTX *copyCtx = NULL;

if (ctx == NULL)
return NULL;

if ((copyCtx = OPENSSL_zalloc(sizeof(SCOSSL_MAC_CTX))) != NULL)
{
if (ctx->pbKey != NULL)
Expand Down
12 changes: 6 additions & 6 deletions SymCryptProvider/inc/p_scossl_base.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ static const OSSL_PARAM p_scossl_param_types[] = {
OSSL_PARAM_int(OSSL_PROV_PARAM_STATUS, NULL),
OSSL_PARAM_END};

// EVP_MD_CTX_dup is a helpful function for the provider, but was not added until OpenSSL 3.1
// This function is copied from 3.1 to allow its use when the provider is built against 3.0
#if OPENSSL_VERSION_MAJOR == 3 && OPENSSL_VERSION_MINOR == 0
EVP_MD_CTX *EVP_MD_CTX_dup(const EVP_MD_CTX *in);

#endif // OPENSSL_VERSION_MAJOR == 3 && OPENSSL_VERSION_MINOR == 0
// Helper function from the default provider that that is used by get/set
// parameter functions to avoid iterating through an empty parameter array.
static inline BOOL p_scossl_is_params_empty(_In_ const OSSL_PARAM params[])
{
return params == NULL || params->key == NULL;
}

#ifdef __cplusplus
}
Expand Down
17 changes: 17 additions & 0 deletions SymCryptProvider/src/asymcipher/p_scossl_rsa_cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ static SCOSSL_STATUS p_scossl_rsa_cipher_get_ctx_params(_In_ SCOSSL_RSA_CIPHER_C
{
OSSL_PARAM *p;

if (ctx == NULL)
{
ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_NULL_PARAMETER);
return SCOSSL_FAILURE;
}

if ((p = OSSL_PARAM_locate(params, OSSL_ASYM_CIPHER_PARAM_PAD_MODE)) != NULL)
{
int i = 0;
Expand Down Expand Up @@ -307,6 +313,17 @@ static SCOSSL_STATUS p_scossl_rsa_cipher_set_ctx_params(_Inout_ SCOSSL_RSA_CIPHE
const OSSL_PARAM *param_propq;
const char *mdName, *mdProps;

if (ctx == NULL)
{
ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_NULL_PARAMETER);
return SCOSSL_FAILURE;
}

if (p_scossl_is_params_empty(params))
{
return SCOSSL_SUCCESS;
}

if ((p = OSSL_PARAM_locate_const(params, OSSL_ASYM_CIPHER_PARAM_PAD_MODE)) != NULL)
{
// Padding mode may be passed as legacy NID or string, and is
Expand Down
24 changes: 22 additions & 2 deletions SymCryptProvider/src/ciphers/p_scossl_aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ static void p_scossl_aes_generic_freectx(SCOSSL_AES_CTX *ctx)

static SCOSSL_AES_CTX *p_scossl_aes_generic_dupctx(SCOSSL_AES_CTX *ctx)
{
if (ctx == NULL)
return NULL;

SCOSSL_COMMON_ALIGNED_ALLOC(copyCtx, OPENSSL_malloc, SCOSSL_AES_CTX);
if (copyCtx != NULL)
{
Expand Down Expand Up @@ -702,7 +705,13 @@ SCOSSL_STATUS p_scossl_aes_generic_get_params(_Inout_ OSSL_PARAM params[],

static SCOSSL_STATUS p_scossl_aes_generic_get_ctx_params(_In_ SCOSSL_AES_CTX *ctx, _Inout_ OSSL_PARAM params[])
{
OSSL_PARAM *p = NULL;
OSSL_PARAM *p;

if (ctx == NULL)
{
ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_NULL_PARAMETER);
return SCOSSL_FAILURE;
}

if ((p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_KEYLEN)) != NULL &&
!OSSL_PARAM_set_size_t(p, ctx->keylen))
Expand Down Expand Up @@ -746,7 +755,18 @@ static SCOSSL_STATUS p_scossl_aes_generic_get_ctx_params(_In_ SCOSSL_AES_CTX *ct

static SCOSSL_STATUS p_scossl_aes_generic_set_ctx_params(_Inout_ SCOSSL_AES_CTX *ctx, _In_ const OSSL_PARAM params[])
{
const OSSL_PARAM *p = NULL;
const OSSL_PARAM *p;

if (ctx == NULL)
{
ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_NULL_PARAMETER);
return SCOSSL_FAILURE;
}

if (p_scossl_is_params_empty(params))
{
return SCOSSL_SUCCESS;
}

if ((p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_PADDING)) != NULL)
{
Expand Down
Loading
Loading