From nobody Sat May 27 19:21:58 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QTBVx2b9Mz4VBt3; Sat, 27 May 2023 19:22:01 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QTBVx28Nbz482Z; Sat, 27 May 2023 19:22:01 +0000 (UTC) (envelope-from jhb@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685215321; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VSy/CyTv78jds9wBLEDdiX6P9r4r4HK+bU+dylaHvuM=; b=o+h3vQonD6DaTrMIj5tITF/86uc+sQ+PCop5t9MVAZS4LOhwWsOS0xxpP+r4MZGJNMOiPd NsTQ8dzYA7OvCNBhB4i6xhQOJPJ9pXbT+PnW4OTMUoMA9ytUBWf0rdsozj/7CcwEgvtRZc jaXTaa0YkY9vdEYxsEUYvG4owWhjy1tGtMdvqE2XIljeNddHcVk9/icsP1P2BQRCnKb0m8 zsetNHKYZs9Vgi2zjYUSIbrEEbrRHcH1u3K8dA8bn/HukXpF6+UDTdd+J7IN+14UQk01n/ Yo6CXH2VHZj+krrz9p13DXSEx2RH3sy6c8ZeciXY7IoMY1OB1DOODjul8wNQgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685215321; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VSy/CyTv78jds9wBLEDdiX6P9r4r4HK+bU+dylaHvuM=; b=ffdUsZFl15YkPH0R6qBpXsCKMLnHdJ/faAX4R/9pLI6STAiB3VPGvnwEhm2862WsO2X57R mXb3TT2ZEofIbpG2WObZLgRqEZ0kWbHxL/t9bwoX5uqa16/3SC8tglb3GOJ6YgNAg/SgQX zZJPZl/hfzhuzTQpO22Lnx/UzV2iPusLy06DCdccAzL3ZdBJ+/Mx38pSZTSTQpd0FWcL/7 mjiSOwA5Z0r1b7a0nFpc/ZntuAkoVIt6ABRT08LtN4g1Y35daSUSNYszVplC6c5IpOCyfC FxYiM+URuJv+Miqb2033QLx9UIALgvON2N+/xC8bD8Rq+5YE3+pym9gKUpGaTg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1685215321; a=rsa-sha256; cv=none; b=qlZfHpNB7Vr3T9w5cNxV/TP0y9IrwJN/czEcR/cJ8qkX3F11H7cf6jl4RoHwSYVGoDk+aR qAYMiWbsZ4k4UORBO8P05PeCTSRHbkyn0AvRd76hW1z3PDcvzSRDVYf5/Y1RdxaESiWaLI s645qL41cbpg80EUMphnxoHmKAbQif9Kt5kk3bZLCDdqkcde0It5W78qN+btEGJBiysrHb d7pQpdRNeFXLGlj5m96fyDf6F+uM0fGRpz8wCNYfhRYVdv6lhDyO9uy1lDzMak8qKAABZb zrxhVmyD2dqSW8h5qw2IqGnmcb26Unxta7QXzeFzExULlwh77y44FFo2VbeM1w== Received: from [IPV6:2601:648:8680:16b0:186d:70a9:97fb:a487] (unknown [IPv6:2601:648:8680:16b0:186d:70a9:97fb:a487]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: jhb) by smtp.freebsd.org (Postfix) with ESMTPSA id 4QTBVw4v9JzLlh; Sat, 27 May 2023 19:22:00 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Message-ID: <626f675b-f304-b772-61a4-0a92283ac348@FreeBSD.org> Date: Sat, 27 May 2023 12:21:58 -0700 List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Content-Language: en-US To: Enji Cooper , src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org References: <202305271811.34RIBtHY093538@gitrepo.freebsd.org> From: John Baldwin Subject: Re: git: 537cd766435c - main - factor: support OpenSSL 3 In-Reply-To: <202305271811.34RIBtHY093538@gitrepo.freebsd.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ThisMailContainsUnwantedMimeParts: N On 5/27/23 11:11 AM, Enji Cooper wrote: > The branch main has been updated by ngie: > > URL: https://cgit.FreeBSD.org/src/commit/?id=537cd766435c80e61e72bb9369f77aa9630a1537 > > commit 537cd766435c80e61e72bb9369f77aa9630a1537 > Author: Enji Cooper > AuthorDate: 2023-05-27 04:55:12 +0000 > Commit: Enji Cooper > CommitDate: 2023-05-27 18:11:44 +0000 > > factor: support OpenSSL 3 > > This change ports the BN APIs to an OpenSSL 3 compatible set of APIs. > > This removes the need for requesting OpenSSL 1.1 compatible APIs. > > MFC after: 1 week > Reviewed by: emaste > Differential Revision: https://reviews.freebsd.org/D40298 > --- > usr.bin/factor/Makefile | 1 - > usr.bin/factor/factor.c | 17 +++++++++++++++-- > 2 files changed, 15 insertions(+), 3 deletions(-) > > diff --git a/usr.bin/factor/Makefile b/usr.bin/factor/Makefile > index 255160ef6e00..ffa9ec7de1f8 100644 > --- a/usr.bin/factor/Makefile > +++ b/usr.bin/factor/Makefile > @@ -9,7 +9,6 @@ CFLAGS+=-I${SRCTOP}/usr.bin/primes > > .if ${MK_OPENSSL} != "no" > CFLAGS+=-DHAVE_OPENSSL > -CFLAGS+=-DOPENSSL_API_COMPAT=0x10100000L > LIBADD+=crypto > .endif > > diff --git a/usr.bin/factor/factor.c b/usr.bin/factor/factor.c > index 4edc2ed2a72c..a3b0a65b5eca 100644 > --- a/usr.bin/factor/factor.c > +++ b/usr.bin/factor/factor.c > @@ -209,7 +209,11 @@ pr_fact(BIGNUM *val) > if (!BN_sqr(bnfact, bnfact, ctx)) > errx(1, "error in BN_sqr()"); > if (BN_cmp(bnfact, val) > 0 || > +#if OPENSSL_VERSION_NUMBER >= 0x30000000L > + BN_check_prime(val, NULL, NULL) == 1) > +#else > BN_is_prime_ex(val, PRIME_CHECKS, NULL, NULL) == 1) > +#endif > pr_print(val); > else > pollard_pminus1(val); > @@ -282,7 +286,11 @@ newbase: > errx(1, "error in BN_gcd()"); > > if (!BN_is_one(x)) { > +#if OPENSSL_VERSION_NUMBER >= 0x30000000L > + if (BN_check_prime(x, NULL, NULL) == 1) > +#else > if (BN_is_prime_ex(x, PRIME_CHECKS, NULL, NULL) == 1) > +#endif > pr_print(x); > else > pollard_pminus1(x); > @@ -291,8 +299,13 @@ newbase: > BN_div(num, NULL, val, x, ctx); > if (BN_is_one(num)) > return; > - if (BN_is_prime_ex(num, PRIME_CHECKS, NULL, > - NULL) == 1) { > +#if OPENSSL_VERSION_NUMBER >= 0x30000000L > + if (BN_check_prime(num, NULL, NULL) == 1) > +#else > + if (BN_is_prime_ex(num, PRIME_CHECKS, NULL, NULL) > + == 1) > +#endif > + { > pr_print(num); > fflush(stdout); > return; I would suggest restructing this by having a compat shim for the 3.0 API at the top of the file (something like this): #if OPENSSL_VERSION_NUMBER < 0x30000000L #define PRIME_CHECKS 5 static int BN_check_prime(const BIGNUM *p, BN_CTX *ctx, BN_GENCB *cb) { return (BN_is_prime_ex(p, PRIME_CHECKS, ctx, cb)); } #endif And then just using BN_check_prime in the rest of the file without #ifdef's. This is the approach we used for OpenSSL 1.1.x and will result in fewer #ifdef's and cleaner code overall. One thing we didn't do for OpenSSL 1.1.x but could choose to do in this case is to define a header with these shims that could be shared to reduce the work needed to update programs to move away from APIs deprecated in 3.0. -- John Baldwin