Hybrid PQ-CP-ABE Library for Windows/Linux - Version 5.0.1¶
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 patch release fixes critical bugs in the TKN20 scheme, documents its NOT (negation) operator, and improves the Windows build process.
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.
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
Compound NOT policies:
# Must be admin AND not HR
main.exe encrypt --scheme tkn20 ./keys/cpabe_pk.key data.txt "(role:admin) and not (department:hr)" data.enc
# Either not master, OR (master AND in IT department)
main.exe encrypt --scheme tkn20 ./keys/cpabe_pk.key data.txt "not (role:master) or (role:master and department:it)" data.enc
Changes Summary¶
- Fixed
//exportdirectives incpabe_tkn20.go(4 functions were not exported). - Fixed
convertPolicyToTKN20to auto-wrapnot <attr>intonot (<attr>). - Rebuilt
libcpabe_tkn20.dllas a proper Windows PE binary. - Updated
tasks.jsonto use.def-based import lib instead of merging Go objects into MSVC archive. - Updated
lib/README.mdwith corrected TKN20 build instructions.