diff --git a/src/openssl.c b/src/openssl.c index d7a63f24..c312f8e2 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -177,7 +177,7 @@ _libssh2_cipher_init(_libssh2_cipher_ctx * h, _libssh2_cipher_type(algo), unsigned char *iv, unsigned char *secret, int encrypt) { -#if OPENSSL_VERSION_NUMBER >= 0x10100000L +#ifdef HAVE_OPAQUE_STRUCTS *h = EVP_CIPHER_CTX_new(); return !EVP_CipherInit(*h, algo(), secret, iv, encrypt); #else @@ -196,7 +196,7 @@ _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx, (void) algo; (void) encrypt; -#if OPENSSL_VERSION_NUMBER >= 0x10100000L +#ifdef HAVE_OPAQUE_STRUCTS ret = EVP_Cipher(*ctx, buf, block, blocksize); #else ret = EVP_Cipher(ctx, buf, block, blocksize); @@ -249,7 +249,7 @@ aes_ctr_init(EVP_CIPHER_CTX *ctx, const unsigned char *key, if (c == NULL) return 0; -#if OPENSSL_VERSION_NUMBER >= 0x10100000L +#ifdef HAVE_OPAQUE_STRUCTS c->aes_ctx = EVP_CIPHER_CTX_new(); #else c->aes_ctx = malloc(sizeof(EVP_CIPHER_CTX)); @@ -260,7 +260,7 @@ aes_ctr_init(EVP_CIPHER_CTX *ctx, const unsigned char *key, } if (EVP_EncryptInit(c->aes_ctx, aes_cipher, key, NULL) != 1) { -#if OPENSSL_VERSION_NUMBER >= 0x10100000L +#ifdef HAVE_OPAQUE_STRUCTS EVP_CIPHER_CTX_free(c->aes_ctx); #else free(c->aes_ctx); @@ -329,7 +329,7 @@ aes_ctr_cleanup(EVP_CIPHER_CTX *ctx) /* cleanup ctx */ } if (c->aes_ctx != NULL) { -#if OPENSSL_VERSION_NUMBER >= 0x10100000L +#ifdef HAVE_OPAQUE_STRUCTS EVP_CIPHER_CTX_free(c->aes_ctx); #else _libssh2_cipher_dtor(c->aes_ctx); @@ -345,7 +345,7 @@ aes_ctr_cleanup(EVP_CIPHER_CTX *ctx) /* cleanup ctx */ static const EVP_CIPHER * make_ctr_evp (size_t keylen, EVP_CIPHER *aes_ctr_cipher, int type) { -#if OPENSSL_VERSION_NUMBER >= 0x10100000L +#ifdef HAVE_OPAQUE_STRUCTS aes_ctr_cipher = EVP_CIPHER_meth_new(type, 16, keylen); if (aes_ctr_cipher) { EVP_CIPHER_meth_set_iv_length(aes_ctr_cipher, 16); @@ -369,7 +369,7 @@ make_ctr_evp (size_t keylen, EVP_CIPHER *aes_ctr_cipher, int type) const EVP_CIPHER * _libssh2_EVP_aes_128_ctr(void) { -#if OPENSSL_VERSION_NUMBER >= 0x10100000L +#ifdef HAVE_OPAQUE_STRUCTS static EVP_CIPHER * aes_ctr_cipher; return !aes_ctr_cipher? make_ctr_evp (16, aes_ctr_cipher, NID_aes_128_ctr) : aes_ctr_cipher; @@ -383,7 +383,7 @@ _libssh2_EVP_aes_128_ctr(void) const EVP_CIPHER * _libssh2_EVP_aes_192_ctr(void) { -#if OPENSSL_VERSION_NUMBER >= 0x10100000L +#ifdef HAVE_OPAQUE_STRUCTS static EVP_CIPHER * aes_ctr_cipher; return !aes_ctr_cipher? make_ctr_evp (24, aes_ctr_cipher, NID_aes_192_ctr) : aes_ctr_cipher; @@ -397,7 +397,7 @@ _libssh2_EVP_aes_192_ctr(void) const EVP_CIPHER * _libssh2_EVP_aes_256_ctr(void) { -#if OPENSSL_VERSION_NUMBER >= 0x10100000L +#ifdef HAVE_OPAQUE_STRUCTS static EVP_CIPHER * aes_ctr_cipher; return !aes_ctr_cipher? make_ctr_evp (32, aes_ctr_cipher, NID_aes_256_ctr) : aes_ctr_cipher; @@ -619,7 +619,7 @@ _libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx, int _libssh2_sha1_init(libssh2_sha1_ctx *ctx) { -#if OPENSSL_VERSION_NUMBER >= 0x10100000L +#ifdef HAVE_OPAQUE_STRUCTS *ctx = EVP_MD_CTX_new(); if (*ctx == NULL) @@ -642,7 +642,7 @@ int _libssh2_sha1(const unsigned char *message, unsigned long len, unsigned char *out) { -#if OPENSSL_VERSION_NUMBER >= 0x10100000L +#ifdef HAVE_OPAQUE_STRUCTS EVP_MD_CTX * ctx = EVP_MD_CTX_new(); if (ctx == NULL) @@ -671,7 +671,7 @@ _libssh2_sha1(const unsigned char *message, unsigned long len, int _libssh2_sha256_init(libssh2_sha256_ctx *ctx) { -#if OPENSSL_VERSION_NUMBER >= 0x10100000L +#ifdef HAVE_OPAQUE_STRUCTS *ctx = EVP_MD_CTX_new(); if (*ctx == NULL) @@ -694,7 +694,7 @@ int _libssh2_sha256(const unsigned char *message, unsigned long len, unsigned char *out) { -#if OPENSSL_VERSION_NUMBER >= 0x10100000L +#ifdef HAVE_OPAQUE_STRUCTS EVP_MD_CTX * ctx = EVP_MD_CTX_new(); if (ctx == NULL) @@ -723,7 +723,7 @@ _libssh2_sha256(const unsigned char *message, unsigned long len, int _libssh2_md5_init(libssh2_md5_ctx *ctx) { -#if OPENSSL_VERSION_NUMBER >= 0x10100000L +#ifdef HAVE_OPAQUE_STRUCTS *ctx = EVP_MD_CTX_new(); if (*ctx == NULL) diff --git a/src/openssl.h b/src/openssl.h index 4b2e3d3c..3ca71fa8 100644 --- a/src/openssl.h +++ b/src/openssl.h @@ -53,6 +53,11 @@ #include #include +#if OPENSSL_VERSION_NUMBER >= 0x10100000L && \ + !defined(LIBRESSL_VERSION_NUMBER) +# define HAVE_OPAQUE_STRUCTS 1 +#endif + #ifdef OPENSSL_NO_RSA # define LIBSSH2_RSA 0 #else @@ -116,7 +121,7 @@ #define libssh2_prepare_iovec(vec, len) /* Empty. */ -#if OPENSSL_VERSION_NUMBER >= 0x10100000L +#ifdef HAVE_OPAQUE_STRUCTS #define libssh2_sha1_ctx EVP_MD_CTX * #else #define libssh2_sha1_ctx EVP_MD_CTX @@ -125,7 +130,7 @@ /* returns 0 in case of failure */ int _libssh2_sha1_init(libssh2_sha1_ctx *ctx); #define libssh2_sha1_init(x) _libssh2_sha1_init(x) -#if OPENSSL_VERSION_NUMBER >= 0x10100000L +#ifdef HAVE_OPAQUE_STRUCTS #define libssh2_sha1_update(ctx, data, len) EVP_DigestUpdate(ctx, data, len) #define libssh2_sha1_final(ctx, out) do { \ EVP_DigestFinal(ctx, out, NULL); \ @@ -139,7 +144,7 @@ int _libssh2_sha1(const unsigned char *message, unsigned long len, unsigned char *out); #define libssh2_sha1(x,y,z) _libssh2_sha1(x,y,z) -#if OPENSSL_VERSION_NUMBER >= 0x10100000L +#ifdef HAVE_OPAQUE_STRUCTS #define libssh2_sha256_ctx EVP_MD_CTX * #else #define libssh2_sha256_ctx EVP_MD_CTX @@ -148,7 +153,7 @@ int _libssh2_sha1(const unsigned char *message, unsigned long len, /* returns 0 in case of failure */ int _libssh2_sha256_init(libssh2_sha256_ctx *ctx); #define libssh2_sha256_init(x) _libssh2_sha256_init(x) -#if OPENSSL_VERSION_NUMBER >= 0x10100000L +#ifdef HAVE_OPAQUE_STRUCTS #define libssh2_sha256_update(ctx, data, len) EVP_DigestUpdate(ctx, data, len) #define libssh2_sha256_final(ctx, out) do { \ EVP_DigestFinal(ctx, out, NULL); \ @@ -162,7 +167,7 @@ int _libssh2_sha256(const unsigned char *message, unsigned long len, unsigned char *out); #define libssh2_sha256(x,y,z) _libssh2_sha256(x,y,z) -#if OPENSSL_VERSION_NUMBER >= 0x10100000L +#ifdef HAVE_OPAQUE_STRUCTS #define libssh2_md5_ctx EVP_MD_CTX * #else #define libssh2_md5_ctx EVP_MD_CTX @@ -171,7 +176,7 @@ int _libssh2_sha256(const unsigned char *message, unsigned long len, /* returns 0 in case of failure */ int _libssh2_md5_init(libssh2_md5_ctx *ctx); #define libssh2_md5_init(x) _libssh2_md5_init(x) -#if OPENSSL_VERSION_NUMBER >= 0x10100000L +#ifdef HAVE_OPAQUE_STRUCTS #define libssh2_md5_update(ctx, data, len) EVP_DigestUpdate(ctx, data, len) #define libssh2_md5_final(ctx, out) do { \ EVP_DigestFinal(ctx, out, NULL); \ @@ -182,7 +187,7 @@ int _libssh2_md5_init(libssh2_md5_ctx *ctx); #define libssh2_md5_final(ctx, out) EVP_DigestFinal(&(ctx), out, NULL) #endif -#if OPENSSL_VERSION_NUMBER >= 0x10100000L +#ifdef HAVE_OPAQUE_STRUCTS #define libssh2_hmac_ctx HMAC_CTX * #define libssh2_hmac_ctx_init(ctx) ctx = HMAC_CTX_new() #define libssh2_hmac_sha1_init(ctx, key, keylen) \ @@ -238,7 +243,7 @@ int _libssh2_md5_init(libssh2_md5_ctx *ctx); #define _libssh2_dsa_free(dsactx) DSA_free(dsactx) #define _libssh2_cipher_type(name) const EVP_CIPHER *(*name)(void) -#if OPENSSL_VERSION_NUMBER >= 0x10100000L +#ifdef HAVE_OPAQUE_STRUCTS #define _libssh2_cipher_ctx EVP_CIPHER_CTX * #else #define _libssh2_cipher_ctx EVP_CIPHER_CTX @@ -261,7 +266,7 @@ int _libssh2_md5_init(libssh2_md5_ctx *ctx); #define _libssh2_cipher_cast5 EVP_cast5_cbc #define _libssh2_cipher_3des EVP_des_ede3_cbc -#if OPENSSL_VERSION_NUMBER >= 0x10100000L +#ifdef HAVE_OPAQUE_STRUCTS #define _libssh2_cipher_dtor(ctx) EVP_CIPHER_CTX_reset(*(ctx)) #else #define _libssh2_cipher_dtor(ctx) EVP_CIPHER_CTX_cleanup(ctx)