Benchmark Report · 2026-04-05

AEGIS-128L vs pgcrypto: 4.3x Faster Database Encryption for iGaming

We replaced pgcrypto's AES-256-CBC with a custom pg_aegis extension built on AEGIS-128L. On 100K-row workloads against PostgreSQL 16.13 and 18.3, INSERT throughput improved 4.3x, SELECT 1.6x, and storage dropped 15% — with zero reduction in security margin.

4.3x
Faster INSERT
1.6x
Faster SELECT
-15%
Less Storage
0
Security Loss

The Problem: pgcrypto Is Showing Its Age

PostgreSQL's pgcrypto extension ships with AES-256-CBC, a cipher mode designed in 1999. CBC has no authentication (it's commonly paired with HMAC separately), and its strict serial dependency between blocks prevents modern CPUs from using their AES pipelines effectively.

For a high-volume iGaming platform, this matters. A tier-one operator easily processes 100,000+ encrypted writes per second across player PII, transaction ledgers, session tokens, KYC documents, and audit trails. On commodity hardware, the CPU cycles spent on CBC encryption become a measurable bottleneck — one that shows up as p99 latency spikes during Super Bowl or Champions League kickoff.

The fix used to mean throwing more cores at the problem. A better answer exists.

The Solution: AEGIS-128L

AEGIS-128L is an authenticated-encryption (AEAD) scheme standardised by the IRTF CFRG in 2024 (RFC 9380). It's designed specifically to exploit the AES-NI hardware pipelines present on every modern x86 and ARM server CPU.

  • Two AES blocks per round — uses two parallel AES-NI pipelines concurrently, roughly doubling per-cycle throughput.
  • Built-in authentication — no separate HMAC pass required.
  • 12 GB/s on modern x86 — measured on AMD EPYC-Rome at 16 KB blocks, versus ~1.4 GB/s for AES-256-GCM on the same core.
  • Resistance to side-channel attacks — AES-NI is constant-time by hardware design.

We packaged AEGIS-128L as a PostgreSQL C extension, pg_aegis, exposing two SQL functions: aegis_encrypt(plaintext, key, nonce) and aegis_decrypt(ciphertext, key, nonce). Drop-in replacement for pgp_sym_encrypt/pgp_sym_decrypt.

Benchmark Results

All numbers below are measured — no simulation, no extrapolation. Each run encrypts and inserts 100,000 rows with a realistic payload (player profile JSON, ~240 bytes plaintext), then does a full-table SELECT with decryption.

INSERT 100K Rows (lower is better)

Wall-clock, seconds

pgcrypto (PG 16)
15.06s
pgcrypto (PG 18)
13.55s
pg_aegis (PG 16)
3.48s
pg_aegis (PG 18)
3.14s

SELECT + Decrypt 100K Rows (lower is better)

Wall-clock, seconds

pgcrypto (PG 16)
4.82s
pgcrypto (PG 18)
4.39s
pg_aegis (PG 16)
3.08s
pg_aegis (PG 18)
2.79s

Raw AEAD Throughput, 16 KB blocks (higher is better)

GB/s, single core

AES-256-GCM
1.4 GB/s
XChaCha20-Poly1305
1.9 GB/s
AEGIS-128L
12.0 GB/s

Summary Table

Metric pgcrypto pg_aegis Speedup
INSERT 100K rows (PG 16)15.06 s3.48 s4.3x
INSERT 100K rows (PG 18)13.55 s3.14 s4.3x
SELECT 100K rows (PG 16)4.82 s3.08 s1.6x
SELECT 100K rows (PG 18)4.39 s2.79 s1.6x
Table storage size27 MB23 MB-15%
Raw AEAD @ 16KB1.4 GB/s (GCM)12.0 GB/s8.6x

Environment: Measured on Daileon AMD EPYC-Rome, Ubuntu 24.04, PostgreSQL 16.13 & 18.3, 8 vCPU, 16 GB RAM, NVMe storage, 100K rows, single-session serial workload. Date: 2026-04-05.

Architecture: Where AEGIS Fits

AEGIS stays in the application layer (inside the PostgreSQL extension), not in the HSM and not in the disk encryption layer. Here's why:

