Skip to content

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.go had incorrect export comments (// export with a space instead of //export), causing TKN20_Setup, TKN20_KeyGen, TKN20_Encrypt, and TKN20_Decrypt to not be exported to C. Only TKN20_FreeByteArray was properly exported.
  • Impact: On Windows, linking with the TKN20 static archive produced LNK2019: unresolved external symbol errors for all TKN20 functions.

Fixed TKN20 NOT Operator Policy Conversion

  • The CIRCL TKN20 parser requires not to be followed by a parenthesized expression (e.g., not (hr:hr)), but convertPolicyToTKN20 was producing not 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.dll shipped in lib/dynamic/ was actually a Linux ELF binary (.so) renamed to .dll, causing 0xc000012f Bad Image errors on Windows.
  • The DLL is now properly built using go build -buildmode=c-shared on Windows, producing a valid PE/MZ binary.

Fixed Build Tasks (tasks.json)

  • Removed Go static archive (libcpabe_tkn20.lib) from the MSVC combined lib.exe archive, which caused LNK1223: invalid .pdata errors due to Go/MinGW ABI incompatibility with MSVC.
  • TKN20 is now linked via a MSVC-native import library (generated from .def file) + runtime DLL.
  • Removed broken copy libcpabe_tkn20.dll step 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 //export directives in cpabe_tkn20.go (4 functions were not exported).
  • Fixed convertPolicyToTKN20 to auto-wrap not <attr> into not (<attr>).
  • Rebuilt libcpabe_tkn20.dll as a proper Windows PE binary.
  • Updated tasks.json to use .def-based import lib instead of merging Go objects into MSVC archive.
  • Updated lib/README.md with corrected TKN20 build instructions.