Merge bitcoin/bitcoin#36838: guix: backport oscrypto PBKDF2 timing fix
What changed, and why it matters
This change fixes a build-time bug in Bitcoin Core's release-signing toolchain. A helper library called oscrypto could crash with a 'division by zero' error when measuring how fast a password-stretching routine (PBKDF2) runs on very fast machines. The patch simply makes sure the measured time is never rounded down to zero, so the calculation can complete. It does not change Bitcoin's consensus rules, networking, or wallet code, and it is not a security vulnerability in Bitcoin itself.
No urgent action needed for node operators or wallet users. For maintainers, ensure the backported patch is included in release branches and remove it once Guix ships an oscrypto release containing the upstream fix. Review the patch file path and checksums if reproducing release builds.
Security signals we found
Fixes a divide-by-zero / ZeroDivisionError in a dependency build script
Backports an upstream timing-measurement fix for PBKDF2 benchmark
Applies only to Guix codesigning manifest and patched oscrypto package
No change to consensus, P2P, wallet, or cryptographic algorithms in Bitcoin Core
Evidence from the diff
The commit backports an upstream oscrypto patch (wbond/oscrypto@144c1219) into Bitcoin Core’s Guix codesigning manifest. OpenSSL 3.5.5, pulled in by a recent Guix time-machine bump, can execute oscrypto’s PBKDF2 benchmark in under one millisecond. oscrypto’s _get_elapsed() returned an integer number of milliseconds, truncating sub-millisecond durations to 0, which then caused a ZeroDivisionError in pbkdf2_iteration_calculator(). The patch changes _get_elapsed() to return a float and clamps observed_ms to at least 1. The patch is applied only to the Guix codesigning package set (contrib/guix/manifest_codesign.scm) and affects the release build environment, not runtime Bitcoin Core code.
Changed components
contrib/guix/manifest_codesign.scmcontrib/guix/patches/oscrypto-pbkdf2-timing.patchGuix codesigning build environmentoscrypto Python package (build-time dependency)Inspect captured patch +42 / −1
### contrib/guix/manifest_codesign.scm
@@ -3,15 +3,23 @@
((gnu packages crypto) #:select (osslsigncode))
((gnu packages nss) #:select (nss-certs))
((gnu packages python-build) #:select (python-poetry-core python-setuptools))
- ((gnu packages python-crypto) #:select (python-asn1crypto python-oscrypto))
+ ((gnu packages python-crypto)
+ #:select (python-asn1crypto
+ (python-oscrypto . guix:python-oscrypto)))
((gnu packages tls) #:select (openssl))
((gnu packages version-control) #:select (git-minimal))
(guix build-system python)
(guix build-system pyproject)
+ ((guix gexp) #:select (local-file))
(guix git-download)
((guix licenses) #:prefix license:)
(guix packages))
+(define-public python-oscrypto
+ ;; Avoid division by zero when PBKDF2 takes less than a millisecond.
+ (package-with-extra-patches guix:python-oscrypto
+ (list (local-file "patches/oscrypto-pbkdf2-timing.patch"))))
+
(define-public python-elfesteem
(let ((commit "2eb1e5384ff7a220fd1afacd4a0170acff54fe56"))
(package
### contrib/guix/patches/oscrypto-pbkdf2-timing.patch
@@ -0,0 +1,33 @@
+From 144c12195001b08b9ccecb8a3fd041d22ae24474 Mon Sep 17 00:00:00 2001
+From: wbond <will@wbond.net>
+Date: Mon, 13 Jul 2026 19:28:28 -0400
+Subject: [PATCH] Handle KDF generation on very fast ARM machines
+
+---
+ oscrypto/kdf.py | 6 ++++--
+ 1 file changed, 4 insertions(+), 2 deletions(-)
+
+diff --git a/oscrypto/kdf.py b/oscrypto/kdf.py
+index 5db07cd..961f105 100644
+--- a/oscrypto/kdf.py
++++ b/oscrypto/kdf.py
+@@ -50,8 +50,8 @@ def _get_start():
+ def _get_elapsed(start):
+ length = datetime.now() - start
+ seconds = length.seconds + (length.days * 24 * 3600)
+- milliseconds = (length.microseconds / 10 ** 3)
+- return int(milliseconds + (seconds * 10 ** 3))
++ milliseconds = length.microseconds / 10 ** 3
++ return milliseconds + (seconds * 10 ** 3)
+
+
+ def pbkdf2_iteration_calculator(hash_algorithm, key_length, target_ms=100, quiet=False):
+@@ -135,6 +135,8 @@ def _measure():
+ start = _get_start()
+ pbkdf2(hash_algorithm, password, salt, iterations, key_length)
+ observed_ms = _get_elapsed(start)
++ if observed_ms < 1:
++ observed_ms = 1
+ if not quiet:
+ print('%s iterations in %sms' % (iterations, observed_ms))
+ return 1.0 / target_ms * observed_msWhy this scored 19/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.