Skip to content

Commit 2f01cb4

Browse files
committed
Secure malloc and free primes and private exponent
1 parent 07ca0d8 commit 2f01cb4

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

SymCryptProvider/src/keymgmt/p_scossl_rsa_keymgmt.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,8 +1064,8 @@ static BOOL p_scossl_rsa_keymgmt_match(_In_ SCOSSL_PROV_RSA_KEY_CTX *keyCtx1, _I
10641064
cleanup:
10651065
OPENSSL_free(pbModulus1);
10661066
OPENSSL_free(pbModulus2);
1067-
OPENSSL_secure_free(pbPrivateExponent1);
1068-
OPENSSL_secure_free(pbPrivateExponent2);
1067+
OPENSSL_secure_clear_free(pbPrivateExponent1, cbModulus);
1068+
OPENSSL_secure_clear_free(pbPrivateExponent2, cbModulus);
10691069

10701070
return ret;
10711071
}
@@ -1114,7 +1114,7 @@ static SCOSSL_STATUS p_scossl_rsa_keymgmt_import(_Inout_ SCOSSL_PROV_RSA_KEY_CTX
11141114
{
11151115
cbModulus = p->data_size;
11161116

1117-
pbModulus = OPENSSL_zalloc(cbModulus);
1117+
pbModulus = OPENSSL_malloc(cbModulus);
11181118
if (pbModulus == NULL)
11191119
{
11201120
ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
@@ -1141,7 +1141,7 @@ static SCOSSL_STATUS p_scossl_rsa_keymgmt_import(_Inout_ SCOSSL_PROV_RSA_KEY_CTX
11411141
{
11421142
pcbPrimes[0] = p->data_size;
11431143

1144-
ppbPrimes[0] = OPENSSL_zalloc(pcbPrimes[0]);
1144+
ppbPrimes[0] = OPENSSL_secure_malloc(pcbPrimes[0]);
11451145
if (ppbPrimes[0] == NULL)
11461146
{
11471147
ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
@@ -1160,7 +1160,7 @@ static SCOSSL_STATUS p_scossl_rsa_keymgmt_import(_Inout_ SCOSSL_PROV_RSA_KEY_CTX
11601160
{
11611161
pcbPrimes[1] = p->data_size;
11621162

1163-
ppbPrimes[1] = OPENSSL_zalloc(pcbPrimes[1]);
1163+
ppbPrimes[1] = OPENSSL_secure_malloc(pcbPrimes[1]);
11641164
if(ppbPrimes[1] == NULL)
11651165
{
11661166
ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
@@ -1182,7 +1182,7 @@ static SCOSSL_STATUS p_scossl_rsa_keymgmt_import(_Inout_ SCOSSL_PROV_RSA_KEY_CTX
11821182
{
11831183
cbPrivateExponent = p->data_size;
11841184

1185-
pbPrivateExponent = OPENSSL_zalloc(cbPrivateExponent);
1185+
pbPrivateExponent = OPENSSL_secure_malloc(cbPrivateExponent);
11861186
if(pbPrivateExponent == NULL)
11871187
{
11881188
ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
@@ -1271,10 +1271,10 @@ static SCOSSL_STATUS p_scossl_rsa_keymgmt_import(_Inout_ SCOSSL_PROV_RSA_KEY_CTX
12711271
ret = SCOSSL_SUCCESS;
12721272

12731273
cleanup:
1274-
OPENSSL_free(pbPrivateExponent);
1274+
OPENSSL_secure_clear_free(pbPrivateExponent, cbModulus);
1275+
OPENSSL_secure_clear_free(ppbPrimes[0], pcbPrimes[0]);
1276+
OPENSSL_secure_clear_free(ppbPrimes[1], pcbPrimes[1]);
12751277
OPENSSL_free(pbModulus);
1276-
OPENSSL_free(ppbPrimes[0]);
1277-
OPENSSL_free(ppbPrimes[1]);
12781278
BN_free(bn);
12791279

12801280
return ret;

0 commit comments

Comments
 (0)