Revocation starts small. You kill one leaked key, the deployed clients learn about it, life goes on. Then the product gets popular. Chargebacks, shared keys, keys pasted into public gists, a reseller who went rogue — a few years in, the set of revoked keys is not one entry, it is thousands. Now the question that was trivial at n=1 is a distribution problem: how does every client in the field cheaply find out whether its key is on a list that keeps growing, without you shipping the whole list to everyone?
The naive answer — push the full set of revoked key identifiers to each client — fails on two fronts at once. It grows without bound, so the download and the on-device footprint creep up forever. And it is a plaintext roster of exactly which keys you revoked, sitting on every customer's disk, which is both an information leak and an invitation. We want the membership answer without the membership list.
The real question
What a client actually needs is a one-bit answer to "is this key revoked?" — and it needs the common case, not revoked, to be instant and offline. That is a set-membership test, and there is a classic structure built for exactly the case where the set is large, the membership test is hot, and you can tolerate a small, controlled error in one direction only: the Bloom filter.
A Bloom filter is a fixed-size bit array of m bits plus k independent hash functions. It answers membership with a crucial asymmetry. If it says not in the set, that is certain — no false negatives, ever. If it says in the set, that is probably true, with a tunable false-positive rate p. For revocation this asymmetry is exactly the one we want: a truly revoked key must always test positive (we can never let a revoked key slip through as "not revoked"), while a tiny fraction of good keys testing positive is acceptable as long as a positive is not the final verdict.
How the filter works
Insertion sets bits. To add a key, hash it k ways, each hash yielding an index in [0, m), and set those k bits to 1. Membership tests the same bits: hash the candidate the same k ways, and if any of those bits is 0, the key was definitely never inserted — a single clear bit is a proof of absence. If all k bits are 1, the key is probably in the set, but those bits could have been set by other keys, which is where false positives come from.
Here is a compact filter. It takes a precomputed 64-bit hash of the key and derives k indices from it by double hashing — splitting the single 64-bit hash into two 32-bit halves and walking h1 + i·h2, the standard Kirsch–Mitzenmacher trick that gives k well-distributed indices from one hash instead of computing k independent digests.
public sealed class BloomFilter
{
private readonly byte[] _bits; // m bits, packed 8 per byte
private readonly int _m; // bit count
private readonly int _k; // number of hash probes
public BloomFilter(int m, int k, byte[]? bits = null)
{
_m = m;
_k = k;
_bits = bits ?? new byte[(m + 7) / 8];
}
public int BitCount => _m;
public int HashCount => _k;
public ReadOnlySpan<byte> Bytes => _bits;
public void Add(ulong hash)
{
uint h1 = (uint)hash;
uint h2 = (uint)(hash >> 32) | 1; // force odd so the step never stalls
for (int i = 0; i < _k; i++)
{
uint combined = unchecked(h1 + (uint)i * h2);
int bit = (int)(combined % (uint)_m);
_bits[bit >> 3] |= (byte)(1 << (bit & 7));
}
}
public bool MightContain(ulong hash)
{
uint h1 = (uint)hash;
uint h2 = (uint)(hash >> 32) | 1;
for (int i = 0; i < _k; i++)
{
uint combined = unchecked(h1 + (uint)i * h2);
int bit = (int)(combined % (uint)_m);
if ((_bits[bit >> 3] & (byte)(1 << (bit & 7))) == 0)
return false; // one clear bit proves the key was never added
}
return true; // all k bits set: probably revoked — must verify
}
}
The hash itself must be stable across runtimes and platforms, because the filter is built on your server and tested on every client. Use a fixed cryptographic digest and take 64 bits of it; do not use string.GetHashCode(), which is randomized per process.
static ulong HashKeyId(string licenseId)
{
Span<byte> digest = stackalloc byte[32];
SHA256.HashData(Encoding.UTF8.GetBytes(licenseId), digest);
return BinaryPrimitives.ReadUInt64LittleEndian(digest);
}
Sizing it
The two knobs, m and k, follow from the count of revoked keys n and the false-positive rate p you are willing to accept. The optimal number of hashes is k = (m/n)·ln2, and the achieved rate is p ≈ (1 − e^(−kn/m))^k. Invert that to size the array for a target p:
public static (int m, int k) SizeFor(int n, double p)
{
// m = -n·ln(p) / (ln2)^2 ; k = (m/n)·ln2
double mBits = -(n * Math.Log(p)) / (Math.Log(2) * Math.Log(2));
int m = (int)Math.Ceiling(mBits);
int k = Math.Max(1, (int)Math.Round((m / (double)n) * Math.Log(2)));
return (m, k);
}
That works out to about 1.44·log2(1/p) bits per key, independent of how long each key string is. Ten thousand revoked keys at p = 0.001 need roughly 144,000 bits — about 18 KB — with k ≈ 10. Building the filter server-side is then a loop:
var revoked = await store.GetRevokedLicenseIdsAsync(); // authoritative set
var (m, k) = BloomFilter.SizeFor(revoked.Count, p: 0.001);
var filter = new BloomFilter(m, k);
foreach (var id in revoked)
filter.Add(HashKeyId(id));
// publish { version, m, k, bits = filter.Bytes } to clients
The client decision flow
The whole point of the asymmetry is the decision the client makes. A filter miss is a final answer; a filter hit is only a trigger. The client treats a positive as "I must do one authoritative online revocation check for this key" — never as the verdict itself.
public async Task<bool> IsRevokedAsync(string licenseId, CancellationToken ct)
{
ulong h = HashKeyId(licenseId);
// Common case: the filter says no. No false negatives, so this is final.
if (!_filter.MightContain(h))
return false; // instant, offline, no network
// Filter hit: a true revocation OR a rare false positive. Only the
// authoritative source can tell them apart — so ask it, for this one key.
return await _revocationApi.IsRevokedAsync(licenseId, ct);
}
Because p is small, the online branch runs rarely: it is taken for every genuinely revoked key (which should be failing anyway) plus a p fraction of good keys. At p = 0.001 that is one unnecessary round-trip per thousand validations of distinct good keys — negligible — while the other 999 are answered instantly with no network at all. That is the trade the Bloom filter buys you: the heavy, authoritative check becomes the exception instead of the rule.
Distribute the filter as a versioned artifact: a small header of { version, m, k } alongside the packed bits. Clients cache the current version and poll for a newer one on a cadence — conditional fetches keep that cheap, which is the same discipline covered in conditional license fetches with ETags. The rebuild cadence is a product decision: rebuilding and republishing the filter every few hours bounds how long a freshly revoked key can hide behind a stale filter, and the authoritative online check closes that gap the moment a client does hit the filter for that key.
This layering complements the propagation mechanics in revoking a leaked key across every client and the freshness guarantees in stapled freshness proofs. Those posts cover how a revocation reaches clients and how fresh the answer is; this one is about encoding the growing set compactly so the common "not revoked" path stays offline and instant.
Caveats and when it breaks
You cannot remove from a plain Bloom filter. Clearing a key's bits would clear bits it shares with other revoked keys and manufacture false negatives — a revoked key leaking through as "clean," the one error the whole scheme forbids. Un-revoking therefore means rebuilding the filter from the current revoked set and shipping a new version. If you genuinely need in-place deletion, a counting Bloom filter (bytes instead of bits) or a cuckoo filter supports it, at a cost in size and complexity you usually do not need given you rebuild on a cadence anyway.
The filter leaks an upper bound on how many keys you revoked. Its size, and the density of set bits, reveal roughly how many entries it holds. That is far less than shipping the actual identifiers, but it is not nothing; size for your real n rather than padding wildly, and treat the number as public.
Pick p deliberately. Too large and clients fall back to the online check constantly, defeating the point and hammering your service. Too small and the filter bloats — halving p costs a fixed slab of bits per key every time. Somewhere around 0.1% to 1% is usually the sweet spot: online fallbacks stay rare without the array growing fat.
The online fallback must itself be authoritative. The filter is a fast negative cache, nothing more. Every positive is resolved by a check that reads the true revocation state — and that check must fail closed on a revoked key and, critically, must be the thing that actually blocks. If your online path is sloppy, the Bloom filter has only made a sloppy answer faster.
Never ship the raw key list client-side. The entire reason to reach for a Bloom filter is that it encodes membership without encoding the keys. Shipping the plaintext list "for convenience" alongside it throws away the privacy property and the size win in one move.
Takeaway
A growing revocation list is a distribution problem, and a Bloom filter solves it by trading a small, one-directional error for a huge saving. Encode the revoked set as a fixed-size bit array with k hash probes; ship that, versioned, to every client. A filter miss is a certain, instant, offline "not revoked"; a filter hit is only a maybe, so the client spends one authoritative online check to decide — and because false positives are rare by design, that check is the exception. Good keys are never blocked by the filter, the common case never touches the network, and the artifact you distribute reveals no key at all. Pair it with Keyright's revocation propagation and your clients stay current on a set that can grow as large as it likes. See Keyright and the licensing docs for the surrounding verification model; the free Community Edition is the place to try it.
Top comments (0)