Cryptographic Entropy, Chi‑Square, and Serial Correlation: What One Key Can Reveal | Understanding Key Entropy, Bias, and Structural Weaknesses in Single‑Key Analysis

Entropy Lab began as a simple playground for randomness analysis — a way to visualize entropy, test key generation, and explore how different sources behave. But over time, it grew into something more ambitious: a tool people rely on to generate cryptographic keys for real‑world protocols like Bitcoin and Nostr. That responsibility demanded a deeper look at how keys were generated, validated, and derived. The result was a full overhaul of Entropy Lab’s cryptographic core. Here’s a breakdown of the major changes and why they matter.

Moving Away from bitcoin-lib.js

The original version of Entropy Lab used bitcoin-lib.js (and indirectly, the older elliptic library) to generate secp256k1 keypairs. While functional, this approach had several drawbacks:

  • Heavy dependency footprint
  • Legacy code with inconsistent browser support
  • No native Schnorr support (required for Nostr)
  • Difficult to load without bundlers or npm
  • Not ideal for modern ES module workflows

We replaced this entire stack with noble‑secp256k1, a modern, audited, browser‑native implementation of secp256k1 and Schnorr signatures.

This change alone dramatically simplified the codebase and improved security.


Secure Private Key Generation Using window.crypto

We validated that window.crypto.getRandomValues() is:

  • A true CSPRNG
  • Backed by OS entropy
  • Safe for cryptographic key generation
  • Not affected by historical “Randstorm” vulnerabilities

But we also added the missing piece: scalar validation. A valid secp256k1 private key must satisfy a strict mathematical rule curve order. Entropy Lab now re‑rolls values until a valid scalar is produced. This ensures every generated key is mathematically valid and safe.


Edge‑Case Rejection and Output Normalization

We added safeguards to avoid pathological or human‑generated patterns:

  • All‑zero keys
  • All‑FF keys
  • Keys with extremely low Hamming weight
  • Keys near the curve order

We also normalize output to:

  • 32‑byte hex
  • lowercase
  • padded
  • clean and consistent

This brings Entropy Lab in line with professional wallet behavior.


A More Accurate Entropy Analyzer

While not directly part of the cryptographic overhaul, the entropy analyzer now:

  • Handles 32‑byte inputs more gracefully
  • Avoids false positives on high‑entropy data
  • Provides clearer visualizations

This makes it easier to compare entropy sources like:

  • window.crypto
  • noble’s DRBG
  • user‑typed input
  • external randomness

The Math Behind QF: What It Actually Measures — and Its Limits

Cryptographic strength is exponential, but not every weakness shows up in a single 32‑byte sample. Through extensive testing, we’ve learned that some generators leave unmistakable structural fingerprints — while others (like weak PRNGs and LCGs) can appear deceptively normal when viewed one key at a time.

Entropy Lab’s Quality Factor (QF) is not a prediction of crack time.
It is a structural health score that summarizes what can be detected from a single key.

Below is the realistic interpretation of QF and Effective Security Bits.


What QF Can Detect Reliably

From a single 32‑byte key, we can confidently detect:

low entropy key

Shannon entropy < 3.5, uneven distribution, missing symbols.

patterned key

Mirrored halves, repeated blocks, low‑uniqueness byte pairs.

ramp key

Monotonic or near‑monotonic sequences (ascending/descending).

biased key

Chi‑Square extremes, alphabet collapse, clumping.

template key

Fixed structure with only a few changing bytes.

catastrophic correlation

SCC > 0.8 or < –0.8 (predictable transitions).

These are the cases where QF and Effective Security Bits drop sharply — and correctly.


What QF Cannot Detect Reliably

Some generators produce weak keys but look statistically normal when viewed one at a time:

weak PRNG key

A weak PRNG can output a single sample that looks perfectly random.

lcg key

Linear congruential generators can produce “normal‑looking” 32‑byte slices.

These weaknesses only become obvious when analyzing multiple outputs, not a single key.

Therefore:

QF is not a universal weakness detector.
It is a structural anomaly detector.


Effective Security Bits

Effective Security Bits is not “crack time.”
It is:

How much of the 256‑bit space this key appears to occupy,
after subtracting detectable structural bias.

Examples:

  • QF = 0.46 → ~118 effective bits
  • QF = 0.95 → ~243 effective bits
  • QF = 0.02 → ~5 effective bits (extreme SCC case)

