Coder Social home page Coder Social logo

tno-mpc / mpyc.exponentiation Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 24 KB

TNO PET Lab - secure Multi-Party Computation (MPC) - MPyC - Secure Exponentiation

Home Page: https://docs.pet.tno.nl/mpc/mpyc/exponentiation

License: Apache License 2.0

Python 100.00%
mpc secret-sharing tno mpc-lab multi-party-computation exponentiation mpyc pet-lab

mpyc.exponentiation's Introduction

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.
This implementation of cryptographic software has not been audited. Use at your own risk.

Documentation

Documentation of the tno.mpc.mpyc.exponentiation package can be found here.

Install

Easily install the tno.mpc.mpyc.exponentiation package using pip:

$ python -m pip install tno.mpc.mpyc.exponentiation

Note:

A significant performance improvement can be achieved by installing the GMPY2 library.

$ python -m pip install 'tno.mpc.mpyc.exponentiation[gmpy]'

If you wish to run the tests you can use:

$ python -m pip install 'tno.mpc.mpyc.exponentiation[tests]'

Usage

Minimal example

example.py

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())

mpyc.exponentiation's People

Contributors

thomastno avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.