← Back to section · Tutorials & Labs
Project: A Post-Quantum Certificate Chain Size Calculator
A zero-dependency tool in pure standard-library Python: turn the parameter tables of FIPS 203/204/205 into data, accumulate public key and signature sizes level by level, and compute exactly how many bytes a certificate chain gains when it moves to post-quantum algorithms.
One of the most common questions in post-quantum migration is: “If we move to ML-DSA, how big does our certificate chain get — will the TLS handshake still fit?” This question needs no packet capture and no lab environment; it is arithmetic over a table lookup plus accumulation. This project builds exactly that tool: pure Python standard library, zero dependencies, with a built-in parameter table for post-quantum algorithms. The input is a chain length and the algorithm at each level; the output is a per-level breakdown and a total byte count, plus a comparison multiple against a classical ECDSA baseline. Small as it is, it demonstrates a very practical engineering skill: turning the parameter tables in standards documents into executable data structures, so planning discussions move from “it feels a lot bigger” to “9.4 KB bigger, and here is the derivation”. The boundary: the tool produces planning-grade estimates; real certificates float with extensions, encodings, and policy fields, so verify against real samples before any formal deployment decision.
Goal and Architecture
The calculator takes three inputs: the chain’s level list (root, intermediates, leaf, top to bottom), the signature algorithm chosen at each level, and the algorithm of the public key carried in each certificate. The size model is deliberately plain: one certificate costs approximately the public key bytes in its to-be-signed body, plus the signature bytes its issuer placed on it, plus structural overhead (serial number, validity, names, extensions — this project uses 400 bytes and marks it in code as an estimate). The leaf additionally carries its CertificateVerify signature from the TLS handshake. The sum approximates the certificate message size in a handshake, directly comparable against the common rule of thumb for the TCP initial congestion window (about 14.6 KB) to judge whether an extra round trip appears.
Why does this arithmetic deserve a dedicated tool? Because certificate growth is multiplied by every single handshake: for a service handling millions of handshakes a day, every extra kilobyte on the chain multiplies by the connection count into real bandwidth and latency cost; and on narrowband links such as IoT or satellite, one extra handshake round trip can mean a connection timeout. Worse, chain size does not grow in a vacuum — it must be totalled together with TLS record fragmentation, the TCP initial congestion window, and middlebox tolerance for large handshakes. Settling this ledger at planning time means a migration review cannot be waved through with “it gets a bit bigger, probably”.
The architecture has three layers. The data layer is a read-only dictionary table; each entry records the algorithm name, public key bytes, signature or ciphertext bytes, and the source clause the numbers came from. The compute layer is a pure function from a level configuration to an itemized breakdown. The presentation layer prints a table and the comparison against the classical baseline. The point of the layering is auditability: anyone who doubts a number only has to check one row of the data layer and its citation, not hunt through computation logic.
Walking Through the Core Code
The data table is the soul of this project; an excerpt (all values from published standards):
# Sources: FIPS 204 Tables 1/2 (ML-DSA), FIPS 205 Table 1 (SLH-DSA),
# SP 800-208 (XMSS/LMS); the classical baseline uses common P-256 encodings
SIGNATURE_SIZES = {
"ML-DSA-44": {"pk": 1312, "sig": 2420},
"ML-DSA-65": {"pk": 1952, "sig": 3309},
"ML-DSA-87": {"pk": 2592, "sig": 4627},
"SLH-DSA-SHA2-128s": {"pk": 32, "sig": 7856},
"ECDSA-P256": {"pk": 64, "sig": 71}, # baseline: raw point coords, typical DER sig
}
OVERHEAD_PER_CERT = 400 # estimate: names/validity/extensions and other fields
def chain_size(chain: list[str]) -> int:
total = 0
for i, alg in enumerate(chain):
total += SIGNATURE_SIZES[alg]["pk"] + OVERHEAD_PER_CERT
if i + 1 < len(chain) or True:
total += SIGNATURE_SIZES[alg]["sig"] if i > 0 else 0
return total
The sketch above deliberately keeps an awkward construct to make a point in the walkthrough: a root certificate’s signature is self-issued, and the root is normally not even sent in a TLS chain, so “which levels’ signatures count and which do not” must be decided at modelling time. The final version’s rule is: every transmitted certificate counts its own public key plus the issuer’s signature on it, and the leaf additionally counts one handshake signature. There is no standard answer to such convention questions, but the convention must be written into the README and defined in exactly one place, so two people using the same tool never produce two different numbers. A second detail is the ECDSA baseline: the public key is the 64 bytes of uncompressed point coordinates and the signature is the typical DER-encoded value of about 71 bytes — both common planning conventions in the industry, and both marked in the table as conventions rather than standardized constants. Separating “standard values” from “empirical values” right in the data layer is the single most transferable trick in this small tool.
Running and Verifying
Verification has three layers. First, a single-point hand check: compute one ML-DSA-65 leaf certificate by hand (1952 key + 3309 signature + 400 overhead = 5661 bytes, excluding the handshake signature) and align it line by line with the tool’s output. Second, compare against published industry measurements: a three-level all-ML-DSA-65 chain should land in the 9–15 KB range depending on intermediate count and whether the root is counted; if the tool says 3 KB or 40 KB, the model is wrong. Third, extreme-value sanity: an all-SLH-DSA-128s chain must be dramatically larger than an all-ML-DSA-44 chain (the signature line alone differs by more than 3×), and the all-ECDSA baseline must sit around one to two KB — if the direction feels wrong, a table row was copied incorrectly. Estimating tools are validated exactly this way, by the dual common sense of magnitude and direction, not by precision to the last digit.
Exercises
One: add the KEM side — extend the table with the public key and ciphertext sizes of the three ML-KEM parameter sets and compute the key_share increment of a hybrid TLS handshake, putting it in the same ledger as the certificate increment. Two: add the sizes of CT log SCTs and stapled OCSP responses, and discuss why planning so often forgets them. Three: add a budget mode — given a total byte budget, work backwards to the strongest algorithm combination each level may choose. Four, the advanced one: reconcile the estimate against a real sample — generate a real self-signed ECDSA certificate with OpenSSL, compare the actual byte count from openssl x509 -text against the tool’s estimate, write down which fields the error comes from, and recalibrate the 400-byte overhead accordingly.
Summary
The technical content of this calculator is not in its code but in its attitude: numbers must have sources, estimates must be labelled as estimates, and conventions must have exactly one definition. Take those three habits with you and, whenever someone asks what switching algorithms will cost, you can hand over an auditable ledger instead of a feeling. And the final reminder: it outputs planning estimates — before a real deployment, verify against real certificate samples. Estimates point the direction; samples settle the facts.
Tags: Certificate ChainsParameter CalculationFIPS 204Standard Library