Skip to content

Commit e0f87f5

Browse files
committed
Replaced explicit OpenSSL version checks with a configure time define
of WITH_OPENSSL3. This has no real functional change but it's more flexible and easier to read.
1 parent 1aaa040 commit e0f87f5

11 files changed

+25
-48
lines changed

cipher-chachapoly-libcrypto-mt.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ struct chachapoly_ctx_mt {
104104
* internal poly1305 methods */
105105
#ifdef OPENSSL_HAVE_POLY_EVP
106106
EVP_MAC_CTX *poly_ctx;
107-
#elif (OPENSSL_VERSION_NUMBER < 0x30000000UL) && defined(EVP_PKEY_POLY1305)
107+
#elif !defined(WITH_OPENSSL3) && defined(EVP_PKEY_POLY1305)
108108
EVP_PKEY_CTX *poly_ctx;
109109
EVP_MD_CTX *md_ctx;
110110
EVP_PKEY *pkey;
@@ -393,7 +393,7 @@ chachapoly_new_mt(u_int startseqnr, const u_char * key, u_int keylen)
393393
explicit_bzero(&startseqnr, sizeof(startseqnr));
394394
return NULL;
395395
}
396-
#elif (OPENSSL_VERSION_NUMBER < 0x30000000UL) && defined(EVP_PKEY_POLY1305)
396+
#elif !defined(WITH_OPENSSL3) && defined(EVP_PKEY_POLY1305)
397397
ctx_mt->md_ctx = EVP_MD_CTX_new();
398398
ctx_mt->pkey = EVP_PKEY_new_mac_key(EVP_PKEY_POLY1305, NULL, ctx_mt->zeros,
399399
POLY1305_KEYLEN);
@@ -567,7 +567,7 @@ chachapoly_crypt_mt(struct chachapoly_ctx_mt *ctx_mt, u_int seqnr, u_char *dest,
567567
if (!do_encrypt) {
568568
const u_char *tag = src + aadlen + len;
569569
u_char expected_tag[POLY1305_TAGLEN];
570-
#if (OPENSSL_VERSION_NUMBER < 0x30000000UL) && defined(EVP_PKEY_POLY1305)
570+
#if !defined(WITH_OPENSSL3) && defined(EVP_PKEY_POLY1305)
571571
EVP_PKEY_CTX_ctrl(ctx_mt->poly_ctx, -1, EVP_PKEY_OP_SIGNCTX, EVP_PKEY_CTRL_SET_MAC_KEY, POLY1305_KEYLEN, ks->poly_key);
572572
EVP_DigestSignUpdate(ctx_mt->md_ctx, src, aadlen + len);
573573
ctx_mt->ptaglen = POLY1305_TAGLEN;
@@ -591,7 +591,7 @@ chachapoly_crypt_mt(struct chachapoly_ctx_mt *ctx_mt, u_int seqnr, u_char *dest,
591591
/* Crypt payload */
592592
fastXOR(dest+aadlen,src+aadlen,ks->mainStream,len);
593593
/* calculate and append tag */
594-
#if (OPENSSL_VERSION_NUMBER < 0x30000000UL) && defined(EVP_PKEY_POLY1305)
594+
#if !defined(WITH_OPENSSL3) && defined(EVP_PKEY_POLY1305)
595595
if (do_encrypt) {
596596
EVP_PKEY_CTX_ctrl(ctx_mt->poly_ctx, -1, EVP_PKEY_OP_SIGNCTX, EVP_PKEY_CTRL_SET_MAC_KEY, POLY1305_KEYLEN, ks->poly_key);
597597
EVP_DigestSignUpdate(ctx_mt->md_ctx, dest, aadlen + len);

cipher-ctr-mt-functions.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@
2424

2525
#include "includes.h"
2626

27-
#ifdef WITH_OPENSSL
2827
/* only for systems with OSSL 3 */
29-
#if OPENSSL_VERSION_NUMBER >= 0x30000000UL
28+
#ifdef WITH_OPENSSL3
3029
#include <stdarg.h>
3130
#include <string.h>
3231
#include <openssl/evp.h>
@@ -648,5 +647,4 @@ int aes_mt_do_cipher(void *vevp_ctx,
648647
return 1;
649648
}
650649

651-
#endif /*OPENSSL_VERSION_NUMBER */
652-
#endif /*WITH_OPENSSL*/
650+
#endif /*WITH_OPENSSL3*/

cipher-ctr-mt-functions.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@
3636
#include <openssl/aes.h>
3737
#endif
3838

39-
#ifdef WITH_OPENSSL
4039
/* only for systems with OSSL 3 */
41-
#if OPENSSL_VERSION_NUMBER >= 0x30000000UL
40+
#ifdef WITH_OPENSSL3
4241

4342
/*-------------------- TUNABLES --------------------*/
4443
/* maximum number of threads and queues */
@@ -139,6 +138,5 @@ void *aes_mt_newctx_256(void *);
139138
void *aes_mt_newctx_192(void *);
140139
void *aes_mt_newctx_128(void *);
141140

142-
#endif /* VERSION NUMBER */
143141
#endif /* WITH OPENSSL */
144142
#endif /* CTR_MT_FUNCS */

cipher-ctr-mt-provider.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222

2323
#include "includes.h"
2424

25-
#ifdef WITH_OPENSSL
2625
/* only for systems with OSSL 3.0+ */
27-
#if OPENSSL_VERSION_NUMBER >= 0x30000000UL
26+
#ifdef WITH_OPENSSL3
2827

2928
#include <sys/types.h>
3029
#include <string.h>
@@ -388,5 +387,4 @@ static int aes_mt_set_ctx_params(void *vctx, const OSSL_PARAM params[])
388387
return ok;
389388
}
390389

391-
#endif /*OPENSSL_VERSION_NUMBER */
392-
#endif /*WITH_OPENSSL*/
390+
#endif /*WITH_OPENSSL3*/

cipher-ctr-mt.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
*/
2424
#include "includes.h"
2525

26-
#if defined(WITH_OPENSSL)
27-
#if OPENSSL_VERSION_NUMBER < 0x30000000UL
26+
#if defined(WITH_OPENSSL) && !defined(WITH_OPENSSL3)
2827
#include <sys/types.h>
2928

3029
#include <stdarg.h>
@@ -652,12 +651,6 @@ ssh_aes_ctr_cleanup(EVP_CIPHER_CTX *ctx)
652651
}
653652

654653
/* <friedl> */
655-
/* we've stipped out support for LibreSSL and OpenSSL < 1.1
656-
* it was getting to be too much to maintain. If LibreSSL
657-
* ever incorporates the meth_new() functionality we'll
658-
* reinstate support in configure.ac
659-
* cjr 2/8/2023
660-
*/
661654
const EVP_CIPHER *
662655
evp_aes_ctr_mt(void)
663656
{
@@ -675,5 +668,4 @@ evp_aes_ctr_mt(void)
675668
# endif /*SSH_OLD_EVP*/
676669
return aes_ctr;
677670
}
678-
#endif /* OSSL VERSION NUMBER */
679-
#endif /* OSSL */
671+
#endif /* OSSL Check */

cipher.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
#include "openbsd-compat/openssl-compat.h"
5454

5555
/* for provider functions */
56-
#if OPENSSL_VERSION_NUMBER >= 0x30000000UL
56+
#ifdef WITH_OPENSSL3
5757
#include <openssl/err.h>
5858
#include <openssl/params.h>
5959
#include <openssl/provider.h>
@@ -381,7 +381,7 @@ cipher_init(struct sshcipher_ctx **ccp, const struct sshcipher *cipher,
381381
* we load our hpnssh provider. If it doesn't (OSSL < 1.1) then we use the
382382
* _meth_new process found in cipher-ctr-mt.c */
383383
if (strstr(cc->cipher->name, "ctr") && post_auth) {
384-
#if OPENSSL_VERSION_NUMBER >= 0x30000000UL
384+
#ifdef WITH_OPENSSL3
385385
/* this version of openssl uses providers */
386386
OSSL_LIB_CTX *aes_lib = NULL; /* probably not needed */
387387
OSSL_PROVIDER *aes_mt_provider = NULL;
@@ -420,7 +420,7 @@ cipher_init(struct sshcipher_ctx **ccp, const struct sshcipher *cipher,
420420
* then we'd only have to call EVP_CIPHER_meth once but this
421421
* works for now. TODO: This. cjr 02.22.2023 */
422422
cc->meth_ptr = type;
423-
#endif /* OPENSSL_VERSION_NUMBER */
423+
#endif /* WITH_OPENSSL3 */
424424
} /* if (strstr()) */
425425
if (EVP_CipherInit(cc->evp, type, NULL, (u_char *)iv,
426426
(do_encrypt == CIPHER_ENCRYPT)) == 0) {

configure.ac

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,21 +2851,20 @@ if test "x$openssl" = "xyes" ; then
28512851
200*) AC_MSG_ERROR([LibreSSL versions older than 3.7 are no longer suported by HPN-SSH.])
28522852
;; # LibreSSL unsupported versions
28532853
Libre*) ;; # LibreSSL that supports evp_cipher_meth_* functions
2854-
# 300*) ;; # OpenSSL 3
2855-
# 301*) ;; # OpenSSL development branch.
2856-
# 302*) ;; # OpenSSL master branch
2857-
# *)
28582854
300*)
28592855
# OpenSSL 3; we use the 1.1x API
28602856
CPPFLAGS="$CPPFLAGS -DOPENSSL_API_COMPAT=0x10100000L"
2857+
AC_DEFINE([WITH_OPENSSL3], [1], [With OpenSSL3])
28612858
;;
28622859
301*|302*)
28632860
# OpenSSL development branch; request 1.1x API
28642861
CPPFLAGS="$CPPFLAGS -DOPENSSL_API_COMPAT=0x10100000L"
2862+
AC_DEFINE([WITH_OPENSSL3], [1], [With OpenSSL3])
28652863
;;
28662864
302*)
28672865
# OpenSSL Master Branch; request 1.1x API
28682866
CPPFLAGS="$CPPFLAGS -DOPENSSL_API_COMPAT=0x10100000L"
2867+
AC_DEFINE([WITH_OPENSSL3], [1], [With OpenSSL3])
28692868
;;
28702869
*)
28712870
AC_MSG_ERROR([Unknown/unsupported OpenSSL version ("$ssl_library_ver")])

