commit:     3d73b3e95dc70779c1db649503f5e3a5a39e2bf7
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Thu Feb 12 23:33:48 2026 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Thu Feb 12 23:34:47 2026 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=3d73b3e9

net-vpn/tor: fix big-endian issues in 0.4.9.5

Done in a -r1 as it's not yet merged upstream.

Signed-off-by: Sam James <sam <AT> gentoo.org>

 net-vpn/tor/files/tor-0.4.9.5-big-endian.patch |  97 ++++++++++++
 net-vpn/tor/tor-0.4.9.5-r1.ebuild              | 203 +++++++++++++++++++++++++
 2 files changed, 300 insertions(+)

diff --git a/net-vpn/tor/files/tor-0.4.9.5-big-endian.patch 
b/net-vpn/tor/files/tor-0.4.9.5-big-endian.patch
new file mode 100644
index 000000000000..5defc4103f67
--- /dev/null
+++ b/net-vpn/tor/files/tor-0.4.9.5-big-endian.patch
@@ -0,0 +1,97 @@
+https://gitlab.torproject.org/tpo/core/tor/-/merge_requests/990
+
+From 64b5638bf0d31e70f0832317fffc47c92b28e5ab Mon Sep 17 00:00:00 2001
+From: Nick Mathewson <[email protected]>
+Date: Thu, 12 Feb 2026 14:56:58 -0500
+Subject: [PATCH] Fix an absolutely silly pile-up of big-endian bugs in
+ polyval.c
+
+Only big-endian systems are affected.
+
+First off, the non-gcc fallback algorithm for byte swapping was wrong:
+We were OR-ing all the input bytes into the low 8 bits of the output.
+
+Secondly, the non-gcc fallback code was broken: it was referring to "value",
+when the input was called "v".
+
+Finally and more significantly, the big-endian detection was wrong:
+We were looking at WORDS_BIG_ENDIAN, when the actual autoconf macro
+is WORDS_BIGENDIAN.
+
+Closes bug #41215.
+---
+ changes/bug41215          |  3 +++
+ src/ext/polyval/polyval.c | 31 ++++++++++++++++---------------
+ 2 files changed, 19 insertions(+), 15 deletions(-)
+ create mode 100644 changes/bug41215
+
+diff --git a/changes/bug41215 b/changes/bug41215
+new file mode 100644
+index 0000000000..d2d715ba5a
+--- /dev/null
++++ b/changes/bug41215
+@@ -0,0 +1,3 @@
++  o Minor bugfixes (portability):
++    - (Hopefully) fix our polyval implementation on big-endian platforms.
++      Fixes bug 41215; bugfix on 0.4.9.3-alpha.
+diff --git a/src/ext/polyval/polyval.c b/src/ext/polyval/polyval.c
+index 9f64734e0f..157ba54044 100644
+--- a/src/ext/polyval/polyval.c
++++ b/src/ext/polyval/polyval.c
+@@ -84,38 +84,39 @@ static void pv_mul_y_h(polyval_t *);h
+ /* =====
+  * Endianness conversion for big-endian platforms
+  */
+-#ifdef WORDS_BIG_ENDIAN
++#ifdef WORDS_BIGENDIAN
+ #ifdef __GNUC__
+ #define bswap64(x) __builtin_bswap64(x)
+ #define bswap32(x) __builtin_bswap32(x)
+ #else
+ /* The (compiler should optimize these into a decent bswap instruction) */
+ static inline uint64_t
+-bswap64(uint64_t v)
++bswap64(uint64_t value)
+ {
+   return
+     ((value & 0xFF00000000000000) >> 56) |
+-    ((value & 0x00FF000000000000) >> 48) |
+-    ((value & 0x0000FF0000000000) >> 40) |
+-    ((value & 0x000000FF00000000) >> 32) |
+-    ((value & 0x00000000FF000000) >> 24) |
+-    ((value & 0x0000000000FF0000) >> 16) |
+-    ((value & 0x000000000000FF00) >> 8) |
+-    ((value & 0x00000000000000FF));
++    ((value & 0x00FF000000000000) >> 40) |
++    ((value & 0x0000FF0000000000) >> 24) |
++    ((value & 0x000000FF00000000) >> 8) |
++    ((value & 0x00000000FF000000) << 8) |
++    ((value & 0x0000000000FF0000) << 24) |
++    ((value & 0x000000000000FF00) << 40) |
++    ((value & 0x00000000000000FF) << 56);
+ }
+-static inline uint64_t
+-bswap32(uint64_t v)
++
++static inline uint32_t
++bswap32(uint32_t value)
+ {
+   return
+     ((value & 0xFF000000) >> 24) |
+-    ((value & 0x00FF0000) >> 16) |
+-    ((value & 0x0000FF00) >> 8) |
+-    ((value & 0x000000FF));
++    ((value & 0x00FF0000) >> 8) |
++    ((value & 0x0000FF00) << 8) |
++    ((value & 0x000000FF) << 24);
+ }
+ #endif
+ #endif
+ 
+-#ifdef WORDS_BIG_ENDIAN
++#ifdef WORDS_BIGENDIAN
+ #define convert_byte_order64(x) bswap64(x)
+ #define convert_byte_order32(x) bswap32(x)
+ #else
+-- 
+GitLab

