mv os.urandom sanity check to main __init__.py
What changed, and why it matters
This commit simply moves an existing safety check from one file to another. It does not add new security behavior or fix a known vulnerability. The check makes sure the system's random number generator appears healthy when Electrum starts.
No action required. Treat as routine refactor.
Security signals we found
os.urandom health check relocated, not added or removed
No cryptographic logic changed
No vulnerability described in commit message or diff
Evidence from the diff
The commit relocates an os.urandom sanity check from electrum/rsakey.py to electrum/init.py. The check compresses 1000 bytes from os.urandom and raises ImportError if the compressed length is 900 bytes or less, which would suggest a non-random source. The change is a code refactor in preparation for deleting rsakey.py. No security defect is introduced or patched.
Changed components
electrum/__init__.pyelectrum/rsakey.pyInspect captured patch +7 / −4
diff --git a/electrum/__init__.py b/electrum/__init__.py
index 793f293..e94ac78 100644
--- a/electrum/__init__.py
+++ b/electrum/__init__.py
@@ -46,3 +46,10 @@ except AssertionError:
else:
raise ImportError("Running with asserts disabled. Refusing to continue. Exiting...")
+
+# Check that os.urandom works
+import zlib
+length = len(zlib.compress(os.urandom(1000)))
+if length <= 900:
+ raise ImportError("Broken PRNG. Refusing to continue. Exiting...")
+
diff --git a/electrum/rsakey.py b/electrum/rsakey.py
index da87076..5266e9c 100644
--- a/electrum/rsakey.py
+++ b/electrum/rsakey.py
@@ -46,10 +46,6 @@ def SHA1(x):
# PRNG Functions
# **************************************************************************
-# Check that os.urandom works
-import zlib
-length = len(zlib.compress(os.urandom(1000)))
-assert length > 900
def getRandomBytes(howMany):
b = bytearray(os.urandom(howMany))
Why this scored 12/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.