Skip to content

Commit

Permalink
Fix: explicit defined() usage for CJOSE_OPENSSL_11X (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxwolf authored Feb 27, 2018
1 parent 65825b2 commit b6665de
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
4 changes: 3 additions & 1 deletion include/cjose/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
extern "C" {
#endif

#define CJOSE_OPENSSL_11X OPENSSL_VERSION_NUMBER >= 0x10100005L && !defined(LIBRESSL_VERSION_NUMBER)
#if OPENSSL_VERSION_NUMBER >= 0x10100005L && !defined(LIBRESSL_VERSION_NUMBER)
#define CJOSE_OPENSSL_11X
#endif

/**
* Macro to explicitly mark a parameter unused, and usable across multiple
Expand Down
2 changes: 1 addition & 1 deletion src/jwe.c
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ static bool _cjose_jwe_set_iv_aes_cbc(cjose_jwe_t *jwe, cjose_err *err)
return true;
}

#if (CJOSE_OPENSSL_11X)
#if defined(CJOSE_OPENSSL_11X)
#define CJOSE_EVP_CTRL_GCM_GET_TAG EVP_CTRL_AEAD_GET_TAG
#define CJOSE_EVP_CTRL_GCM_SET_TAG EVP_CTRL_AEAD_SET_TAG
#else
Expand Down
12 changes: 6 additions & 6 deletions src/jwk.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void _cjose_jwk_rsa_get(RSA *rsa, BIGNUM **rsa_n, BIGNUM **rsa_e, BIGNUM **rsa_d
{
if (rsa == NULL)
return;
#if (CJOSE_OPENSSL_11X)
#if defined(CJOSE_OPENSSL_11X)
RSA_get0_key(rsa, (const BIGNUM **)rsa_n, (const BIGNUM **)rsa_e, (const BIGNUM **)rsa_d);
#else
*rsa_n = rsa->n;
Expand All @@ -78,7 +78,7 @@ bool _cjose_jwk_rsa_set(RSA *rsa, uint8_t *n, size_t n_len, uint8_t *e, size_t e
if (d && d_len > 0)
rsa_d = BN_bin2bn(d, d_len, NULL);

#if (CJOSE_OPENSSL_11X)
#if defined(CJOSE_OPENSSL_11X)
return RSA_set0_key(rsa, rsa_n, rsa_e, rsa_d) == 1;
#else
rsa->n = rsa_n;
Expand All @@ -90,7 +90,7 @@ bool _cjose_jwk_rsa_set(RSA *rsa, uint8_t *n, size_t n_len, uint8_t *e, size_t e

void _cjose_jwk_rsa_get_factors(RSA *rsa, BIGNUM **p, BIGNUM **q)
{
#if (CJOSE_OPENSSL_11X)
#if defined(CJOSE_OPENSSL_11X)
RSA_get0_factors(rsa, (const BIGNUM **)p, (const BIGNUM **)q);
#else
*p = rsa->p;
Expand All @@ -107,7 +107,7 @@ void _cjose_jwk_rsa_set_factors(RSA *rsa, uint8_t *p, size_t p_len, uint8_t *q,
if (q && q_len > 0)
rsa_q = BN_bin2bn(q, q_len, NULL);

#if (CJOSE_OPENSSL_11X)
#if defined(CJOSE_OPENSSL_11X)
RSA_set0_factors(rsa, rsa_p, rsa_q);
#else
rsa->p = rsa_p;
Expand All @@ -117,7 +117,7 @@ void _cjose_jwk_rsa_set_factors(RSA *rsa, uint8_t *p, size_t p_len, uint8_t *q,

void _cjose_jwk_rsa_get_crt(RSA *rsa, BIGNUM **dmp1, BIGNUM **dmq1, BIGNUM **iqmp)
{
#if (CJOSE_OPENSSL_11X)
#if defined(CJOSE_OPENSSL_11X)
RSA_get0_crt_params(rsa, (const BIGNUM **)dmp1, (const BIGNUM **)dmq1, (const BIGNUM **)iqmp);
#else
*dmp1 = rsa->dmp1;
Expand All @@ -138,7 +138,7 @@ void _cjose_jwk_rsa_set_crt(
if (iqmp && iqmp_len > 0)
rsa_iqmp = BN_bin2bn(iqmp, iqmp_len, NULL);

#if (CJOSE_OPENSSL_11X)
#if defined(CJOSE_OPENSSL_11X)
RSA_set0_crt_params(rsa, rsa_dmp1, rsa_dmq1, rsa_iqmp);
#else
rsa->dmp1 = rsa_dmp1;
Expand Down
10 changes: 5 additions & 5 deletions src/jws.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ static bool _cjose_jws_build_dig_hmac_sha(cjose_jws_t *jws, const cjose_jwk_t *j
}

// instantiate and initialize a new mac digest context
#if (CJOSE_OPENSSL_11X)
#if defined(CJOSE_OPENSSL_11X)
ctx = HMAC_CTX_new();
#else
ctx = cjose_get_alloc()(sizeof(HMAC_CTX));
Expand All @@ -279,7 +279,7 @@ static bool _cjose_jws_build_dig_hmac_sha(cjose_jws_t *jws, const cjose_jwk_t *j
goto _cjose_jws_build_dig_hmac_sha_cleanup;
}

#if !(CJOSE_OPENSSL_11X)
#if !defined(CJOSE_OPENSSL_11X)
HMAC_CTX_init(ctx);
#endif

Expand Down Expand Up @@ -316,7 +316,7 @@ static bool _cjose_jws_build_dig_hmac_sha(cjose_jws_t *jws, const cjose_jwk_t *j
_cjose_jws_build_dig_hmac_sha_cleanup:
if (NULL != ctx)
{
#if (CJOSE_OPENSSL_11X)
#if defined(CJOSE_OPENSSL_11X)
HMAC_CTX_free(ctx);
#else
HMAC_CTX_cleanup(ctx);
Expand Down Expand Up @@ -565,7 +565,7 @@ static bool _cjose_jws_build_sig_ec(cjose_jws_t *jws, const cjose_jwk_t *jwk, cj
memset(jws->sig, 0, jws->sig_len);

const BIGNUM *pr, *ps;
#if (CJOSE_OPENSSL_11X)
#if defined(CJOSE_OPENSSL_11X)
ECDSA_SIG_get0(ecdsa_sig, &pr, &ps);
#else
pr = ecdsa_sig->r;
Expand Down Expand Up @@ -1007,7 +1007,7 @@ static bool _cjose_jws_verify_sig_ec(cjose_jws_t *jws, const cjose_jwk_t *jwk, c
ECDSA_SIG *ecdsa_sig = ECDSA_SIG_new();
int key_len = jws->sig_len / 2;

#if (CJOSE_OPENSSL_11X)
#if defined(CJOSE_OPENSSL_11X)
BIGNUM *pr = BN_new(), *ps = BN_new();
BN_bin2bn(jws->sig, key_len, pr);
BN_bin2bn(jws->sig + key_len, key_len, ps);
Expand Down
2 changes: 1 addition & 1 deletion src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static void cjose_apply_allocs()
{
// set upstream
json_set_alloc_funcs(cjose_get_alloc(), cjose_get_dealloc());
#if (CJOSE_OPENSSL_11X)
#if defined(CJOSE_OPENSSL_11X)
CRYPTO_set_mem_functions(cjose_get_alloc3(), cjose_get_realloc3(), cjose_get_dealloc3());
#else
CRYPTO_set_mem_functions(cjose_get_alloc(), cjose_get_realloc(), cjose_get_dealloc());
Expand Down

0 comments on commit b6665de

Please sign in to comment.