Your intuition is correct: perceptual hashing is a cheap, CPU-bound first-pass filter, and the token cost of an LLM or VLM review is orders of magnitude higher. For an image host, the winning architecture is a cascade where 99%+ of uploads are cleared by a hash match against a known-CSAM database, and only the tiny fraction that fail the hash check (or are flagged as borderline) ever reach a more expensive classifier or human reviewer.
The Core Technique: Perceptual Hashing
Unlike cryptographic hashes (MD5, SHA-256), which produce completely different outputs for even single-bit changes, perceptual hashes (pHash, dHash, PDQ, PhotoDNA) extract visual features and produce similar hashes for visually similar images. This makes them robust to resizing, compression, and minor edits, which is exactly what you need to catch "obfuscated" versions of known material.
The standard pHash pipeline is straightforward: resize to a fixed small size (e.g., 32x32), grayscale, apply a DCT, and use the low-frequency coefficients to generate a binary hash. Comparison is done via Hamming distance, with a threshold (often around 10 bits difference for a 256-bit hash) determining a match. This is a pure CPU operation, typically measured in tens of milliseconds per image or less with optimized libraries.
Existing Infrastructure You Can Plug Into
You do not need to build the hash database. The infrastructure already exists and is free for qualified organizations.
Source What They Provide Cost
IWF Hash List ~2.88 million unique hashes (perceptual + cryptographic), updated continuously Free to members
NCMEC Hash Sharing API 5 million verified CSAM hashes, with polling API for new entries Free (credentials required)
Microsoft PhotoDNA Cloud API for hashing and matching Free to qualified customers
Project Arachnid (C3P) No-cost API for smaller operators, including hash list access Free
The NCMEC Hash Sharing API is a polling API: you submit your own hashes for verification, and you can query the shared database for matches. The IWF Hash List is available in both perceptual and cryptographic formats, and at the end of 2024 contained 2,883,015 unique hashes with 44 member organizations using the service.
The Cost Economics: CPU vs. GPU vs. Tokens
The cost hierarchy is clear, and your instinct that CPU is cheaper than tokens is correct by several orders of magnitude.
Perceptual hashing on CPU. A single pHash computation is on the order of 10–50 milliseconds on a modern CPU, often less with vectorized implementations. At that rate, a single core can process tens of thousands of images per hour. Cloud compute costs for a modest VM are measured in cents per hour, which translates to a negligible per-image cost at scale.
PhotoDNA on GPU. Microsoft's own deployment documentation notes that GPU-backed SageMaker Batch materially improved throughput and unit cost for PhotoDNA hashing compared to CPU fleets, delivering better $/throughput when saturated. This is for the heavier PhotoDNA algorithm, not for simple pHash. For a lightweight pHash cascade, CPU is sufficient and cheaper.
LLM/VLM review. A vision-language model reviewing a single image consumes thousands of tokens. At current API pricing, that is cents to dollars per image, depending on resolution and model. Compared to the microsecond-scale CPU hash, this is the expensive final tier, and you only want to invoke it on the fraction of images that survive the hash filter.
The Ofcom cost analysis for CSAM hash matching estimates one-off build costs ranging from £17,000 to £339,000, but ongoing tech costs for smaller services starting from £1,000 annually. That is the infrastructure cost for a compliant system. Your marginal cost per image for the hash layer is effectively zero.
The Cascade Architecture
The correct design is a multi-tier filter:
1. Cryptographic hash (SHA-256): Instant, blocks exact re-uploads. Zero false positives.
2. Perceptual hash (pHash, PDQ, dHash): CPU-bound, catches resized/compressed/edited versions. Hamming distance threshold determines match. This is where the bulk of the work happens.
3. Lightweight classifier (optional): If you need to flag novel material not in any hash database, a small CNN or a lightweight VLM can run on the residual. This is where GPU or token costs enter.
4. Human review: Only for confirmed hits or high-confidence borderline cases.
Your point about CPU being cheaper than tokens is exactly right for tiers 1 and 2. The hash filter is the high-volume, low-cost workhorse. The LLM is the low-volume, high-cost specialist.
Practical Implementation Notes
Libraries. The Thorn perception library is specifically built for this use case. It supports pHash, PDQ, dHash, aHash, Block Mean, and more, with a simple API and documentation on detecting CSAM and deduplicating media. It is Python-based, but the algorithms are trivial to port to any language. For Moxie, the DCT-based pHash is the simplest to implement: fixed-size resize, grayscale, DCT, threshold, binary hash. The blockhash variant is even simpler (divide into blocks, average, compare).
Hash format. The IWF list is available in "multiple hash formats including both perceptual and cryptographic". You need to match the format your hash function produces. PDQ and pHash are the most common. If you are using a custom hash, you will need a bridge to the standard formats.
Adversarial caveat. Perceptual hashing is not bulletproof. Research has shown that PhotoDNA hashes can be manipulated to produce false positives or identical hashes for different images, and that inpainting attacks can alter semantic content without changing the hash enough to trigger a match. This is why the cascade matters: the hash layer is fast and cheap, but it should be combined with a classifier for novel material, and it should not be the sole basis for a strike or a report.
Bottom Line
For an image host, perceptual hashing is the correct first-pass filter for known CSAM. It is CPU-bound, it is fast, and it is free to access via IWF, NCMEC, and Microsoft's PhotoDNA Cloud Service. The token cost of an LLM review is orders of magnitude higher, so the architecture should be a cascade: hash first, classify second, review third. Your Moxie port can implement pHash or Blockhash in a few hundred lines, and the Hamming distance comparison is a bitwise XOR and a popcount, which is trivial in any language.
