From fda82eff86d5f59575eb24d0586b48af7a9608de Mon Sep 17 00:00:00 2001 From: Dustin <6962246+djdarcy@users.noreply.github.com> Date: Thu, 14 May 2026 16:30:02 -0400 Subject: [PATCH] core: Find Python-bundled libcrypto on Windows On Python 3.8+ Windows, ctypes.util.find_library() can't see Python's own DLLs/ dir because it's no longer on the DLL search path. Fall back to scanning sys.{base_,}prefix/DLLs for libcrypto-*.dll before LoadLibrary(None) raises TypeError. Layered on top of #306, which only works on systems that already have libcrypto.dll in system32 from another package. Closes #316. --- bitcoin/core/key.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/bitcoin/core/key.py b/bitcoin/core/key.py index 0f902c8c..a0f1cc63 100644 --- a/bitcoin/core/key.py +++ b/bitcoin/core/key.py @@ -18,15 +18,34 @@ import ctypes import ctypes.util import hashlib +import os +import sys from os import urandom import bitcoin import bitcoin.signature import bitcoin.core.script + +def _find_bundled_libcrypto(): + # On Python 3.8+ Windows, sys.{base_,}prefix/DLLs is no longer on the DLL + # search path, so find_library can't see the libcrypto-*.dll Python ships. + if sys.platform != 'win32': + return None + for base in (sys.base_prefix, sys.prefix): + d = os.path.join(base, 'DLLs') + if not os.path.isdir(d): + continue + for name in os.listdir(d): + low = name.lower() + if low.startswith('libcrypto-') and low.endswith('.dll'): + return os.path.join(d, name) + return None + + _ssl = ctypes.cdll.LoadLibrary( ctypes.util.find_library('ssl.35') or ctypes.util.find_library('ssl') or ctypes.util.find_library('libeay32') - or ctypes.util.find_library('libcrypto') + or ctypes.util.find_library('libcrypto') or _find_bundled_libcrypto() ) _libsecp256k1_path = ctypes.util.find_library('secp256k1')