Repository navigation
Python Bindings
bindings/python wraps the crypto box API in a Cython extension called pyopenabe.
Platforms: Linux and macOS only.
setup.pyexits on any other platform, so the bindings do not build on Windows/MSYS2 yet. CI builds and runs them on Linux.
Build the C++ library first (see Getting Started), then:
. ./env # setup.py refuses to run without ZROOT
python3 -m venv .venv && . .venv/bin/activate
pip install -r bindings/python/requirements.txt setuptools
cd bindings/python
python3 setup.py build_ext --inplace
python3 test.pyThis is what CI does. The older make -C bindings path relies on virtualenv and setup.py bdist, and is not tested.
import pyopenabe
openabe = pyopenabe.PyOpenABE()| Factory | Returns | Mirrors |
|---|---|---|
openabe.CreateABEContext("CP-ABE" or "KP-ABE") |
PyABEContext |
OpenABECryptoContext |
openabe.CreatePKEContext() |
PyPKEContext |
OpenPKEContext (NIST P-256) |
openabe.CreatePKSIGContext() |
PyPKSIGContext |
OpenPKSIGContext (NIST P-256) |
openabe.getSchemeTypes() lists the scheme IDs the bindings know about.
The methods keep the C++ names but return values instead of filling output parameters.
cpabe = openabe.CreateABEContext("CP-ABE")
cpabe.generateParams()
cpabe.keygen("|two|three|", "alice")
pt = b"hello world!" # plaintexts are bytes
ct = cpabe.encrypt("((one or two) and three)", pt)
assert cpabe.decrypt("alice", ct) == pt
# moving parameters and keys around
mpk = cpabe.exportPublicParams()
msk = cpabe.exportSecretParams()
uk = cpabe.exportUserKey("alice")
other = openabe.CreateABEContext("CP-ABE")
other.importPublicParams(mpk)
other.importSecretParams(msk)
other.importUserKey("alice", uk)pke = openabe.CreatePKEContext()
pke.keygen("user1")
ct = pke.encrypt("user1", b"hello")
assert pke.decrypt("user1", ct) == b"hello"
sig_ctx = openabe.CreatePKSIGContext()
sig_ctx.keygen("user2")
sig = sig_ctx.sign("user2", b"hello")
assert sig_ctx.verify("user2", b"hello", sig)Failures raise pyopenabe.PyOpenABEError. For example, decrypt raises Failed to decrypt! when the key does not satisfy the policy, so wrap calls in try/except rather than checking return values.
- Strings are accepted as
str(encoded as UTF-8) orbytes. Anything else raisesPyOpenABEError. - The PKE
decryptfailure message currently readsFailed to encrypt. It is a known copy-paste slip in the bindings.
OpenABE · AGPL-3.0 · Found a mistake in this wiki? Open an issue.
Using OpenABE
Reference
Contributing
Design notes
Help