Metadata-Version: 2.1
Name: otc
Version: 3.0.0
Summary: Oblivious transfer (OT) communications protocol message/response functionality implementations based on Curve25519 primitives.
Home-page: https://github.com/nthparty/otc
Author: Andrei Lapets
Author-email: a@lapets.io
License: MIT
Platform: UNKNOWN
Description-Content-Type: text/x-rst
License-File: LICENSE
Requires-Dist: bcl (~=2.1)
Requires-Dist: oblivious (~=5.0)

===
otc
===

Oblivious transfer (OT) communications protocol message/response functionality implementations based on Curve25519 primitives, including both pure-Python and libsodium-based variants.

|pypi| |readthedocs| |actions| |coveralls|

.. |pypi| image:: https://badge.fury.io/py/otc.svg
   :target: https://badge.fury.io/py/otc
   :alt: PyPI version and link.

.. |readthedocs| image:: https://readthedocs.org/projects/otc/badge/?version=latest
   :target: https://otc.readthedocs.io/en/latest/?badge=latest
   :alt: Read the Docs documentation status.

.. |actions| image:: https://github.com/nthparty/otc/workflows/lint-test-cover-docs/badge.svg
   :target: https://github.com/nthparty/otc/actions/workflows/lint-test-cover-docs.yml
   :alt: GitHub Actions status.

.. |coveralls| image:: https://coveralls.io/repos/github/nthparty/otc/badge.svg?branch=main
   :target: https://coveralls.io/github/nthparty/otc?branch=main
   :alt: Coveralls test coverage summary.

Purpose
-------
This library provides data structures and methods for a basic `oblivious transfer (OT) <https://en.wikipedia.org/wiki/Oblivious_transfer>`_ communications protocol defined in `work by Chou and Orlandi <https://eprint.iacr.org/2015/267.pdf>`_. Thanks to the underlying `oblivious <https://pypi.org/project/oblivious/>`_ library, users of this library have the option of relying either on pure Python implementations of cryptographic primitives or on wrappers for `libsodium <https://github.com/jedisct1/libsodium>`_.

For more information and background about the underlying mathematical structures and primitives, consult materials about `Curve25519 <https://cr.yp.to/ecdh.html>`_, the `Ristretto <https://ristretto.group/>`_ group, and the related `Ed25519 <https://ed25519.cr.yp.to/>`_ system.

Package Installation and Usage
------------------------------
The package is available on `PyPI <https://pypi.org/project/otc/>`_::

    python -m pip install otc

The library can be imported in the usual manner::

    import otc
    from otc import *

Example
^^^^^^^
Suppose that a sender wants to send exactly one of two payloads to a receiver (such as one of two decryption keys). Furthermore, the receiver does not want to reveal to the sender which of the two payloads they chose to receive. To begin, the sender creates a sender object `s` with a public key `s.public` that should be sent to the receiver::

    >>> import otc
    >>> s = otc.send()

The receiver can then create a receiver object and use `s.public` to make an encrypted selection that the sender cannot decrypt::

    >>> r = otc.receive()
    >>> selection = r.query(s.public, 1)

The sender can then send two encrypted replies based on the receiver's selection; the receiver will *only be able to decrypt the pre-selected payload*, and the sender *does not know* which of the two payloads can be decrypted by the receiver::

    >>> replies = s.reply(selection, bytes([0] * 16), bytes([255] * 16))

Finally, the receiver can decrypt their chosen payload::

    >>> r.elect(s.public, 1, *replies) == bytes([255] * 16) # Second message.
    True

See the article `Privacy-Preserving Information Exchange Using Python <https://medium.com/nthparty/privacy-preserving-information-exchange-using-python-1a4a11bed3d5>`_ for a more detailed presentation of the this example.

Documentation
-------------
The documentation can be generated automatically from the source files using `Sphinx <https://www.sphinx-doc.org/>`_::

    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 <https://docs.pytest.org/>`_ (see ``setup.cfg`` for configuration details)::

    python -m pip install pytest pytest-cov
    python -m pytest

Alternatively, all unit tests are included in the module itself and can be executed using `doctest <https://docs.python.org/3/library/doctest.html>`_::

    python otc/otc.py -v

Style conventions are enforced using `Pylint <https://www.pylint.org/>`_::

    python -m pip install pylint
    python -m pylint otc

Contributions
-------------
In order to contribute to the source code, open an issue or submit a pull request on the `GitHub page <https://github.com/nthparty/otc>`_ for this library.

Versioning
----------
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 <https://semver.org/#semantic-versioning-200>`_.

Publishing
----------
This library can be published as a `package on PyPI <https://pypi.org/project/otc/>`_ by a package maintainer. Install the `wheel <https://pypi.org/project/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 <https://pypi.org/project/twine/>`_ package and upload the package distribution archive to PyPI::

    python -m pip install twine
    python -m twine upload dist/*


