AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Informational 15 Bitcoin

crypto: add runtime sanity checks

Public commit record

What the developer wrote

Authored by SomberNight

78/100 · Adequate
crypto: add runtime sanity checks

- if one of the critical hash functions is broken, we should panic early
(sha256/sha512/hash160), as the consequences could be devastating.
- sha512 is used for bip32
- sha256/hash160 are used for deriving addresses

- but we might as well also test the symmetric ciphers
- though those checks are a bit slower
- but I would prefer erring on the side of paranoia and doing the check

naive benchmarks:
(it's not AES that is slow, but the first invocations of the symmetric ciphers)
```
>>> from electrum.crypto import *
backends: HAS_CRYPTODOME=True, HAS_CRYPTOGRAPHY=False
time taken by 'hash functions1': 0.065 msec
time taken by 'aes1': 3.377 msec
time taken by 'aes2': 0.047 msec
time taken by 'chacha20': 0.182 msec
time taken by 'chacha20-poly1305': 0.405 msec
total time taken: 4.235 msec
```
```
>>> from electrum.crypto import *
backends: HAS_CRYPTODOME=False, HAS_CRYPTOGRAPHY=True
time taken by 'hash functions1': 0.064 msec
time taken by 'aes1': 7.131 msec
time taken by 'aes2': 0.040 msec
time taken by 'chacha20': 0.056 msec
time taken by 'chacha20-poly1305': 0.023 msec
total time taken: 7.446 msec
```
✓ Descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Mentions testing or verification
The short version

What changed, and why it matters

This commit adds self-tests to Electrum's cryptography code. When the program starts, it now runs a few known test vectors through hash and encryption functions and crashes immediately if the results are wrong. This is a defensive hardening change, not a fix for an active security flaw.

Recommended action

No immediate action required. Treat as routine hardening. Review whether assert-based failures are surfaced clearly to users in release builds.

Security signals we found

01

defensive runtime self-tests for cryptographic primitives

02

fail-fast assertions on hash and cipher backends

03

no change to protocol logic, parsing, or wallet handling

Risk score

Why this scored 15/100

Our methodology →
Potential impact 0/30
Exploitability 0/25
Stealth signal 0/15
Affected reach 0/15
Confidence 10/10
Evidence quality 5/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.