diff --git a/net-vpn/tor/tor-0.4.9.5-r1.ebuild 
b/net-vpn/tor/tor-0.4.9.5-r1.ebuild
new file mode 100644
index 000000000000..c0942649184d
--- /dev/null
+++ b/net-vpn/tor/tor-0.4.9.5-r1.ebuild
@@ -0,0 +1,203 @@
+# Copyright 1999-2026 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+PYTHON_COMPAT=( python3_{11..14} )
+VERIFY_SIG_OPENPGP_KEY_PATH=/usr/share/openpgp-keys/torproject.org.asc
+inherit edo python-any-r1 readme.gentoo-r1 systemd verify-sig
+
+MY_PV="$(ver_rs 4 -)"
+MY_PF="${PN}-${MY_PV}"
+DESCRIPTION="Anonymizing overlay network for TCP"
+HOMEPAGE="https://www.torproject.org/ 
https://gitlab.torproject.org/tpo/core/tor/";
+
+if [[ ${PV} == 9999 ]] ; then
+       EGIT_REPO_URI="https://gitlab.torproject.org/tpo/core/tor";
+       inherit autotools git-r3
+else
+       SRC_URI="
+               https://www.torproject.org/dist/${MY_PF}.tar.gz
+               
https://archive.torproject.org/tor-package-archive/${MY_PF}.tar.gz
+               verify-sig? (
+                       https://dist.torproject.org/${MY_PF}.tar.gz.sha256sum
+                       
https://dist.torproject.org/${MY_PF}.tar.gz.sha256sum.asc
+               )
+       "
+
+       S="${WORKDIR}/${MY_PF}"
+
+       if [[ ${PV} != *_alpha* && ${PV} != *_beta* && ${PV} != *_rc* ]]; then
+               KEYWORDS="~amd64 ~arm ~arm64 ~hppa ~mips ~ppc ~ppc64 ~riscv 
~sparc ~x86"
+       fi
+
+       BDEPEND="verify-sig? ( >=sec-keys/openpgp-keys-tor-20250713 )"
+fi
+
+# BSD in general, but for PoW, needs --enable-gpl (GPL-3 per --version)
+# We also already had GPL-2 listed here for the init script, but obviously
+# that's different from the actual binary.
+LICENSE="BSD GPL-2 GPL-3"
+SLOT="0"
+IUSE="caps doc hardened lzma +man scrypt seccomp selinux +server systemd test 
zstd"
+RESTRICT="!test? ( test )"
+
+RDEPEND="
+       >=dev-libs/libevent-2.1.12-r1:=[ssl]
+       >=dev-libs/openssl-1.1.1:=[-bindist(-)]
+       virtual/zlib:=
+       caps? ( sys-libs/libcap )
+       man? ( app-text/asciidoc )
+       lzma? ( app-arch/xz-utils )
+       scrypt? ( app-crypt/libscrypt )
+       seccomp? ( >=sys-libs/libseccomp-2.4.1 )
+       systemd? ( sys-apps/systemd:= )
+       zstd? ( app-arch/zstd:= )
+"
+DEPEND="
+       ${RDEPEND}
+       test? (
+               ${DEPEND}
+               ${PYTHON_DEPS}
+       )
+"
+RDEPEND+="
+       acct-user/tor
+       acct-group/tor
+       selinux? ( sec-policy/selinux-tor )
+"
+BDEPEND+="
+       acct-user/tor
+       acct-group/tor
+"
+
+DOCS=()
+
+PATCHES=(
+       "${FILESDIR}"/${PN}-0.2.7.4-torrc.sample.patch
+       "${FILESDIR}"/${PN}-0.4.9.5-big-endian.patch
+)
+
+QA_CONFIG_IMPL_DECL_SKIP=(
+       # test correctly fails because -lnacl fails if not available
+       # https://bugs.gentoo.org/900092
+       crypto_scalarmult_curve25519
+)
+
+pkg_setup() {
+       use test && python-any-r1_pkg_setup
+}
+
+src_unpack() {
+       if [[ ${PV} == 9999 ]] ; then
+               git-r3_src_unpack
+       else
+               if use verify-sig; then
+                       cd "${DISTDIR}" || die
+                       verify-sig_verify_detached 
${MY_PF}.tar.gz.sha256sum{,.asc}
+                       verify-sig_verify_unsigned_checksums \
+                               ${MY_PF}.tar.gz.sha256sum sha256 ${MY_PF}.tar.gz
+                       cd "${WORKDIR}" || die
+               fi
+
+               default
+       fi
+}
+
+src_prepare() {
+       default
+
+       # Running shellcheck automagically isn't useful for ebuild testing.
+       echo "exit 0" > scripts/maint/checkShellScripts.sh || die
+
+       if [[ ${PV} == 9999 ]] ; then
+               eautoreconf
+       fi
+}
+
+src_configure() {
+       use doc && DOCS+=( README.md ChangeLog ReleaseNotes doc/HACKING )
+
+       export ac_cv_lib_cap_cap_init=$(usex caps)
+       export tor_cv_PYTHON="${EPYTHON}"
+       # Already set by default in profiles for our toolchain
+       export tor_cv_cflags__fcf_protection_full=no
+       export tor_cv_cflags__mbranch_protection_standard=no
+
+       local myeconfargs=(
+               --localstatedir="${EPREFIX}/var"
+               --disable-all-bugs-are-fatal
+               --enable-system-torrc
+               --disable-android
+               --disable-coverage
+               --disable-html-manual
+               --disable-libfuzzer
+               --enable-missing-doc-warnings
+               --disable-module-dirauth
+               --enable-pic
+               --disable-restart-debugging
+
+               # Unless someone asks & has a compelling reason, just always
+               # build in GPL mode for pow, given we don't want yet another USE
+               # flag combination to have to test just for the sake of it.
+               # (PoW requires GPL.)
+               --enable-gpl
+               --enable-module-pow
+
+               $(use_enable hardened gcc-hardening)
+               $(use_enable hardened linker-hardening)
+               $(use_enable man asciidoc)
+               $(use_enable man manpage)
+               $(use_enable lzma)
+               $(use_enable scrypt libscrypt)
+               $(use_enable seccomp)
+               $(use_enable server module-relay)
+               $(use_enable systemd)
+               $(use_enable test unittests)
+               $(use_enable zstd)
+       )
+
+       econf "${myeconfargs[@]}"
+}
+
+src_test() {
+       local skip_tests=(
+               # Fails in sandbox
+               :sandbox/open_filename
+               :sandbox/openat_filename
+       )
+
+       if use arm ; then
+               skip_tests+=(
+                       # bug #920905
+                       # 
https://gitlab.torproject.org/tpo/core/tor/-/issues/40912
+                       :sandbox/opendir_dirname
+                       :sandbox/openat_filename
+                       :sandbox/chmod_filename
+                       :sandbox/chown_filename
+                       :sandbox/rename_filename
+               )
+       fi
+
+       # The makefile runs these by parallel by chunking them with a script
+       # but that means we lose verbosity and can't skip individual tests 
easily
+       # either.
+       edo ./src/test/test --verbose "${skip_tests[@]}"
+}
+
+src_install() {
+       default
+       readme.gentoo_create_doc
+
+       newconfd "${FILESDIR}"/tor.confd tor
+       newinitd "${FILESDIR}"/tor.initd-r9 tor
+       systemd_dounit "${FILESDIR}"/tor.service
+
+       keepdir /var/lib/tor
+
+       fperms 750 /var/lib/tor
+       fowners tor:tor /var/lib/tor
+
+       insinto /etc/tor/
+       newins "${FILESDIR}"/torrc-r2 torrc
+}

Reply via email to