Skip to main content

Crate libpep

Crate libpep 

Source
Expand description

§libpep: Library for polymorphic pseudonymization and encryption

This library implements n-PEP, a scheme for end-to-end encrypted, pseudonymized data sharing. Every party knows its data subjects under its own pseudonyms, which cannot be linked to another party’s. Encrypted data is blindly re-encrypted (transcrypted) for a receiving party by semi-trusted transcryptors, which convert the pseudonyms in it to the receiver’s domain without decrypting anything. Transcryption can be distributed over n transcryptors, so that every transcryptor can independently monitor and block data exchanges, while confidentiality and pseudonym unlinkability hold as long as at least one of them remains uncompromised.

The cryptographic background, a quick start and the relation to OPRFs and proxy re-encryption are described in the README. The scheme is described in the paper by Job Doesburg, Bernard van Gastel and Erik Poll, n-PEP: Secure Data Sharing with Transitive and Distributed Blind Pseudonymization, Security and Trust Management. 22nd International Workshop, STM 2026, Proceedings, Lecture Notes in Computer Science, Springer (PDF).

§Organization

§Feature flags

Default features: long (pseudonyms and attributes over 15 bytes), offline (encryption towards global keys), batch (batch transcryption with shuffling), serde, json (structured data with nested pseudonyms), and build-binary (the peppy CLI).

Optional features and their security implications:

  • elgamal3: ciphertexts additionally encode the public key they were encrypted for, making decryption with a mismatched key detectable at the cost of larger ciphertexts and slower operations. This feature changes API signatures: decryption functions return an Option (or an error for batches) instead of a plain value. The two modes are not wire-compatible; choose one for your deployment.
  • legacy: compatibility with the legacy PEP repository implementation (different scalar derivation). Implies elgamal3, offline and global-pseudonyms; only for interoperability with legacy deployments.
  • insecure: methods that use global secret keys directly, such as offline decryption (decrypt_global). In the intended security model the global secret key is discarded after distributed setup; retaining it to use these methods gives its holder the ability to decrypt everything. Intended for testing only.
  • global-pseudonyms: allows pseudonyms in a global pseudonymization domain (reshuffle factor 1). Such pseudonyms are linkable across all domains; only use this when that linkability is an explicit requirement.

Modules§

client
PEP client for encrypting and decrypting data using session keys or global public keys.
contexts
Specification of PseudonymizationDomains and EncryptionContexts and transcryption between them. Based on simple string representations, this module provides the necessary types to describe transcryption between different domains and sessions.
data
elgamal
ElGamal encryption and decryption, the underlying group arithmetic, and the low-level (n)-PEP primitives that operate on ElGamal ciphertexts.
errors
Error types shared across the library.
factors
Cryptographic factors for pseudonymization, rekeying and rerandomization, and their derivation from secrets and contexts.
keys
Key management for PEP encryption.
prelude
Prelude module for convenient imports.
transcryptor
PEP transcryptor system for pseudonymizing and rekeying encrypted data.

Macros§

pep_json
Macro for creating PEPJSONValue objects with a JSON-like syntax.