Skip to content

Commit 9fd0228

Browse files
authored
Bugfixes for 1.9 (#150)
* Add OSSL_SIGNATURE_PARAM_NONCE_TYPE to ECDSA signature * Only optimize debug release builds * Only export EC public/private if available * Fix HMAC dupctx * Bump version to 1.9.4 * Add goto cleanup
1 parent 0ccc46c commit 9fd0228

File tree

9 files changed

+50
-7
lines changed

9 files changed

+50
-7
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.13.0)
22

33
project(SymCrypt-OpenSSL
4-
VERSION 1.9.3
4+
VERSION 1.9.4
55
DESCRIPTION "The SymCrypt engine and provider for OpenSSL (SCOSSL)"
66
HOMEPAGE_URL "https://github.com/microsoft/SymCrypt-OpenSSL")
77

ScosslCommon/inc/scossl_helpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ typedef enum {
118118
SCOSSL_ERR_F_GET_SYMCRYPT_HASH_ALGORITHM,
119119
SCOSSL_ERR_F_GET_SYMCRYPT_MAC_ALGORITHM,
120120
SCOSSL_ERR_F_HKDF_DERIVE,
121+
SCOSSL_ERR_F_MAC_DUPCTX,
121122
SCOSSL_ERR_F_MAC_INIT,
122123
SCOSSL_ERR_F_MAC_SET_HMAC_MD,
123124
SCOSSL_ERR_F_RSA_DECRYPT,

ScosslCommon/src/scossl_helpers.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ static ERR_STRING_DATA SCOSSL_ERR_function_strings[] = {
7878
{ERR_PACK(0, SCOSSL_ERR_F_GET_SYMCRYPT_HASH_ALGORITHM, 0), "scossl_get_symcrypt_hash_algorithm"},
7979
{ERR_PACK(0, SCOSSL_ERR_F_GET_SYMCRYPT_MAC_ALGORITHM, 0), "scossl_get_symcrypt_hmac_algorithm"},
8080
{ERR_PACK(0, SCOSSL_ERR_F_HKDF_DERIVE, 0), "scossl_hkdf_derive"},
81+
{ERR_PACK(0, SCOSSL_ERR_F_MAC_DUPCTX, 0), "scossl_mac_dupctx"},
8182
{ERR_PACK(0, SCOSSL_ERR_F_MAC_INIT, 0), "scossl_mac_init"},
8283
{ERR_PACK(0, SCOSSL_ERR_F_MAC_SET_HMAC_MD, 0), "scossl_mac_set_hmac_md"},
8384
{ERR_PACK(0, SCOSSL_ERR_F_RSA_DECRYPT, 0), "scossl_rsa_decrypt"},

ScosslCommon/src/scossl_mac.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,20 @@ SCOSSL_MAC_CTX *scossl_mac_dupctx(SCOSSL_MAC_CTX *ctx)
118118

119119
if (ctx->macState != NULL)
120120
{
121+
if (copyCtx->expandedKey == NULL)
122+
{
123+
SCOSSL_LOG_ERROR(SCOSSL_ERR_F_MAC_DUPCTX, ERR_R_INTERNAL_ERROR,
124+
"Missing expandedKey in mac context when attempting to copy macState");
125+
goto cleanup;
126+
}
121127
SCOSSL_COMMON_ALIGNED_ALLOC_EX(macState, OPENSSL_malloc, SCOSSL_MAC_STATE, ctx->pMac->stateSize);
122128
if (macState == NULL)
123129
{
124130
goto cleanup;
125131
}
126132

127133
copyCtx->macState = macState;
128-
ctx->pMacEx->stateCopyFunc(ctx->macState, ctx->expandedKey, copyCtx->macState);
134+
ctx->pMacEx->stateCopyFunc(ctx->macState, copyCtx->expandedKey, copyCtx->macState);
129135
}
130136
}
131137

SymCryptProvider/src/keymgmt/p_scossl_ecc_keymgmt.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,9 +1262,11 @@ static SCOSSL_STATUS p_scossl_ecc_keymgmt_export(_In_ SCOSSL_ECC_KEY_CTX *keyCtx
12621262
goto cleanup;
12631263
}
12641264

1265-
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
1265+
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0 &&
1266+
keyCtx->initialized)
12661267
{
1267-
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)
1268+
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0 &&
1269+
SymCryptEckeyHasPrivateKey(keyCtx->key))
12681270
{
12691271
if (!p_scossl_ecc_keymgmt_get_private_key_bn(keyCtx, &bnPrivateKey, &cbPrivateKey) ||
12701272
!OSSL_PARAM_BLD_push_BN_pad(bld, OSSL_PKEY_PARAM_PRIV_KEY, bnPrivateKey, cbPrivateKey))

SymCryptProvider/src/signature/p_scossl_ecdsa_signature.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,24 @@ static SCOSSL_STATUS p_scossl_ecdsa_set_ctx_params(_Inout_ SCOSSL_ECDSA_CTX *ctx
365365
return SCOSSL_FAILURE;
366366
}
367367

368+
#ifdef OSSL_SIGNATURE_PARAM_NONCE_TYPE
369+
if ((p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_NONCE_TYPE)) != NULL)
370+
{
371+
unsigned int nonce_type;
372+
if (!OSSL_PARAM_get_uint(p, &nonce_type))
373+
{
374+
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
375+
return SCOSSL_FAILURE;
376+
}
377+
378+
if (nonce_type != 0)
379+
{
380+
ERR_raise(ERR_LIB_PROV, PROV_R_NOT_SUPPORTED);
381+
return SCOSSL_FAILURE;
382+
}
383+
}
384+
#endif
385+
368386
return SCOSSL_SUCCESS;
369387
}
370388