This does not mean the key is literally 5‑bit secure.
It means:

The structure of this key resembles something that could have been generated from a 5‑bit internal state.


Important Edge Cases

Some keys pass:

  • Shannon entropy
  • Chi‑Square
  • Pattern Score

…but still collapse due to:

Extreme Serial Correlation (SCC ≈ ±1.0)

This is the “silent killer” — invisible to entropy and chi‑square, but devastating to structure.

Example key:

e454c4b493cc8e8a89af4eff67f137cb5fdf47bc3da380b91ffb2af6bacdaf05

Metrics:

  • Shannon: 3.965
  • Chi‑Square: 240
  • Pattern Score: 1.00
  • SCC: –0.9898 ← catastrophic
  • Effective Security: 5 bits
  • QF: 0.02
  • Status: BAD KEY

This is not a bug — it’s exactly what structural analysis should detect.


What QF Really Represents

QF is a normalized score (0–1) summarizing detectable structural anomalies in a single 32‑byte key.
It does not measure true cryptographic strength.
It measures how “healthy” the key’s structure appears.

QF is meaningful only in the context of:

  • entropy
  • fairness
  • correlation
  • pattern complexity
  • structural anomalies

It is not a brute‑force estimator.


Conclusion

Entropy Lab now reflects the real limits and capabilities of single‑sample analysis. Some weaknesses are detectable from one 32‑byte key:

  • low entropy
  • biased distributions
  • catastrophic serial correlation
  • mirrored halves and repeated blocks
  • template‑like structure
  • ramps and monotonic sequences

These leave clear, measurable fingerprints in a single sample — and Entropy Lab catches them. Some weaknesses are not detectable from one key:

  • weak PRNGs
  • LCG‑based generators
  • small‑state deterministic generators

This isn’t a limitation of Entropy Lab — no tool on Earth can detect these from a single output. QF is therefore a structural quality score, not a cryptanalytic oracle. It summarizes what can be measured from one key:

  • entropy
  • fairness
  • correlation
  • structural complexity

Effective Security Bits represent apparent keyspace usage — not literal crack time — based on the structure visible in that single sample.

Extreme SCC or structural patterns can collapse QF even when entropy looks perfect, because structure, not distribution, is the real weakness.


Why Weak PRNGs and LCGs Cannot Be Detected from One Key

Even if an attacker knows the generator is weak, they still cannot crack a single key produced by it.
This isn’t about difficulty or compute power — it’s about information theory.

A single output simply does not contain enough information to reconstruct:

  • the seed
  • the internal state
  • the recurrence
  • the modulus
  • the multiplier
  • the increment
  • or any other generator parameters

Even if the attacker knows:

  • it’s an LCG
  • it’s a weak PRNG
  • it has a tiny internal state
  • it uses predictable math
  • it’s horribly insecure
    …they still cannot reverse it from one output.

Why? Because one output corresponds to infinitely many possible internal states and generator configurations. Weak PRNGs fail over time, not in single samples.


How Weak PRNGs Are Actually Broken

Attackers need multiple outputs, not one. They rely on:

  • several consecutive keys
  • predictable timestamps
  • predictable seeds
  • repeated outputs
  • correlations between outputs
  • known plaintext relationships

But never a single key. This is why weak PRNGs are dangerous in systems, not in isolated keys.


What Happens If You Only Have One Weak Key?

If you only have the key itself, and no additional outputs from the generator, there is no shortcut. You must attack it as if it were a normal 256‑bit key.

There is no:

  • “LCG crack” button
  • “weak PRNG reversal”
  • “seed recovery”
  • “state reconstruction”
    …from one output.

This is why Entropy Lab cannot detect weakPRNGKey from one key

  • No analyzer can
  • No cryptographer can
  • No attacker can

It is simply impossible.


The Final Reality

Entropy Lab reflects the true boundaries of single‑sample cryptanalysis:

  • It detects what can be detected from one key
  • It does not pretend to detect what is mathematically impossible
  • It exposes structural anomalies that do appear in a single sample
  • It avoids false confidence about weaknesses that require multiple outputs
  • It provides honest, interpretable metrics instead of misleading promises

And that’s exactly what it is built for.

https://youtu.be/aPQC4u0N9xk

Write a comment
No comments yet.