num.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
#include <string.h>
44
#include "num.h"
55

6-
#ifdef WITH_OPENSSL
7-
#if OPENSSL_VERSION_NUMBER >= 0x30000000UL
6+
#ifdef WITH_OPENSSL3
87

98
typedef enum { BIG = 1, LITTLE = -1 } endian_t;
109
typedef enum { NEGATIVE = 0xff, POSITIVE = 0x00 } sign_t;
@@ -154,5 +153,4 @@ static struct resultdesc provnum_copy(struct numdesc dest, struct numdesc src)
154153

155154
implement_provnum(size_t, OSSL_PARAM_UNSIGNED_INTEGER)
156155

157-
#endif /* OPENSSL_VERSION_NUMBER >= 0x30000000UL */
158-
#endif /* WITH_OPENSSL */
156+
#endif /* WITH_OPENSSL3 */

num.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/* CC0 license applied, see LICENCE.md */
22

33
#include "includes.h"
4-
#ifdef WITH_OPENSSL
5-
#if OPENSSL_VERSION_NUMBER >= 0x30000000UL
4+
#ifdef WITH_OPENSSL3
65

76
#include <openssl/core.h>
87

@@ -13,5 +12,4 @@ int provnum_set_size_t(OSSL_PARAM *param, size_t src);
1312
#define PROVNUM_E_WRONG_TYPE -1
1413
#define PROVNUM_E_TOOBIG -2
1514
#define PROVNUM_E_UNSUPPORTED -3
16-
#endif /* OPENSSL_VERSION_NUMBER >= 0x30000000UL */
17-
#endif /* WITH_OPENSSL */
15+
#endif /* WITH_OPENSSL3 */

ossl3-provider-err.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
#include <stdlib.h>
55
#include "ossl3-provider-err.h"
66

7-
#ifdef WITH_OPENSSL
8-
#if OPENSSL_VERSION_NUMBER >= 0x30000000UL
7+
#ifdef WITH_OPENSSL3
98

109
struct proverr_functions_st {
1110
const OSSL_CORE_HANDLE *core;
@@ -106,5 +105,4 @@ void proverr_set_error(const struct proverr_functions_st *handle,
106105
va_end(ap);
107106
}
108107

109-
#endif /* OPENSSL_VERSION_NUMBER >= 0x30000000UL */
110-
#endif /* WITH_OPENSSL */
108+
#endif /* WITH_OPENSSL3 */

0 commit comments

Comments
 (0)