@@ -399,6 +417,15 @@ static SCOSSL_STATUS p_scossl_ecdsa_get_ctx_params(_In_ SCOSSL_ECDSA_CTX *ctx, _
399417
goto cleanup;
400418
}
401419

420+
#ifdef OSSL_SIGNATURE_PARAM_NONCE_TYPE
421+
if ((p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_NONCE_TYPE)) != NULL &&
422+
!OSSL_PARAM_set_uint(p, 0))
423+
{
424+
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
425+
goto cleanup;
426+
}
427+
#endif
428+
402429
if ((p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_ALGORITHM_ID)) != NULL)
403430
{
404431
int cbAid;

cmake-toolchain/LinuxUserMode-AMD64.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ set(CMAKE_SYSTEM_PROCESSOR AMD64)
77

88
# Define _AMD64_ to set up the correct SymCrypt macros, e.g. SYMCRYPT_CPU_AMD64
99
add_compile_options(-D_AMD64_)
10-
add_compile_options(-O3)
10+
if (CMAKE_BUILD_TYPE MATCHES Release|RelWithDebInfo)
11+
add_compile_options(-O3)
12+
endif()
1113

1214
# Enable a baseline of features for the compiler to support everywhere
1315
# Other than for SSSE3 we do not expect the compiler to generate these instructions anywhere other than with intrinsics

cmake-toolchain/LinuxUserMode-ARM.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ if(NOT CMAKE_HOST_SYSTEM_PROCESSOR MATCHES armv8l|ARM$|ARM32|aarch32 AND NOT SCO
2525
endif()
2626

2727
add_compile_options(-D_ARM_)
28-
add_compile_options(-O3)
28+
if (CMAKE_BUILD_TYPE MATCHES Release|RelWithDebInfo)
29+
add_compile_options(-O3)
30+
endif()

cmake-toolchain/LinuxUserMode-ARM64.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ endif()
3232

3333
# Define _ARM64_ to set up the correct SymCrypt macros, e.g. SYMCRYPT_CPU_ARM64
3434
add_compile_options(-D_ARM64_)
35-
add_compile_options(-O3)
35+
if (CMAKE_BUILD_TYPE MATCHES Release|RelWithDebInfo)
36+
add_compile_options(-O3)
37+
endif()

0 commit comments

Comments
 (0)