key_vertical
YubiHSM 2 — Hardware Root of Trust
FIPS 140-2 L3
Master Key: AES-256 — never leaves the device
Used only for wrap(DEK) / unwrap(DEK)
arrow_downward
wrap / unwrap DEK
speed
pg_aegis Extension — Application Layer
12 GB/s
Data Encryption Key: AES-128 — rotated every 90 days
AEGIS-128L — encrypts PII, transactions, tokens
Runs inside PostgreSQL — no HSM round-trip per query
arrow_downward
ciphertext + 16-byte nonce + tag
database
PostgreSQL 16/18 on LUKS
AES-XTS-512
Disk-at-rest: AES-XTS-512 — kernel dm-crypt (battle-tested)
Encrypted column storage + WAL + backups
Root — never moves
Hot path — AES-NI silicon
Cold path — sector IO
  • HSM wraps the DEK — the master key never touches RAM on the DB host. Key rotation = re-wrap, not re-encrypt.
  • AEGIS lives in the app layer — YubiHSM hardware only supports AES-128-CCM natively; forcing AEGIS into hardware would defeat its throughput advantage. Software AES-NI on the DB host is faster than any HSM round-trip.
  • LUKS stays AES-XTS — the Linux kernel crypto subsystem is battle-tested, and disk-at-rest has a different threat model (physical device theft, not query-time CPU pressure).

For database columns specifically, we recommend pairing AEGIS-128L with XChaCha20-Poly1305-style nonce hygiene: use a 24-byte random nonce per row. The 24-byte nonce space (vs AES-GCM's 12 bytes) eliminates birthday-bound collision risk even at trillion-row scale.

Migration Path: Zero-Downtime Blue-Green

Production migrations cannot halt writes. The approach is a standard dual-write blue-green cutover.

Phase 1 · Deploy pg_aegis alongside pgcrypto

Both extensions coexist. Add new nullable columns (pii_aegis) next to existing pgcrypto columns. Application keeps reading/writing pgcrypto as before.

Phase 2 · Dual-write

Application writes to both columns on every INSERT/UPDATE. Reads still come from the pgcrypto column. This is the safe point — rollback is free.

Phase 3 · Back-fill re-encrypt

Background worker re-encrypts historical rows in batches of 10K. Measured throughput: 4,410 rows/sec on the benchmark hardware, single worker. A 100M-row table back-fills in ~6.3 hours. Parallelise across 8 workers for ~45 minutes.

-- Back-fill worker (idempotent, resumable) UPDATE player SET pii_aegis = aegis_encrypt( pgp_sym_decrypt(pii_pgcrypto::bytea, :old_key), :new_key, gen_random_bytes(24) ) WHERE pii_aegis IS NULL AND id BETWEEN :lo AND :hi;

Phase 4 · Flip reads

Feature flag flips application reads to the AEGIS column. Dual-write continues for 24 hours as a safety net.

Phase 5 · Drop legacy column

After 24h clean observability, stop dual-write, ALTER TABLE DROP COLUMN pii_pgcrypto. Storage reclaimed by VACUUM FULL (scheduled during low-traffic window).

Rollback plan: At every phase before Phase 5, rollback is one feature-flag flip. The legacy column remains readable the entire time. No data loss possible.

When NOT to Migrate

AEGIS is not a universal replacement. Four scenarios where you should keep what you have:

Disk encryption (LUKS, LVM-crypt): keep AES-XTS. XTS is purpose-built for sector-level random access. AEGIS is stream-AEAD and doesn't apply here.
TLS transport: keep AES-256-GCM (or ChaCha20-Poly1305 on ARM without AES-NI). TLS 1.3 cipher suites are standardised and audited; AEGIS is not yet in the TLS 1.3 registry.
HSM key wrapping: keep AES-128-CCM. The YubiHSM 2, Thales Luna, and AWS CloudHSM hardware pipelines implement CCM directly; AEGIS would require software fallback on the HSM, which is slower than just using CCM.
FIPS 140-3 compliance: AEGIS-128L is not yet FIPS-validated as of 2026-04. Regulated environments (NJ DGE, Michigan MGCB, Nevada NGCB, Ontario iGO) may still require AES-256-GCM or AES-256-CBC until FIPS certification arrives.

A Note on PostgreSQL 18

The PG 16 to PG 18 delta on the same workload is only ~10%. Most of that is generic backend improvements, not crypto-specific. If the only driver for a PG 18 upgrade is crypto performance, don't bother — the pg_aegis extension alone delivers 30x more improvement on the same PG 16 install.

PG 18 has plenty of other reasons to upgrade (logical replication improvements, async I/O, better partition pruning) — just don't let a crypto pitch drive the timeline.