Skip to content

Add IP address encryption (crypto_ipcrypt) and bump to libsodium 1.0.22#123

Merged
michelp merged 2 commits into
mainfrom
feat/crypto-ipcrypt
Jun 10, 2026
Merged

Add IP address encryption (crypto_ipcrypt) and bump to libsodium 1.0.22#123
michelp merged 2 commits into
mainfrom
feat/crypto-ipcrypt

Conversation

@michelp

@michelp michelp commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Summary

Implements the libsodium 1.0.22 crypto_ipcrypt_* family, exposing the ipcrypt-std IP-address encryption/anonymization primitives to SQL, shipped as version 3.1.11.

Four variants, each following existing pgsodium conventions (bytea C core in src/ipcrypt.c + raw-key, by_id server-key, and uuid managed-key SQL overloads):

Variant Prefix Key Output Properties
Deterministic crypto_ipcrypt_ 16B 16B Format-preserving; equal inputs → equal outputs
Prefix-preserving crypto_ipcrypt_pfx_ 32B 16B Format-preserving + preserves network prefixes
Non-deterministic crypto_ipcrypt_nd_ 16B 24B Randomized via 8B tweak (KIASU-BC)
Extended ND crypto_ipcrypt_ndx_ 32B 32B Randomized via 16B tweak (AES-XTS)

Also adds crypto_ipcrypt_ip2bin/bin2ip text↔binary helpers, inet → inet overloads for the two format-preserving variants, four ipcrypt-* key types, and a README section.

Supporting changes (required to build/test the above)

  • Bump bundled libsodium to 1.0.22 (provides crypto_ipcrypt); align debug/example/Windows references.
  • Fix the pending 3.1.10 mask_role migration: GRANT ALL ON %I quoted a schema-qualified view name as one identifier, breaking TCE view generation. Now casts view_name::regclass, which rejects injection payloads (they can't resolve to a real relation) and renders the qualified name correctly.

Test Plan

  • ./test.sh — PostgreSQL 14.19 / 15.14 / 16.10 / 17.6 / 18.1 × {no preload, preload, preload+getkey} → 15/15 PASS
  • Tests include official ipcrypt-std known-answer vectors for all four variants, PFX prefix-preservation, ND/NDX non-determinism, and by_id/uuid round-trips
  • Fresh install and incremental 3.1.9 → 3.1.11 upgrade verified

🤖 Generated with Claude Code

michelp and others added 2 commits June 10, 2026 09:58
Implement the libsodium 1.0.22 crypto_ipcrypt_* family, exposing the
ipcrypt-std IP-address encryption/anonymization primitives to SQL:

- deterministic (AES-128, format-preserving)
- pfx (prefix-preserving)
- nd  (KIASU-BC, non-deterministic, 8 byte tweak)
- ndx (AES-XTS, non-deterministic, 16 byte tweak)

Each variant follows existing pgsodium conventions: a bytea C core
(src/ipcrypt.c) plus raw-key, server-key (by_id bigint + context) and
managed-key (uuid) SQL overloads, with inet->inet overloads for the two
format-preserving variants. Adds ip2bin/bin2ip helpers, four ipcrypt-*
key types, and tests with the official ipcrypt-std known-answer vectors.
Ships as version 3.1.11.

Supporting changes required to build and test the above:

- Bump the bundled libsodium to 1.0.22 (which provides crypto_ipcrypt),
  and align the debug/example/Windows build references to 1.0.22.
- Fix the pending 3.1.10 mask_role migration: GRANT ALL ON %I quoted a
  schema-qualified view name as a single identifier, breaking TCE view
  generation. Cast view_name::regclass instead, which both rejects
  injection payloads (they cannot resolve to a real relation) and renders
  the qualified name correctly.

Verified with ./test.sh across PostgreSQL 14-18 and all preload/getkey
configurations (15/15 PASS), including fresh install and incremental
3.1.9 -> 3.1.11 upgrade.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
main's branch protection requires a status check named "tests", but the
job was named "Linux build and tests", so the required context was never
reported and pull requests stayed blocked on "Expected — Waiting for
status to be reported". Rename the job to "tests" so the check it
publishes matches the required context.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@michelp michelp merged commit fcb5126 into main Jun 10, 2026
1 check passed
@michelp michelp deleted the feat/crypto-ipcrypt branch June 10, 2026 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant