Metadata-Version: 2.1
Name: tno.mpc.mpyc.exponentiation
Version: 1.4.0
Summary: A generic extension to MPyC that allows you to securely compute a^[x], where a is a non-negative, plain-text base (floating point or integer) and x is a secure number (SecFxp or SecInt)
Home-page: https://mpc.tno.nl/
Author: TNO MPC Lab
Author-email: mpclab@tno.nl
Maintainer: TNO MPC Lab
Maintainer-email: mpclab@tno.nl
License: Apache License, Version 2.0
Download-URL: https://pypi.org/project/tno.mpc.mpyc.exponentiation/#files
Project-URL: Documentation, https://docs.mpc.tno.nl/mpyc/exponentiation/1.4.0
Project-URL: Source Code, https://github.com/TNO-MPC/mpyc.exponentiation
Keywords: TNO,MPC,multi-party computation,MPyC,exponentiation
Platform: any
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: Science/Research
Classifier: Typing :: Typed
Classifier: Topic :: Security :: Cryptography
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: tno.mpc.mpyc.stubs (>=0.3.0)
Requires-Dist: mpyc (>=0.6.8)
Provides-Extra: gmpy
Requires-Dist: gmpy2 ; extra == 'gmpy'
Provides-Extra: tests
Requires-Dist: pytest ; extra == 'tests'
Requires-Dist: pytest-asyncio ; extra == 'tests'

# TNO MPC Lab - MPyC - Secure Exponentiation

The TNO MPC lab consists of generic software components, procedures, and functionalities developed and maintained on a regular basis to facilitate and aid in the development of MPC solutions. The lab is a cross-project initiative allowing us to integrate and reuse previously developed MPC functionalities to boost the development of new protocols and solutions.

The package tno.mpc.mpyc.exponentiation is part of the TNO Python Toolbox.

The package contains a generic extension to MPyC that allows you to securely compute $`a^{[x]}`$, where $`a`$ is a non-negative, plain-text base (floating point or integer) and $`x`$ is a secure number (SecFxp or SecInt).

*Limitations in (end-)use: the content of this software package may solely be used for applications that comply with international export control laws.*

## Documentation

Documentation of the tno.mpc.mpyc.exponentiation package can be found [here](https://docs.mpc.tno.nl/mpyc/exponentiation/1.4.0).

## Install

Easily install the tno.mpc.mpyc.exponentiation package using pip:
```console
$ python -m pip install tno.mpc.mpyc.exponentiation
```

### Note:
A significant performance improvement can be achieved by installing the GMPY2 library.
```console
$ python -m pip install 'tno.mpc.mpyc.exponentiation[gmpy]'
```

If you wish to run the tests you can use:
```console
$ python -m pip install 'tno.mpc.mpyc.exponentiation[tests]'
```

## Usage

### Minimal example

> `example.py`
> ```python
> import math
> 
> from mpyc.runtime import mpc
> 
> from tno.mpc.mpyc.exponentiation import secure_pow
> 
> 
> async def main(base=math.e, x=[-1.5, 2.3, 4.5]):
>     async with mpc:
>         stype = mpc.SecFxp()
>         sec_x = (
>             [stype(xx, integral=False) for xx in x] if isinstance(x, list) else stype(x)
>         )
>         result = secure_pow(base, sec_x)
>         revealed_result = await mpc.output(result)
>     plain_result = [base ** xx for xx in x] if isinstance(x, list) else base ** x
>     print(f"Result of secure exponentiation is {revealed_result}")
>     print(f"In the plain we would have gotten  {plain_result}")
>     diff = (
>         [abs(sec - plain) for sec, plain in zip(revealed_result, plain_result)]
>         if isinstance(x, list)
>         else abs(revealed_result - plain_result)
>     )
>     print(f"The absolute difference is {diff}")
> 
> 
> if __name__ == "__main__":
>     mpc.run(main())
> ```


