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 pure-Python implementations, Python wrappers for libsodium and mcl, 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.
Installation and Usage
This library is available as a package on PyPI:
python -m pip install oblivious
It is possible to install the library together with packages that bundle dynamic/shared libraries, such as rbcl and/or mclbn256 (note that in some environments, the brackets and/or commas may need to be escaped):
python -m pip install oblivious[rbcl]
python -m pip install oblivious[mclbn256]
python -m pip install oblivious[rbcl,mclbn256]
The library can be imported in the usual ways:
import oblivious
from oblivious import ristretto
from oblivious import bn254
Examples
This library supports concise construction of elliptic curve points and scalars. The examples below use the ristretto module that provides data structures for working with the Ristretto group:
>>> from oblivious.ristretto import point, scalar
>>> p = point.hash('abc'.encode()) # Point derived from a hash of a string.
>>> s = scalar() # Random scalar.
>>> t = scalar.from_int(0) # Scalar corresponding to the zero residue.
Built-in Python operators are overloaded to support point operations (such as addition, subtraction, negation, and equality) and scalar operations (such as 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
>>> t * p == p - p
True
The point and scalar classes have common conversion methods that correspond to those supported by bytes objects (and in some cases, these classes are themselves derived from bytes):
>>> hex = '35c141f1c2c43543de9d188805a210abca3cd39a1e986304991ceded42b11709'
>>> s = scalar.from_hex(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
For more information and background about the underlying mathematical structures and primitives found in the ristretto module, consult materials about Curve25519, the Ristretto group, and the related Ed25519 system.
Development
All installation and development dependencies are fully specified in pyproject.toml. The project.optional-dependencies object is used to specify optional requirements for various development tasks. This makes it possible to specify additional options (such as docs, lint, and so on) when performing installation using pip:
python -m pip install .[docs,lint]
Documentation
The documentation can be generated automatically from the source files using Sphinx:
python -m pip install .[docs]
cd docs
sphinx-apidoc -f -e -E --templatedir=_templates -o _source .. && make html
Testing and Conventions
All unit tests are executed and their coverage is measured when using pytest (see the pyproject.toml file for configuration details, and note that unit tests that require rbcl and/or mclbn256 are skipped if the corresponding optional package is not installed):
python -m pip install .[test]
python -m pytest
Concise unit tests are implemented with the help of fountains; new reference specifications for the tests in a given testing module can be generated by running that testing module directly:
python test/test_ristretto.py
python test/test_bn254.py
Style conventions are enforced using Pylint:
python -m pip install .[lint]
python -m pylint src/oblivious test/test_ristretto.py test/test_bn254.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. First, install the dependencies required for packaging and publishing:
python -m pip install .[publish]
Ensure that the correct version number appears in pyproject.toml, and that any links in this README document to the Read the Docs documentation of this package (or its dependencies) have appropriate version numbers. Also ensure that the Read the Docs project for this library has an automation rule that activates and sets as the default all tagged versions. Create and push a tag for this version (replacing ?.?.? with the version number):
git tag ?.?.?
git push origin ?.?.?
Remove any old build/distribution files. Then, package the source into a distribution archive:
rm -rf build dist src/*.egg-info
python -m build --sdist --wheel .
Finally, upload the package distribution archive to PyPI:
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
File details
Details for the file oblivious-7.0.0.tar.gz
.
File metadata
- Download URL: oblivious-7.0.0.tar.gz
- Upload date:
- Size: 51.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f9a0517e059c9a5f3a54c1313761603bbfa34d5aa15b1a258437d4833d24b60 |
|
MD5 | 2b1d8eccab4d301e0c7fc24e5d29efa8 |
|
BLAKE2b-256 | 401d0e5bb39234ff1d99a732c78294e118c508281a8d90ff0f43673cd2822da9 |
File details
Details for the file oblivious-7.0.0-py3-none-any.whl
.
File metadata
- Download URL: oblivious-7.0.0-py3-none-any.whl
- Upload date:
- Size: 37.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d05999ee123c918351994b6fe99851f49252564388cfab163ae513348132b2e |
|
MD5 | 8a27b96151cebabd86fb61cc6f16c4b4 |
|
BLAKE2b-256 | 8a302359492441dafdbf87119c43066e1e96145c59496cfc1a13560dfacfa2d6 |