Metadata-Version: 2.1
Name: otc
Version: 2.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

===
otc
===

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

|pypi| |readthedocs| |travis| |coveralls|

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

.. |travis| image:: https://app.travis-ci.com/nthparty/otc.svg?branch=main
   :target: https://app.travis-ci.com/nthparty/otc
   :alt: Travis CI build 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.

.. |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.

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 `nose <https://nose.readthedocs.io/>`_ (see ``setup.cfg`` for configuration details)::

    python -m pip install nose coverage
    nosetests --cover-erase

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
    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>`_.


