pg_secret
pg_secret · Defines order-revealing encrypted domains, comparison operators, and a B-tree operator class.
Overview
Usage
Sources:
pg_secret 0.5 is an experimental order-revealing encryption prototype. It turns an integer or text value into the secret domain and supplies comparison operators plus a B-tree operator class. Use it only to study indexed ordering over ciphertext; it is not a general secret-management or production encryption system.
Core Workflow
make_secret(key, key, int8) encrypts a 64-bit integer. The text overload first converts the input to a 64-bit SipHash value, so its encrypted ordering is hash ordering, not lexical text ordering. Both keys must be exactly 16 bytes even though the key domain itself does not enforce a length.
Applications must retain and protect both keys outside this table. Recreating a comparison boundary requires calling make_secret with the same pair of keys.
Objects
- Domains:
secretis abyteavalue constrained to 224 bytes;keyis an unconstrainedbyteadomain. - Constructors:
make_secret(key, key, int8)andmake_secret(key, key, text). - Comparisons:
<,<=,=,>=, and>forsecret, implemented throughsecret_cmpand the default B-tree operator classsecret_btree_ops.
There is no decryption function, authenticated-encryption API, key registry, or key-rotation workflow in version 0.5.
Security and Operational Boundaries
Order-revealing encryption deliberately leaks order, and the upstream notes call this implementation a weaker security model. The server receives the plaintext and both keys; PostgreSQL logging, error reporting, memory handling, or WAL-related behavior may expose sensitive material. The implementation also contains unresolved key-cleanup work.
The source was an early 2019–2020 experiment and depends on bundled cryptographic code plus OpenSSL/GMP-era build assumptions. Perform independent cryptographic review, restrict execution privileges, and test the exact PostgreSQL build. Do not use pg_secret as a substitute for audited encryption, KMS integration, or application-side key custody.