Skip to content

encsearch

Experimental encrypted text search using AEAD ciphers and keyed blind indexes

encsearch : Experimental encrypted text search using AEAD ciphers and keyed blind indexes

Overview

ID Extension Package Version Category License Language
7035 encsearch encsearch 0.1.1 SEC PostgreSQL Rust
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--sLd-- No Yes Yes Yes no no
Early release 0.1.1 changes PGXN status to stable without code changes from 0.1.0; PG17 tested, other Cargo PG14-18 targets untested. Session preload must precede key settings; blind indexes leak equality and token frequency.

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT PIGSTY 0.1.1 18 17 16 15 14 encsearch -
RPM PIGSTY 0.1.1 18 17 16 15 14 encsearch_$v -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64 N/A PIGSTY 0.1.1 N/A N/A N/A
el8.aarch64 N/A PIGSTY 0.1.1 N/A N/A N/A
el9.x86_64 N/A PIGSTY 0.1.1 N/A N/A N/A
el9.aarch64 N/A PIGSTY 0.1.1 N/A N/A N/A
el10.x86_64 N/A PIGSTY 0.1.1 N/A N/A N/A
el10.aarch64 N/A PIGSTY 0.1.1 N/A N/A N/A
d12.x86_64 N/A N/A N/A N/A N/A
d12.aarch64 N/A N/A N/A N/A N/A
d13.x86_64 N/A N/A N/A N/A N/A
d13.aarch64 N/A N/A N/A N/A N/A
u22.x86_64 N/A N/A N/A N/A N/A
u22.aarch64 N/A N/A N/A N/A N/A
u24.x86_64 N/A N/A N/A N/A N/A
u24.aarch64 N/A N/A N/A N/A N/A
u26.x86_64 N/A N/A N/A N/A N/A
u26.aarch64 N/A N/A N/A N/A N/A
Package Version OS ORG SIZE File URL
encsearch_17 0.1.1 el8.x86_64 pigsty 517.1 KiB encsearch_17-0.1.1-1PGSTY.el8.x86_64.rpm
encsearch_17 0.1.1 el8.aarch64 pigsty 414.3 KiB encsearch_17-0.1.1-1PGSTY.el8.aarch64.rpm
encsearch_17 0.1.1 el9.x86_64 pigsty 519.3 KiB encsearch_17-0.1.1-1PGSTY.el9.x86_64.rpm
encsearch_17 0.1.1 el9.aarch64 pigsty 445.6 KiB encsearch_17-0.1.1-1PGSTY.el9.aarch64.rpm
encsearch_17 0.1.1 el10.x86_64 pigsty 473.0 KiB encsearch_17-0.1.1-1PGSTY.el10.x86_64.rpm
encsearch_17 0.1.1 el10.aarch64 pigsty 430.4 KiB encsearch_17-0.1.1-1PGSTY.el10.aarch64.rpm

Source

pig build pkg encsearch;		# build rpm

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install encsearch;		# install via package name, for the active PG version

pig install encsearch -v 17;   # install for PG 17

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'encsearch';

Create this extension with:

CREATE EXTENSION encsearch;

Usage

Sources:

encsearch stores encrypted text alongside keyed search tokens in an int8[] column. Its experimental 0.1.0 release supports exact, word and pattern searches through a GIN index. Upstream has tested PostgreSQL 17; the other Cargo feature targets are untested.

Core Workflow

session_preload_libraries = 'encsearch'
CREATE EXTENSION encsearch;
CREATE TABLE encrypted_notes (id bigint GENERATED ALWAYS AS IDENTITY, body bytea, idx int8[]);
CREATE INDEX encrypted_notes_tokens ON encrypted_notes USING gin (idx);
INSERT INTO encrypted_notes (body, idx)
VALUES (enc_encrypt('Patient has diabetes'), enc_index('Patient has diabetes'));
SELECT enc_decrypt(body) FROM encrypted_notes
WHERE enc_like(body, idx, '%diab%');

Operational Boundaries

An administrator installs this untrusted extension. Configure session_preload_libraries before opening client sessions and before setting encsearch.key; otherwise an early key setting remains an unregistered setting visible to other roles. Supply a securely retained key of at least 32 characters to the session or explicit-key function overloads before running the data example. enc_gen_key() generates a 64-character key. Losing the key loses access to the plaintext.

enc_encrypt and enc_decrypt handle text and ciphertext. enc_index creates stored tokens; enc_like, enc_ilike and enc_eq filter candidates and check decrypted values. enc_has_words tests token containment without decrypting; enc_q_like, enc_q_exact and enc_q_words expose raw query tokens. enc_algorithm and enc_algorithms inspect available ciphers.

encsearch.algorithm defaults to aes-256-gcm; deterministic aes-256-siv reveals duplicate plaintext. Keep encsearch.token_hash identical when building and querying tokens: hmac-sha256 is the default and blake3 is the alternative. Changing the token hash requires regenerating tokens; changing keys requires decrypting with the old key and rebuilding ciphertext and tokens with the new key.

Blind indexes reveal shared values, words and character chunks and their frequency. Keys reach the database server and may appear in statement or parameter logs. This is an experimental privacy/performance tradeoff, not protection against a server that has the key.