Skip to content

Commit 8f98300

Browse files
committed
OpenSSL 1.0.2 build fix
1 parent 9da9f92 commit 8f98300

5 files changed

Lines changed: 29 additions & 6 deletions

File tree

src/libp11-int.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ extern int ERR_load_CKR_strings(void);
200200
#define PKCS11_DUP(s) \
201201
pkcs11_strdup((char *) s, sizeof(s))
202202
extern char *pkcs11_strdup(char *, size_t);
203+
extern void *pkcs11_zalloc(size_t);
204+
extern void pkcs11_clear_free(void *, size_t);
203205

204206
/* Emulate the OpenSSL 1.1 getters */
205207
#if OPENSSL_VERSION_NUMBER < 0x10100003L || ( defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x3000000L )

src/libpkcs11.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,9 @@ C_LoadModule(const char *mspec, CK_FUNCTION_LIST_PTR_PTR funcs,
7171
if (funcs_3_2)
7272
*funcs_3_2 = NULL;
7373

74-
mod = OPENSSL_zalloc(sizeof(sc_pkcs11_module_t));
74+
mod = pkcs11_zalloc(sizeof(sc_pkcs11_module_t));
7575
if (!mod)
7676
return NULL;
77-
7877
mod->_magic = MAGIC;
7978

8079
/* The caller intentionally selects the PKCS#11 module to load. */

src/p11_ec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ static int pkcs11_ecdh_derive(unsigned char **out, size_t *outlen,
584584
if (pkcs11_evp_pkey_ecdh_derive(key,
585585
params->pPublicData, params->ulPublicDataLen,
586586
cofactor_mode, secret, &secretlen) <= 0) {
587-
OPENSSL_clear_free(secret, (size_t)key_len);
587+
pkcs11_clear_free(secret, (size_t)key_len);
588588
return -1;
589589
}
590590

src/p11_misc.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@ char *pkcs11_strdup(char *mem, size_t size)
3939
return res;
4040
}
4141

42+
void *pkcs11_zalloc(size_t size)
43+
{
44+
void *mem = OPENSSL_malloc(size);
45+
46+
if (mem)
47+
memset(mem, 0, size);
48+
return mem;
49+
}
50+
51+
void pkcs11_clear_free(void *mem, size_t size)
52+
{
53+
if (mem) {
54+
OPENSSL_cleanse(mem, size);
55+
OPENSSL_free(mem);
56+
}
57+
}
58+
4259
int pkcs11_atomic_add(int *value, int amount, pthread_mutex_t *lock)
4360
{
4461
#if defined( _WIN32)

src/p11_pkey.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ static CK_RV pkcs11_derive_with_mechanism(PKCS11_OBJECT_private *key,
658658
if (newkey != CK_INVALID_HANDLE)
659659
CRYPTOKI_call(ctx, C_DestroyObject(session, newkey));
660660

661-
OPENSSL_clear_free(value, value_len_alloc);
661+
pkcs11_clear_free(value, value_len_alloc);
662662
pkcs11_session_pool_release(slot, session);
663663
return rv;
664664
}
@@ -784,7 +784,7 @@ static CK_RV pkcs11_decapsulate_with_mechanism(
784784
if (newkey != CK_INVALID_HANDLE)
785785
CRYPTOKI_call(ctx, C_DestroyObject(session, newkey));
786786

787-
OPENSSL_clear_free(value, value_len_alloc);
787+
pkcs11_clear_free(value, value_len_alloc);
788788
pkcs11_session_pool_release(slot, session);
789789
return rv;
790790
}
@@ -863,7 +863,12 @@ static int pkcs11_build_digestinfo(const char *mdname,
863863
if (x509_sig == NULL)
864864
return 0;
865865

866+
#if OPENSSL_VERSION_NUMBER < 0x10100000L
867+
alg = x509_sig->algor;
868+
digest = x509_sig->digest;
869+
#else
866870
X509_SIG_getm(x509_sig, &alg, &digest);
871+
#endif
867872

868873
if (!X509_ALGOR_set0(alg, OBJ_nid2obj(EVP_MD_type(md)), V_ASN1_NULL, NULL))
869874
goto err;
@@ -1341,7 +1346,7 @@ extern int pkcs11_evp_pkey_ecdh_derive(PKCS11_OBJECT_private *key,
13411346

13421347
rv = pkcs11_derive_with_mechanism(key, &mechanism, secret, secretlen);
13431348

1344-
OPENSSL_clear_free(der_pub, der_pub_len);
1349+
pkcs11_clear_free(der_pub, der_pub_len);
13451350

13461351
if (rv != CKR_OK)
13471352
return -1;

0 commit comments

Comments
 (0)