Python library that serves as an API for common cryptographic primitives used to implement OPRF, OT, and PSI protocols.
Project description
Python library that serves as an API for common cryptographic primitives used to implement OPRF, OT, and PSI protocols.
Purpose
This library provides native Python implementations, Python libsodium wrappers, and additional utility methods for cryptographic primitives that are often used to implement oblivious pseudorandom function (OPRF), oblivious transfer (OT), and private set intersection (PSI) protocols.
For more information and background about the underlying mathematical structures and primitives, consult materials about Curve25519, the Ristretto group, and the related Ed25519 system.
Package Installation and Usage
The package is available on PyPI:
python -m pip install oblivious
The library can be imported in the usual ways:
import oblivious from oblivious import *
Examples
This library supports concise construction of elliptic curve points and scalars:
>>> from oblivious import point, scalar >>> p = point.hash('abc'.encode()) # Point derived from a hash of a string. >>> s = scalar() # Random scalar.
Built-in Python operators are overloaded to support point operations (addition, subtraction, negation, and equality) and scalar operations (multiplication by a scalar and inversion of scalars):
>>> q = s * p >>> p == (~s) * q True >>> p == (((~s) * s)) * p True >>> p + q == q + p True
Because the classes point and scalar are derived from bytes, all methods and other operators supported by bytes objects are supported by point and scalar objects:
>>> hex = '35c141f1c2c43543de9d188805a210abca3cd39a1e986304991ceded42b11709' >>> s = scalar.fromhex(hex) >>> s.hex() '35c141f1c2c43543de9d188805a210abca3cd39a1e986304991ceded42b11709'
In addition, Base64 conversion methods are included to support concise encoding and decoding of point and scalar objects:
>>> s.to_base64() 'NcFB8cLENUPenRiIBaIQq8o805oemGMEmRzt7UKxFwk=' >>> s == scalar.from_base64('NcFB8cLENUPenRiIBaIQq8o805oemGMEmRzt7UKxFwk=') True
Documentation
The documentation can be generated automatically from the source files using Sphinx:
cd docs python -m pip install -r requirements.txt sphinx-apidoc -f -E --templatedir=_templates -o _source .. ../setup.py && make html
Testing and Conventions
All unit tests are executed and their coverage is measured when using pytest (see setup.cfg for configuration details, and note that unit tests that require rbcl are skipped if that optional package is not installed):
python -m pip install pytest pytest-cov python -m pytest
Concise unit tests are implemented with the help of fountains; new reference specifications for these tests can be generated by running the testing module directly:
python test/test_oblivious.py
Style conventions are enforced using Pylint:
python -m pip install pylint python -m pylint oblivious ./test/test_oblivious.py
Contributions
In order to contribute to the source code, open an issue or submit a pull request on the GitHub page for this library.
Versioning
Beginning with version 0.1.0, the version number format for this library and the changes to the library associated with version number increments conform with Semantic Versioning 2.0.0.
Publishing
This library can be published as a package on PyPI by a package maintainer. Install the wheel package, remove any old build/distribution files, and package the source into a distribution archive:
python -m pip install wheel rm -rf dist *.egg-info python setup.py sdist bdist_wheel
Next, install the twine package and upload the package distribution archive to PyPI:
python -m pip install twine python -m twine upload dist/*
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for oblivious-5.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 560c76b0cc2ce8b7258c8e292c690901b250f247186c79b77c41d70f3b6efe8c |
|
MD5 | b41af6cf377202cd8430446e66ba2866 |
|
BLAKE2b-256 | 30e1deddf006df88ddf6eae7aad6b052aab9f305d0243c3d1fdf71116b79e9b5 |