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

IDExtensionPackageVersionCategoryLicenseLanguage
7035encsearchencsearch0.1.1SECPostgreSQLRust
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--sLd--NoYesYesYesnono
Load before setting keys. Blind indexes reveal equality and token frequency.

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXTPIGSTY0.1.119 18 17 16 15encsearch-
RPMPIGSTY0.1.119 18 17 16 15encsearch_$v-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 0.1.1PIGSTY 0.1.1PIGSTY 0.1.1PIGSTY 0.1.1
el8.aarch64N/APIGSTY 0.1.1PIGSTY 0.1.1PIGSTY 0.1.1PIGSTY 0.1.1
el9.x86_64PIGSTY 0.1.1PIGSTY 0.1.1PIGSTY 0.1.1PIGSTY 0.1.1PIGSTY 0.1.1
el9.aarch64PIGSTY 0.1.1PIGSTY 0.1.1PIGSTY 0.1.1PIGSTY 0.1.1PIGSTY 0.1.1
el10.x86_64PIGSTY 0.1.1PIGSTY 0.1.1PIGSTY 0.1.1PIGSTY 0.1.1PIGSTY 0.1.1
el10.aarch64PIGSTY 0.1.1PIGSTY 0.1.1PIGSTY 0.1.1PIGSTY 0.1.1PIGSTY 0.1.1
d12.x86_64N/AN/AN/AN/AN/A
d12.aarch64N/AN/AN/AN/AN/A
d13.x86_64N/AN/AN/AN/AN/A
d13.aarch64N/AN/AN/AN/AN/A
u22.x86_64N/AN/AN/AN/AN/A
u22.aarch64N/AN/AN/AN/AN/A
u24.x86_64N/AN/AN/AN/AN/A
u24.aarch64N/AN/AN/AN/AN/A
u26.x86_64N/AN/AN/AN/AN/A
u26.aarch64N/AN/AN/AN/AN/A
PackageVersionOSORGSIZEFile URL
encsearch_190.1.1el9.x86_64pigsty617.2 KiBencsearch_19-0.1.1-2PGSTY.el9.x86_64.rpm
encsearch_190.1.1el9.aarch64pigsty530.1 KiBencsearch_19-0.1.1-2PGSTY.el9.aarch64.rpm
encsearch_190.1.1el10.x86_64pigsty561.8 KiBencsearch_19-0.1.1-2PGSTY.el10.x86_64.rpm
encsearch_190.1.1el10.aarch64pigsty513.3 KiBencsearch_19-0.1.1-2PGSTY.el10.aarch64.rpm
PackageVersionOSORGSIZEFile URL
encsearch_180.1.1el8.x86_64pigsty517.3 KiBencsearch_18-0.1.1-2PGSTY.el8.x86_64.rpm
encsearch_180.1.1el8.aarch64pigsty419.3 KiBencsearch_18-0.1.1-2PGSTY.el8.aarch64.rpm
encsearch_180.1.1el9.x86_64pigsty612.5 KiBencsearch_18-0.1.1-2PGSTY.el9.x86_64.rpm
encsearch_180.1.1el9.aarch64pigsty525.4 KiBencsearch_18-0.1.1-2PGSTY.el9.aarch64.rpm
encsearch_180.1.1el10.x86_64pigsty556.8 KiBencsearch_18-0.1.1-2PGSTY.el10.x86_64.rpm
encsearch_180.1.1el10.aarch64pigsty509.4 KiBencsearch_18-0.1.1-2PGSTY.el10.aarch64.rpm
PackageVersionOSORGSIZEFile URL
encsearch_170.1.1el8.x86_64pigsty517.1 KiBencsearch_17-0.1.1-1PGSTY.el8.x86_64.rpm
encsearch_170.1.1el8.aarch64pigsty414.3 KiBencsearch_17-0.1.1-1PGSTY.el8.aarch64.rpm
encsearch_170.1.1el9.x86_64pigsty608.2 KiBencsearch_17-0.1.1-2PGSTY.el9.x86_64.rpm
encsearch_170.1.1el9.aarch64pigsty521.5 KiBencsearch_17-0.1.1-2PGSTY.el9.aarch64.rpm
encsearch_170.1.1el10.x86_64pigsty552.2 KiBencsearch_17-0.1.1-2PGSTY.el10.x86_64.rpm
encsearch_170.1.1el10.aarch64pigsty504.4 KiBencsearch_17-0.1.1-2PGSTY.el10.aarch64.rpm
PackageVersionOSORGSIZEFile URL
encsearch_160.1.1el8.x86_64pigsty512.5 KiBencsearch_16-0.1.1-2PGSTY.el8.x86_64.rpm
encsearch_160.1.1el8.aarch64pigsty414.6 KiBencsearch_16-0.1.1-2PGSTY.el8.aarch64.rpm
encsearch_160.1.1el9.x86_64pigsty606.0 KiBencsearch_16-0.1.1-2PGSTY.el9.x86_64.rpm
encsearch_160.1.1el9.aarch64pigsty518.9 KiBencsearch_16-0.1.1-2PGSTY.el9.aarch64.rpm
encsearch_160.1.1el10.x86_64pigsty549.7 KiBencsearch_16-0.1.1-2PGSTY.el10.x86_64.rpm
encsearch_160.1.1el10.aarch64pigsty501.3 KiBencsearch_16-0.1.1-2PGSTY.el10.aarch64.rpm
PackageVersionOSORGSIZEFile URL
encsearch_150.1.1el8.x86_64pigsty507.9 KiBencsearch_15-0.1.1-2PGSTY.el8.x86_64.rpm
encsearch_150.1.1el8.aarch64pigsty409.5 KiBencsearch_15-0.1.1-2PGSTY.el8.aarch64.rpm
encsearch_150.1.1el9.x86_64pigsty598.9 KiBencsearch_15-0.1.1-2PGSTY.el9.x86_64.rpm
encsearch_150.1.1el9.aarch64pigsty511.8 KiBencsearch_15-0.1.1-2PGSTY.el9.aarch64.rpm
encsearch_150.1.1el10.x86_64pigsty543.3 KiBencsearch_15-0.1.1-2PGSTY.el10.x86_64.rpm
encsearch_150.1.1el10.aarch64pigsty494.5 KiBencsearch_15-0.1.1-2PGSTY.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 by package name

pig install encsearch -v 19;   # install for PG 19
pig install encsearch -v 18;   # install for PG 18
pig install encsearch -v 17;   # install for PG 17
pig install encsearch -v 16;   # install for PG 16
pig install encsearch -v 15;   # install for PG 15

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.

Table reader