Hybrid PQ-CP-ABE Library for Windows/Linux - Version 5.1.0¶
Note
IMPORTANT NOTICE:
- From Version 4.0, this library natively supports and includes Post-Quantum Cryptography (PQC).
- If your project DOES NOT need PQC (to save space, avoid liboqs dependencies, or minimize performance overhead), please download and use Version 3.1 from the Releases page.
Overview¶
This major release introduces the HashiCorp Vault Secrets Engine Plugin, effectively transforming the library into a true Cryptography-as-a-Service platform. It also rolls up all the critical TKN20 scheme bug fixes and the NOT (negation) operator documentation from the 5.0.1 patch.
New Feature: HashiCorp Vault Plugin (Zero-Trust Architecture)¶
- A completely new Go-based Vault Plugin (
src/go/vault-plugin-abe) has been developed using Cgo to natively wrap the C++ core. - Master Key Isolation: The Master Secret Key (MSK) is now generated and stored entirely within the Vault's secure backend (
msk/abe) during thesetupphase. The MSK never leaves the Vault enclave. - RESTful Endpoints: The plugin exposes four secure endpoints:
/v1/abe/setup,/v1/abe/genkey,/v1/abe/encrypt, and/v1/abe/decrypt. - By delegating all cryptographic operations to Vault, the client applications no longer need to hold or manage the root keys, achieving a true Zero-Trust architecture.
- Comprehensive Python Test Suite: Introduced
src/vault/test_vault.pyto rigorously test the Vault plugin endpoints for bothAC17andTKN20schemes.
New Feature: TKN20 NOT (Negation) Operator¶
The TKN20 scheme supports the not operator in access policies, enabling negated attribute matching. This is not available in AC17.
How NOT Works in TKN20¶
Important
not in TKN20 means "attribute must be present with a different value", not "attribute is absent".
Users must always be assigned all relevant attributes with explicit values (e.g., department:hr, department:it).
| Policy | User Attributes | Result |
|---|---|---|
not department:hr |
department:it |
✅ Decrypt OK (it ≠ hr) |
not department:hr |
department:hr |
❌ Decrypt FAIL (hr = hr) |
not department:hr |
(no department attr) |
❌ Decrypt FAIL (attribute absent) |
Usage Examples¶
Setup & Key Generation:
# Setup TKN20 keys
main.exe setup --scheme tkn20 ./keys
# Admin user (not HR)
main.exe genkey --scheme tkn20 ./keys/cpabe_msk.key "role:admin department:it" ./keys/admin.key
# HR user
main.exe genkey --scheme tkn20 ./keys/cpabe_msk.key "role:hr department:medicine" ./keys/hr.key
Encrypt with NOT policy:
# Only non-HR users can decrypt
main.exe encrypt --scheme tkn20 ./keys/cpabe_pk.key data.txt "not department:hr" data.enc
# Admin can decrypt (department 'it' ≠ 'hr')
main.exe decrypt ./keys/admin.key data.enc recovered.txt # ✅ Success
# HR cannot decrypt (department 'hr' = 'hr')
main.exe decrypt ./keys/hr.key data.enc recovered.txt # ❌ Policy mismatch
Enhancements & Optimizations¶
1. Massive Docker Build Optimization (.dockerignore)¶
- Identified and fixed a major performance bottleneck where the
docker buildcommand was unnecessarily transferring the entire localsrc/cpp/build/and.git/directories into the Docker daemon context. - Added a precise
.dockerignorefile at the root of the repository. - Impact: The Docker context transfer time dropped from ~30 seconds to <0.1 seconds, and the layer cache is now correctly preserved. Re-running the
test_pluginscripts without C++ source changes is now nearly instantaneous.
2. Port Conflict Resolution in Testing Scripts¶
- Fixed
test_plugin.ps1andtest_plugin.sh: Removed the-p 8200:8200host port binding from the ephemeralvault-devcontainer launch command. - Testing scripts now map to port
8201(-p 8201:8200), allowing them to run independently without interfering with production or development clusters.
Bug Fixes¶
Fixed TKN20 CGo Export Directives¶
- The Go source file
cpabe_tkn20.gohad incorrect export comments (// exportwith a space instead of//export), causingTKN20_Setup,TKN20_KeyGen,TKN20_Encrypt, andTKN20_Decryptto not be exported to C. OnlyTKN20_FreeByteArraywas properly exported. - Impact: On Windows, linking with the TKN20 static archive produced
LNK2019: unresolved external symbolerrors for all TKN20 functions.
Fixed TKN20 NOT Operator Policy Conversion¶
- The CIRCL TKN20 parser requires
notto be followed by a parenthesized expression (e.g.,not (hr:hr)), butconvertPolicyToTKN20was producingnot hr:hr(without parentheses), resulting in a malformed policy that no attribute set could satisfy. - Added automatic wrapping:
not attr→not (attr)in the policy conversion post-processing step.
Fixed Windows DLL (ELF Mismatch)¶
- The pre-built
libcpabe_tkn20.dllshipped inlib/dynamic/was actually a Linux ELF binary (.so) renamed to.dll, causing0xc000012f Bad Imageerrors on Windows. - The DLL is now properly built using
go build -buildmode=c-sharedon Windows, producing a valid PE/MZ binary.
Fixed Build Tasks (tasks.json)¶
- Removed Go static archive (
libcpabe_tkn20.lib) from the MSVC combinedlib.exearchive, which causedLNK1223: invalid .pdataerrors due to Go/MinGW ABI incompatibility with MSVC. - TKN20 is now linked via a MSVC-native import library (generated from
.deffile) + runtime DLL. - Removed broken
copy libcpabe_tkn20.dllstep that referenced a non-existent path.
Quick Start (Vault Integration)¶
To test the new Vault capabilities, navigate to the Go directory and run the automated script:
Windows:
cd src/go
.\test_plugin.ps1
Linux / macOS:
cd src/go
./test_plugin.sh
To run the Python validation suite:
cd src/vault
pip install requests
python test_vault.py